bfsOpen()

PROTOTYPE

#include <bfs.h>

int bfsOpen(const char *name, int mode);

DESCRIPTION

bfsOpen() opens the file specified by name. mode must be one of the following:

  • BFS_READ - Open for reading only.
  • BFS_WRITE - Open for writing only.
  • BFS_UPDATE - Open for writing only.

If BFS_WRITE is used and the named file already exists, it is deleted. If BFS_UPDATE is used, the named file already exists, and a reset occurs before the new copy is written to and closed, the original file contents will be found at the next start up. The new contents replace the old only if the file opened in update mode has been written to and then closed.

It is an error to open the boot file (whose name is given by the BFS_BOOT_FILE #define) in update mode. Because the boot file, if enabled, occupies consecutive blocks at the beginning of the TargetBFS volume, it is not possible to keep a prior copy while creating a new version.

If successful, bfsOpen() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EFAULT name equals NULL or the empty string.
EINVAL The specified file name or open mode is invalid.
EMFILE A file is already open or a fatal error has occurred.
ENFILE The maximum number of files has already been created.
ENOENT The file to be opened in read mode does not exist.
other An I/O error occurred while deleting a previously existing file.

EXAMPLE

  /*-------------------------------------------------------------------*/
  /* Try to open the specified file. Return if error.                  */
  /*-------------------------------------------------------------------*/
  if (bfsOpen(name, BFS_READ))
  {
    perror("bfsOpen() failed");
    return;
  }