Shinobi Library - Memory Card Function

buFindFirstFile

Gets the name of the first file

FORMAT

Sint32 buFindFirstFile( drive, *fname )
Sint32 drive
char *fname

PARAMETER

 drive  Extension socket number 
 *fname  Address that gets file name 

RETURN

 BUD_ERR_OK  Normal end 
 BUD_ERR_FILE_NOT_FOUND  File not found 
 BUD_ERR_UNFORMAT  Disk is not formatted 
 BUD_ERR_NO_DISK  No memory card found 
 BUD_ERR_BUSY  A TYPE_B function is being processed 

DESCRIPTION

Gets the name of the first file on a memory card inserted in a specified extension socket.

The following values can be designated for the argument drive that specifies extension sockets.

 BUD_DRIVE_A1  Extension socket 1 on board A 
 BUD_DRIVE_A2  Extension socket 2 on board A 
 BUD_DRIVE_B1  Extension socket 1 on board B 
 BUD_DRIVE_B2  Extension socket 2 on board B 
 BUD_DRIVE_C1  Extension socket 1 on board C 
 BUD_DRIVE_C2  Extension socket 2 on board C 
 BUD_DRIVE_D1  Extension socket 1 on board D 
 BUD_DRIVE_D2  Extension socket 2 on board D 

If the file does not exist, then fname[0] = '\0' results. Normally, this function is used in combination with buFindNextFile() function to get the names of all files in a drive.


EXAMPLE

  Sint32 ret, files, blocks, totel;
  char fname[16];
  BUS_FILEINFO info;
  files = blocks = total = 0;
  /* Get name of first file */
  ret = buFindFirstFile(drive, fname);
  if (ret < 0) {
    if (ret == BUD_ERR_FILE_NOT_FOUND) goto end;
    else goto err;
  }
  if (buGetFileInfo(drive, fname, &info) < 0) goto err;
    blocks = info.blocks;
    total += blocks;
    files++;
    do {
      printf("%12s %10d bytes(%3d blocks)\n", files, blocks * 512, blocks);
      /* Get name of second and subsequent files */
      ret = buFindNextFile(drive, fname);
      if (ret < 0) {
        if (ret == BUD_ERR_FILE_NOT_FOUND) goto end;
        else goto err;
      }
      if (buGetFileInfo(drive, fname, &info) < 0) goto err;
      blocks = info.blocks;
      total += blocks;
      files++;
    } while (files < FILE_MAX);
  end:
    return OK;
  err:
    return NG;

NOTE

A minimum of 13 bytes is required for the area where the file name is to be stored.

buFindFirstFile
COPYRIGHT © SEGA ENTERPRISES, LTD., 1998,1999