SysOpen

From WhitixDoc

Jump to: navigation, search

SysOpen opens or create a file. Returns a file descriptor that can be used in later calls to SysRead, SysWrite and other filesystem calls.

Contents

Syntax

int SysOpen(
    const char* fileName,
    int flags,
    int permissions
)

Parameters

  • fileName. The name of the filesystem object to be created or opened. The length of the string is limited to PATH_MAX (typically 2048) bytes by the kernel.
  • flags. The following flags can be passed to the function:
Name Value Comments
_SYS_FILE_READ 0x0001 Open the file for reading. Some filesystem objects may be write-only (such as the Null special device) and may not permit reading.
_SYS_FILE_WRITE 0x0002 Open the file for writing. Some filesystem objects may be read-only (such as files mounted on a read-only filesystem) and may not permit writing.
_SYS_FILE_CREATE_OPEN 0x0004 Open the file, or create it if it doesn't exist. Opening a file with this option on a read-only filesystem will not succeed.
_SYS_FILE_FORCE_OPEN 0x0008 Open the file if and only if it exists.
_SYS_FILE_FORCE_CREATE 0x0010 Create the file.
_SYS_FILE_DIRECTORY 0x0020 Open the file if and only if it is a directory.
  • permissions. Currently unused. Will be used in the future for filesystem permissions, but is currently ignored by the kernel.

Returns

Returns an integer of 0 or above if the filesystem object can be opened with the appropriate flags parameters.

If the filesystem object cannot be opened, one of the standard error codes will be returned.

Example

This example opens the first console device for reading and writing, assuming it already exists.

/* Open the first console device. */
int fd=SysOpen("/System/Devices/Consoles/Console0", _SYS_FILE_READ | _SYS_FILE_WRITE | _SYS_FILE_FORCE_OPEN, 0);
 
if (fd < 0)
{
    /* Failure */
}


Personal tools