muteki
Loading...
Searching...
No Matches
fs.h File Reference

Filesystem access API. More...

#include <muteki/common.h>

Go to the source code of this file.

Data Structures

struct  find_context_t
 Structure for find context. More...
 
struct  fs_stat_t
 Filesystem usage statistics. More...
 
struct  fn_parts_lfn_s
 All-in-one struct that contain all parts used in _wfnsplit() and _wfnmerge() More...
 
struct  fn_parts_dos_s
 All-in-one struct that contain all parts used in _afnsplit() and _afnmerge() More...
 

Macros

#define SYS_PATH_MAX_CU   256u
 Max code units (ASCII or UTF-16) a path can contain.
 
#define FIND_TS_YEAR(ts)   ((ts >> 25) + 1980)
 Read year from find timestamp.
 
#define FIND_TS_MONTH(ts)   ((ts >> 21) & 0xf)
 Read month from find timestamp.
 
#define FIND_TS_DAY(ts)   ((ts >> 16) & 0x1f)
 Read day from find timestamp.
 
#define FIND_TS_HOUR(ts)   ((ts >> 11) & 0x1f)
 Read hour from find timestamp.
 
#define FIND_TS_MINUTE(ts)   ((ts >> 5) & 0x3f)
 Read minute from find timestamp.
 
#define FIND_TS_SECOND(ts)   ((ts & 0xf) * 4)
 Read second from find timestamp.
 
#define FNSPLIT_LFN_PATHNAME_MAX   261u
 
#define FNSPLIT_LFN_DRIVE_MAX   4u
 
#define FNSPLIT_LFN_DIRNAME_MAX   257u
 
#define FNSPLIT_LFN_BASENAME_MAX   257u
 
#define FNSPLIT_LFN_SUFFIX_MAX   259u
 
#define FNSPLIT_DOS_PATHNAME_MAX   81u
 
#define FNSPLIT_DOS_DRIVE_MAX   4u
 
#define FNSPLIT_DOS_DIRNAME_MAX   67u
 
#define FNSPLIT_DOS_BASENAME_MAX   10u
 
#define FNSPLIT_DOS_SUFFIX_MAX   9u
 

Typedefs

typedef struct fn_parts_lfn_s fs_parts_lfn_t
 All-in-one struct that contain all parts used in _wfnsplit() and _wfnmerge()
 
typedef struct fn_parts_dos_s fs_parts_dos_t
 All-in-one struct that contain all parts used in _afnsplit() and _afnmerge()
 

Enumerations

enum  fs_attribute_e {
  ATTR_READONLY = 0x1 , ATTR_HIDDEN = 0x2 , ATTR_SYSTEM = 0x4 , ATTR_DIR = 0x10 ,
  ATTR_ARCHIVE = 0x20 , ATTR_DEVICE = 0x40 , ATTR_NONE = 0x80
}
 File/directory attributes. More...
 

Functions

bool _aremove (const char *pathname)
 Delete a file.
 
bool __wremove (const UTF16 *pathname)
 Delete a file.
 
short _afindfirst (const char *fnmatch, find_context_t *ctx, int attrib_mask)
 Begin a file/directory search.
 
short _afindnext (find_context_t *ctx)
 Continue a previously started file/directory search.
 
short _wfindfirst (const UTF16 *fnmatch, find_context_t *ctx, int attrib_mask)
 Begin a file/directory search (LFN support).
 
short _wfindnext (find_context_t *ctx)
 Continue a previously started file/directory search.
 
int _findclose (find_context_t *ctx)
 Terminate a file/directory search.
 
short _wfgetattr (UTF16 *path)
 Get attributes of specific path.
 
short _wfsetattr (UTF16 *path, short attrs)
 Set attributes of specific path.
 
short _afgetattr (char *path)
 Get attributes of specific path.
 
short _afsetattr (char *path, short attrs)
 Set attributes of specific path.
 
int _wmkdir (UTF16 *path)
 Create a new directory.
 
int _amkdir (char *path)
 Create a new directory.
 
int _wrmdir (UTF16 *path)
 Remove a directory.
 
int _armdir (char *path)
 Remove a directory.
 
short _agetcurdir (void *unk, char *buf)
 Get system CWD value.
 
short _wgetcurdir (void *unk, UTF16 *buf)
 Get system CWD value.
 
short _achdir (const char *path)
 Change system working directory to a new path.
 
short _wchdir (const UTF16 *path)
 Change system working directory to a new path.
 
short _arename (const char *old_path, const char *new_path)
 Rename/move a file.
 
short _wrename (const UTF16 *old_path, const UTF16 *new_path)
 Rename/move a file.
 
int FSGetDiskRoomState (int fsid, fs_stat_t *fs_stat)
 Get filesystem usage stats.
 
int _afnsplit (const char *pathname, char *drive, char *dirname, char *basename, char *suffix)
 Split a DOS 8.3 pathname into parts.
 
int _afnmerge (char *pathname, const char *drive, const char *dirname, const char *basename, const char *suffix)
 Build an DOS 8.3 pathname from parts.
 
int _wfnsplit (const UTF16 *pathname, UTF16 *drive, UTF16 *dirname, UTF16 *basename, UTF16 *suffix)
 Split an LFN pathname into parts.
 
int _wfnmerge (UTF16 *pathname, const UTF16 *drive, const UTF16 *dirname, const UTF16 *basename, const UTF16 *suffix)
 Build an LFN pathname from parts.
 

Detailed Description

Filesystem access API.

Macro Definition Documentation

◆ FNSPLIT_DOS_BASENAME_MAX

#define FNSPLIT_DOS_BASENAME_MAX   10u

Maximum number of code units a DOS 8.3 base name can have including the trailing NUL.

◆ FNSPLIT_DOS_DIRNAME_MAX

#define FNSPLIT_DOS_DIRNAME_MAX   67u

Maximum number of code units a DOS 8.3 directory name can have including the trailing NUL.

◆ FNSPLIT_DOS_DRIVE_MAX

#define FNSPLIT_DOS_DRIVE_MAX   4u

Maximum number of code units a DOS 8.3 drive specifier can have including the trailing NUL.

◆ FNSPLIT_DOS_PATHNAME_MAX

#define FNSPLIT_DOS_PATHNAME_MAX   81u

Maximum number of code units an DOS 8.3 pathname can have including the trailing NUL.

◆ FNSPLIT_DOS_SUFFIX_MAX

#define FNSPLIT_DOS_SUFFIX_MAX   9u

Maximum number of code units a DOS 8.3 file suffix can have including the trailing NUL.

◆ FNSPLIT_LFN_BASENAME_MAX

#define FNSPLIT_LFN_BASENAME_MAX   257u

Maximum number of code units an LFN base name can have including the trailing NUL.

◆ FNSPLIT_LFN_DIRNAME_MAX

#define FNSPLIT_LFN_DIRNAME_MAX   257u

Maximum number of code units an LFN directory name can have including the trailing NUL.

◆ FNSPLIT_LFN_DRIVE_MAX

#define FNSPLIT_LFN_DRIVE_MAX   4u

Maximum number of code units an LFN drive specifier can have including the trailing NUL.

◆ FNSPLIT_LFN_PATHNAME_MAX

#define FNSPLIT_LFN_PATHNAME_MAX   261u

Maximum number of code units an LFN pathname can have including the trailing NUL.

◆ FNSPLIT_LFN_SUFFIX_MAX

#define FNSPLIT_LFN_SUFFIX_MAX   259u

Maximum number of code units an LFN file suffix can have including the trailing NUL.

◆ SYS_PATH_MAX_CU

#define SYS_PATH_MAX_CU   256u

Max code units (ASCII or UTF-16) a path can contain.

This includes the NUL terminator. Note that this can differ from libc definitions due to possible encoding differences (e.g. newlib-muteki uses UTF-8 as the "ANSI" encoding by default).

Enumeration Type Documentation

◆ fs_attribute_e

File/directory attributes.

Just the attributes in FAT32.

See also
https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
Enumerator
ATTR_READONLY 

Entry is read only.

ATTR_HIDDEN 

Entry is hidden.

ATTR_SYSTEM 

Entry is a system file/directory.

ATTR_DIR 

Entry is a directory.

ATTR_ARCHIVE 

Entry is archived.

ATTR_NONE 

Entry does not have any other attribute.

Function Documentation

◆ __wremove()

bool __wremove ( const UTF16 pathname)
extern

Delete a file.

Syscall Number
0x10274
Parameters
pathnameUTF-16 LFN path to the file being removed.
Return values
trueThe operation was completed successfully.
falseThe operation failed with error.

◆ _achdir()

short _achdir ( const char *  path)
extern

Change system working directory to a new path.

Syscall Number
0x100e2
Parameters
pathDOS 8.3 path.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _afgetattr()

short _afgetattr ( char *  path)
extern

Get attributes of specific path.

Similar to GetFileAttributeA() in Windows.

Syscall Number
0x100db
Parameters
pathDOS 8.3 path.
Returns
The attribute, or -1 on error.
See also
fs_attribute_e

◆ _afindfirst()

short _afindfirst ( const char *  fnmatch,
find_context_t ctx,
int  attrib_mask 
)
extern

Begin a file/directory search.

Matches the first file/directory based on fnmatch pattern fnmatch and attribute mask attrib_mask. Saves context at ctx, which can be used later with _afindnext() and _findclose().

Syscall Number
0x100d8
Parameters
fnmatchThe pattern.
ctxThe context object.
attrib_maskAttribute mask (use 0 to match everything regardless of attributes).
Return values
0There is a match.
-1No more match was found.

◆ _afindnext()

short _afindnext ( find_context_t ctx)
extern

Continue a previously started file/directory search.

Matches the next file/directory.

Syscall Number
0x100d9
Parameters
ctxThe context object.
Return values
0There is a match.
-1No more match was found.

◆ _afnmerge()

int _afnmerge ( char *  pathname,
const char *  drive,
const char *  dirname,
const char *  basename,
const char *  suffix 
)
extern

Build an DOS 8.3 pathname from parts.

DOS 8.3 counterpart of _wfnmerge().

Syscall Number
0x100c6
Parameters
[out]pathnamePointer to a buffer where the constructed pathname will be stored. This buffer must be at least as long as FNSPLIT_DOS_PATHNAME_MAX.
[in]driveDrive specifier (e.g., C or C:). If provided, it must be a valid drive name.
[in]dirnameDirectory path (e.g., \path\to\a\). If provided, it must end with a backslash.
[in]basenameBase name without a suffix (e.g., file).
[in]suffixFile suffix (e.g., .txt).
Returns
Bitfield that indicates which parts were added into the resulting pathname.
See also
_wfnmerge Its LFN counterpart.

◆ _afnsplit()

int _afnsplit ( const char *  pathname,
char *  drive,
char *  dirname,
char *  basename,
char *  suffix 
)
extern

Split a DOS 8.3 pathname into parts.

DOS 8.3 counterpart of _wfnsplit().

Syscall Number
0x100c5
Parameters
[in]pathnamePathname to be split.
[out]driveDrive name, or NULL to omit this part. Must be at least as long as FNSPLIT_DOS_DRIVE_MAX.
[out]dirnameDirectory, or NULL to omit this part. Must be at least as long as FNSPLIT_DOS_DIRNAME_MAX.
[out]basenameBasename without suffix, or NULL to omit this part. Must be at least as long as FNSPLIT_DOS_BASENAME_MAX.
[out]suffixSuffix, or NULL to omit this part. Must be at least as long as FNSPLIT_DOS_SUFFIX_MAX.
Returns
Bitfield that indicates which parts were being extracted successfully.
See also
_wfnsplit Its LFN counterpart.

◆ _afsetattr()

short _afsetattr ( char *  path,
short  attrs 
)
extern

Set attributes of specific path.

Similar to SetFileAttributeA() in Windows.

Syscall Number
0x100dc
Parameters
pathDOS 8.3 path.
attrsThe new attribute.
Returns
The new attribute, or -1 on error.
See also
fs_attribute_e

◆ _agetcurdir()

short _agetcurdir ( void *  unk,
char *  buf 
)
extern

Get system CWD value.

Syscall Number
0x100e3
Parameters
unkSome context object, format unknown. Use NULL to get the CWD of current applet.
bufBuffer large enough to contain a DOS8.3 path. Must be at least SYS_PATH_MAX_CU bytes long.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _amkdir()

int _amkdir ( char *  path)
extern

Create a new directory.

Syscall Number
0x100e0
Parameters
pathDOS 8.3 path to the new directory.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _aremove()

bool _aremove ( const char *  pathname)
extern

Delete a file.

Syscall Number
0x100dd
Parameters
pathnameDOS 8.3 path to the file being removed.
Return values
trueThe operation was completed successfully.
falseThe operation failed with error.

◆ _arename()

short _arename ( const char *  old_path,
const char *  new_path 
)
extern

Rename/move a file.

Syscall Number
0x100de
Parameters
old_pathOld DOS 8.3 path.
new_pathNew DOS 8.3 path.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _armdir()

int _armdir ( char *  path)
extern

Remove a directory.

Syscall Number
0x100e1

Sets kerrno namespace to ERRNO_NS_KERNEL and error code to 0xffff when directory is not empty.

Parameters
pathDOS 8.3 path to the directory being removed.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _findclose()

int _findclose ( find_context_t ctx)
extern

Terminate a file/directory search.

Syscall Number
0x100da
Parameters
ctxThe context object.
Return values
0The operation was completed successfully.

◆ _wchdir()

short _wchdir ( const UTF16 path)
extern

Change system working directory to a new path.

Syscall Number
0x10279
Parameters
pathUTF-16 LFN path.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _wfgetattr()

short _wfgetattr ( UTF16 path)
extern

Get attributes of specific path.

Similar to GetFileAttributeW() in Windows.

Syscall Number
0x10272
Parameters
pathUTF-16 LFN path.
Returns
The attribute, or -1 on error.
See also
fs_attribute_e

◆ _wfindfirst()

short _wfindfirst ( const UTF16 fnmatch,
find_context_t ctx,
int  attrib_mask 
)
extern

Begin a file/directory search (LFN support).

Matches the first file/directory based on fnmatch pattern fnmatch and attribute mask attrib_mask. Saves context at ctx, which can be used later with _afindnext() and _findclose().

Syscall Number
0x10270
Parameters
fnmatchThe pattern (encoded in UTF-16).
ctxThe context object.
attrib_maskAttribute mask (use 0 to match everything regardless of attributes).
Return values
0There is a match.
-1No more match was found.

◆ _wfindnext()

short _wfindnext ( find_context_t ctx)
extern

Continue a previously started file/directory search.

Matches the next file/directory.

Not sure if interchangeable with _afindnext() since it should have no dependency on different find context. Needs to be verified later.

Syscall Number
0x10271
Parameters
ctxThe context object.
Return values
0There is a match.
-1No more match was found.

◆ _wfnmerge()

int _wfnmerge ( UTF16 pathname,
const UTF16 drive,
const UTF16 dirname,
const UTF16 basename,
const UTF16 suffix 
)
extern

Build an LFN pathname from parts.

Borland libc style path parsing helper. It constructs a pathname by combining the components: drive, directory, basename, and suffix. It is designed to be the inverse of the _wfnsplit() syscall, allowing users to reconstruct a full pathname from its individual parts.

Each component is optional and can be provided as NULL if it is not needed in the final pathname. The syscall will concatenate the non-NULL components in the order of drive, directory, basename, and suffix, ensuring proper formatting such as adding backslashes where necessary.

Borland C++ has a documentation regarding to their implementation: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Fnmerge,_wfnmerge.

Syscall Number
0x1026c
Parameters
[out]pathnamePointer to a buffer where the constructed pathname will be stored. This buffer must be at least as long as FNSPLIT_LFN_PATHNAME_MAX.
[in]driveDrive specifier (e.g., C or C:). If provided, it must be a valid drive name.
[in]dirnameDirectory path (e.g., \path\to\a\). If provided, it must end with a backslash.
[in]basenameBase name without a suffix (e.g., file).
[in]suffixFile suffix (e.g., .txt).
Returns
Bitfield that indicates which parts were added into the resulting pathname.

◆ _wfnsplit()

int _wfnsplit ( const UTF16 pathname,
UTF16 drive,
UTF16 dirname,
UTF16 basename,
UTF16 suffix 
)
extern

Split an LFN pathname into parts.

Borland libc style path parsing helper. It takes a pathname in the format of C:\path\to\a\file.txt and parse it into 4 parts:

  • drive: The drive name consists of the drive letter and a single colon (C:)
  • dirname: The directory name with the root backslash and training backslash (\path\to\a\)
  • basename: Basename without the suffix (file)
  • suffix: Suffix with the leading dot (.txt)

Borland C++ has a documentation regarding to their implementation: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Fnsplit,_wfnsplit.

Syscall Number
0x1026b
Parameters
[in]pathnamePathname to be split.
[out]driveDrive name, or NULL to omit this part. Must be at least as long as FNSPLIT_LFN_DRIVE_MAX.
[out]dirnameDirectory, or NULL to omit this part. Must be at least as long as FNSPLIT_LFN_DIRNAME_MAX.
[out]basenameBasename without suffix, or NULL to omit this part. Must be at least as long as FNSPLIT_LFN_BASENAME_MAX.
[out]suffixSuffix, or NULL to omit this part. Must be at least as long as FNSPLIT_LFN_SUFFIX_MAX.
Returns
Bitfield that indicates which parts were being extracted successfully.

◆ _wfsetattr()

short _wfsetattr ( UTF16 path,
short  attrs 
)
extern

Set attributes of specific path.

Similar to SetFileAttributeW() in Windows.

Syscall Number
0x10273
Parameters
pathUTF-16 LFN path.
attrsThe new attribute.
Returns
The new attribute, or -1 on error.
See also
fs_attribute_e

◆ _wgetcurdir()

short _wgetcurdir ( void *  unk,
UTF16 buf 
)
extern

Get system CWD value.

Syscall Number
0x1027a
Parameters
unkSome context object, format unknown. Use NULL to get the CWD of current applet.
bufBuffer large enough to contain a UTF-16 LFN path. Must be at least SYS_PATH_MAX_CU units long.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _wmkdir()

int _wmkdir ( UTF16 path)
extern

Create a new directory.

Syscall Number
0x10277
Parameters
pathUTF-16 LFN path to the new directory.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _wrename()

short _wrename ( const UTF16 old_path,
const UTF16 new_path 
)
extern

Rename/move a file.

Syscall Number
0x10275
Parameters
old_pathOld UTF-16 LFN path.
new_pathNew UTF-16 LFN path.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ _wrmdir()

int _wrmdir ( UTF16 path)
extern

Remove a directory.

Syscall Number
0x10278

Sets kerrno namespace to ERRNO_NS_KERNEL and error code to 0xffff when directory is not empty.

Parameters
pathUTF-16 LFN path to the directory being removed.
Return values
0The operation was completed successfully.
-1The operation failed with error.

◆ FSGetDiskRoomState()

int FSGetDiskRoomState ( int  fsid,
fs_stat_t fs_stat 
)
extern

Get filesystem usage stats.

Syscall Number
0x100eb
Parameters
fsidFilesystem ID.
fs_statTarget to store filesystem usage stats.
Return values
0The operation was completed successfully.