<< Previous | Next >>

fat_Open

int fat_Open( fat_part *part, char *name, int type, int ff, FATfile *file, long *prealloc );

Description

Opens a file or directory, optionally creating it if it does not already exist. If the function returns -EBUSY, call it repeatedly with the same arguments until it returns something other than -EBUSY.

Parameters

part
Handle for the partition being used.

name
Pointer to the full path name of the file to be opened/created.

type
FAT_FILE or FAT_DIR, depending on what is to be opened/created.

ff
File flags, must be one of:

  • FAT_OPEN - Object must already exist. If it does not exist, -ENOENT will be returned.

  • FAT_CREATE - Object is created only if it does not already exist

  • FAT_MUST_CREATE - Object is created, and it must not already exist.

  • FAT_READONLY - No write operations (this flag is mutually exclusive with any of the CREATE flags).

  • FAT_SEQUENTIAL - Optimize for sequential reads and/or writes. This setting can be changed while the file is open by using the fat_fcntl() function.

file
Pointer to an empty FAT file structure that will act as a handle for the newly opened file. Note that you must memset this structure to zero when you are using the non-blocking mode before calling this function the first time. Keep calling until something other than -EBUSY is returned, but do not change anything in any of the parameters while doing so.

prealloc
An initial byte count if the object needs to be created. This number is rounded up to the nearest whole number of clusters greater than or equal to 1. This parameter is only used if one of the *_CREATE flag is set and the object does not already exist. On return, *prealloc is updated to the actual number of bytes allocated. May be NULL, in which case one cluster is allocated if the call is successful.

Return Value

0: success.
-EINVAL: invalid arguments. Trying to create volume label, or conflicting flags.
-ENOENT: file/directory could not be found.
-EPATHSTR: Invalid path string for parent directory
-EEXIST: object existed when FAT_MUST_CREATE flag set.
-EPERM: trying to create a file/directory on a read-only partition.
-EMFILE - too many open files. If you get this code, increase the FAT_MAXMARKERS definition in the BIOS.

Other negative values indicate I/O error, etc.

Non-blocking mode only:

-EBUSY: the device is busy (nonblocking mode only).
-EFSTATE - file structure is not in a valid state. Usually means it was not zerod before calling this function for the first time (for that file) struct, when in non-blocking mode; can also occur if the same file struct is opened more than once.

Library

FAT.LIB

See Also

fat_ReadDir, fat_Status, fat_Close


Dynamic C Functions << Previous | Next >> rabbit.com