Mstdlib-1.24.0
Common

Macros

#define M_FS_PATH_NORM_RESDIR   M_FS_PATH_NORM_HOME|M_FS_PATH_NORM_FOLLOWSYMLINKS|M_FS_PATH_NORM_SYMLINKS_FAILDNE
 
#define M_FS_PATH_NORM_RESALL   M_FS_PATH_NORM_HOME|M_FS_PATH_NORM_FOLLOWSYMLINKS|M_FS_PATH_NORM_SYMLINKS_FAILDNE|M_FS_PATH_NORM_SYMLINKS_FAILDNELAST
 
#define M_FS_DIR_WALK_FILTER_ALL   M_FS_DIR_WALK_FILTER_FILE|M_FS_DIR_WALK_FILTER_DIR|M_FS_DIR_WALK_FILTER_SYMLINK|M_FS_DIR_WALK_FILTER_HIDDEN
 
#define M_FS_BUF_SIZE   1024
 

Typedefs

typedef struct M_fs_perms M_fs_perms_t
 
typedef struct M_fs_info M_fs_info_t
 
typedef struct M_fs_file M_fs_file_t
 
typedef struct M_fs_dir_entry M_fs_dir_entry_t
 
typedef struct M_fs_dir_entries M_fs_dir_entries_t
 
typedef struct M_fs_progress M_fs_progress_t
 
typedef M_bool(* M_fs_dir_walk_cb_t) (const char *path, M_fs_dir_entry_t *entry, M_fs_error_t res, void *thunk)
 
typedef M_bool(* M_fs_progress_cb_t) (const M_fs_progress_t *p)
 

Enumerations

enum  M_fs_error_t {
  M_FS_ERROR_SUCCESS = 0 ,
  M_FS_ERROR_GENERIC ,
  M_FS_ERROR_INVALID ,
  M_FS_ERROR_PERMISSION ,
  M_FS_ERROR_NOT_SUPPORTED ,
  M_FS_ERROR_IO ,
  M_FS_ERROR_SEEK ,
  M_FS_ERROR_READONLY ,
  M_FS_ERROR_QUOTA ,
  M_FS_ERROR_DNE ,
  M_FS_ERROR_NAMETOOLONG ,
  M_FS_ERROR_FILE_EXISTS ,
  M_FS_ERROR_FILE_2BIG ,
  M_FS_ERROR_FILE_2MANY ,
  M_FS_ERROR_ISDIR ,
  M_FS_ERROR_NOTDIR ,
  M_FS_ERROR_DIR_NOTEMPTY ,
  M_FS_ERROR_LINK_LOOP ,
  M_FS_ERROR_LINK_2MANY ,
  M_FS_ERROR_NOT_SAMEDEV ,
  M_FS_ERROR_CANCELED
}
 
enum  M_fs_iostream_t {
  M_FS_IOSTREAM_IN = 0 ,
  M_FS_IOSTREAM_OUT ,
  M_FS_IOSTREAM_ERR
}
 
enum  M_fs_perms_mode_t {
  M_FS_PERMS_MODE_NONE = 0 ,
  M_FS_PERMS_MODE_READ = 1 << 0 ,
  M_FS_PERMS_MODE_WRITE = 1 << 1 ,
  M_FS_PERMS_MODE_EXEC = 1 << 2
}
 
enum  M_fs_perms_type_t {
  M_FS_PERMS_TYPE_EXACT = 0 ,
  M_FS_PERMS_TYPE_ADD ,
  M_FS_PERMS_TYPE_REMOVE
}
 
enum  M_fs_perms_who_t {
  M_FS_PERMS_WHO_USER = 0 ,
  M_FS_PERMS_WHO_GROUP ,
  M_FS_PERMS_WHO_OTHER
}
 
enum  M_fs_path_norm_t {
  M_FS_PATH_NORM_NONE = 0 ,
  M_FS_PATH_NORM_ABSOLUTE = 1 << 0 ,
  M_FS_PATH_NORM_FOLLOWSYMLINKS = 1 << 1 ,
  M_FS_PATH_NORM_SYMLINKS_FAILDNE = 1 << 2 ,
  M_FS_PATH_NORM_SYMLINKS_FAILDNELAST = 1 << 3 ,
  M_FS_PATH_NORM_HOME = 1 << 4 ,
  M_FS_PATH_NORM_NOPARENT = 1 << 5
}
 
enum  M_fs_info_flags_t {
  M_FS_PATH_INFO_FLAGS_NONE = 0 ,
  M_FS_PATH_INFO_FLAGS_FOLLOW_SYMLINKS = 1 << 0 ,
  M_FS_PATH_INFO_FLAGS_BASIC = 1 << 1
}
 
enum  M_fs_file_mode_t {
  M_FS_FILE_MODE_NONE = 0 ,
  M_FS_FILE_MODE_READ = 1 << 0 ,
  M_FS_FILE_MODE_WRITE = 1 << 1 ,
  M_FS_FILE_MODE_NOCREATE = 1 << 2 ,
  M_FS_FILE_MODE_APPEND = 1 << 3 ,
  M_FS_FILE_MODE_OVERWRITE = 1 << 4 ,
  M_FS_FILE_MODE_PRESERVE_PERMS = 1 << 5 ,
  M_FS_FILE_MODE_NOCLOSEEXEC = 1 << 6
}
 
enum  M_fs_file_read_write_t {
  M_FS_FILE_RW_NORMAL = 0 ,
  M_FS_FILE_RW_FULLBUF = 1 << 0
}
 
enum  M_fs_file_seek_t {
  M_FS_FILE_SEEK_BEGIN = 0 ,
  M_FS_FILE_SEEK_END ,
  M_FS_FILE_SEEK_CUR
}
 
enum  M_fs_file_sync_t {
  M_FS_FILE_SYNC_NONE = 0 ,
  M_FS_FILE_SYNC_BUFFER = 1 << 0 ,
  M_FS_FILE_SYNC_OS = 1 << 1
}
 
enum  M_fs_dir_walk_filter_t {
  M_FS_DIR_WALK_FILTER_NONE = 0 ,
  M_FS_DIR_WALK_FILTER_FILE = 1 << 0 ,
  M_FS_DIR_WALK_FILTER_DIR = 1 << 1 ,
  M_FS_DIR_WALK_FILTER_PIPE = 1 << 2 ,
  M_FS_DIR_WALK_FILTER_SYMLINK = 1 << 3 ,
  M_FS_DIR_WALK_FILTER_HIDDEN = 1 << 4 ,
  M_FS_DIR_WALK_FILTER_RECURSE = 1 << 5 ,
  M_FS_DIR_WALK_FILTER_FOLLOWSYMLINK = 1 << 6 ,
  M_FS_DIR_WALK_FILTER_JAIL_FAIL = 1 << 7 ,
  M_FS_DIR_WALK_FILTER_JAIL_SKIP = 1 << 8 ,
  M_FS_DIR_WALK_FILTER_AS_SET = 1 << 9 ,
  M_FS_DIR_WALK_FILTER_READ_INFO_BASIC = 1 << 10 ,
  M_FS_DIR_WALK_FILTER_READ_INFO_FULL = 1 << 11 ,
  M_FS_DIR_WALK_FILTER_CASECMP = 1 << 12
}
 
enum  M_fs_dir_sort_t {
  M_FS_DIR_SORT_NAME_CASECMP = 0 ,
  M_FS_DIR_SORT_NAME_CMP ,
  M_FS_DIR_SORT_ISDIR ,
  M_FS_DIR_SORT_ISHIDDEN ,
  M_FS_DIR_SORT_NONE ,
  M_FS_DIR_SORT_SIZE ,
  M_FS_DIR_SORT_ATIME ,
  M_FS_DIR_SORT_MTIME ,
  M_FS_DIR_SORT_CTIME
}
 
enum  M_fs_progress_flags_t {
  M_FS_PROGRESS_NOEXTRA = 0 ,
  M_FS_PROGRESS_COUNT = 1 << 0 ,
  M_FS_PROGRESS_SIZE_TOTAL = 1 << 1 ,
  M_FS_PROGRESS_SIZE_CUR = 1 << 2
}
 
enum  M_fs_system_t {
  M_FS_SYSTEM_AUTO = 0 ,
  M_FS_SYSTEM_WINDOWS ,
  M_FS_SYSTEM_UNIX
}
 
enum  M_fs_type_t {
  M_FS_TYPE_UNKNOWN = 0 ,
  M_FS_TYPE_FILE ,
  M_FS_TYPE_DIR ,
  M_FS_TYPE_PIPE ,
  M_FS_TYPE_SYMLINK
}
 

Detailed Description

Macro Definition Documentation

◆ M_FS_PATH_NORM_RESDIR

◆ M_FS_PATH_NORM_RESALL

◆ M_FS_DIR_WALK_FILTER_ALL

◆ M_FS_BUF_SIZE

#define M_FS_BUF_SIZE   1024

Typedef Documentation

◆ M_fs_perms_t

typedef struct M_fs_perms M_fs_perms_t

◆ M_fs_info_t

typedef struct M_fs_info M_fs_info_t

◆ M_fs_file_t

typedef struct M_fs_file M_fs_file_t

◆ M_fs_dir_entry_t

typedef struct M_fs_dir_entry M_fs_dir_entry_t

◆ M_fs_dir_entries_t

typedef struct M_fs_dir_entries M_fs_dir_entries_t

◆ M_fs_progress_t

typedef struct M_fs_progress M_fs_progress_t

◆ M_fs_dir_walk_cb_t

typedef M_bool(* M_fs_dir_walk_cb_t) (const char *path, M_fs_dir_entry_t *entry, M_fs_error_t res, void *thunk)

Walk callback function prototype.

Parameters
[in]pathThe path passed into walk.
[in]entryThe entry created for the location. The cb will have ownership of the entry. It is up to the cb to save or destroy the entry.
[in]resThe status of the entry. A success should be treat the entry as a good entry for the purpose of the callback. Any other result should be treated as an error condition and it is up to the callback as to how it should be handled. For example and infinite recursion loop due to circular symlinks will have an entry denoting which link causes the loop and a result of M_FS_ERROR_LINK_LOOP.
[in]thunkAdditional data passed to walk for use in this callback.
Returns
M_TRUE if walk should continue. M_FALSE if the walk should be cancelled.

◆ M_fs_progress_cb_t

typedef M_bool(* M_fs_progress_cb_t) (const M_fs_progress_t *p)

File operation progress callback function prototype.

Many file and directory operations (move, copy, delete...) can report their progress as the operation is run.

Parameters
pThe progress object. Contains information about the status of the operation. The object is only valid until the callback returns; it should not be stored.
Returns
M_TRUE if the operation should continue. M_FALSE if the operation should be cancelled.

Enumeration Type Documentation

◆ M_fs_error_t

Error codes.

Enumerator
M_FS_ERROR_SUCCESS 

Operation completed successfully

M_FS_ERROR_GENERIC 

Generic, uncategorized error

M_FS_ERROR_INVALID 

Invalid argument

M_FS_ERROR_PERMISSION 

Operation not permitted

M_FS_ERROR_NOT_SUPPORTED 

Operation not supported

M_FS_ERROR_IO 

Input/output error

M_FS_ERROR_SEEK 

Invalid seek

M_FS_ERROR_READONLY 

Read-only file system

M_FS_ERROR_QUOTA 

Disk quota exceeded

M_FS_ERROR_DNE 

No such file or directory

M_FS_ERROR_NAMETOOLONG 

Filename too long

M_FS_ERROR_FILE_EXISTS 

File exists

M_FS_ERROR_FILE_2BIG 

File too large

M_FS_ERROR_FILE_2MANY 

Too many open files

M_FS_ERROR_ISDIR 

Is a directory

M_FS_ERROR_NOTDIR 

Not a directory

M_FS_ERROR_DIR_NOTEMPTY 

Directory not empty

M_FS_ERROR_LINK_LOOP 

Too many levels of symbolic links

M_FS_ERROR_LINK_2MANY 

Too many links

M_FS_ERROR_NOT_SAMEDEV 

Cannot move across mount points.

M_FS_ERROR_CANCELED 

The operation was canceled (typically by user interaction).

◆ M_fs_iostream_t

Standard streams for input and output.

Enumerator
M_FS_IOSTREAM_IN 
M_FS_IOSTREAM_OUT 
M_FS_IOSTREAM_ERR 

◆ M_fs_perms_mode_t

File permissions. Based on POSIX file permissions.

Enumerator
M_FS_PERMS_MODE_NONE 

No perms.

M_FS_PERMS_MODE_READ 

Read.

M_FS_PERMS_MODE_WRITE 

Write.

M_FS_PERMS_MODE_EXEC 

Execute.

◆ M_fs_perms_type_t

How should the perms be modified.

Enumerator
M_FS_PERMS_TYPE_EXACT 

Perms are exactly what is set.

M_FS_PERMS_TYPE_ADD 

Perms will be added to existing perms.

M_FS_PERMS_TYPE_REMOVE 

Perms will be removed from existing perms.

◆ M_fs_perms_who_t

Who do the given perms apply to. Based on POSIX file permissions.

Enumerator
M_FS_PERMS_WHO_USER 

User/owner.

M_FS_PERMS_WHO_GROUP 

Group.

M_FS_PERMS_WHO_OTHER 

Other.

◆ M_fs_path_norm_t

How should the path be normalized.

Enumerator
M_FS_PATH_NORM_NONE 
M_FS_PATH_NORM_ABSOLUTE 

Use the current working directory to determine absolute path if provided path is relative.

M_FS_PATH_NORM_FOLLOWSYMLINKS 

Follow sym links. This will succeed if even if the path pointed by by the symlink does not exist.

M_FS_PATH_NORM_SYMLINKS_FAILDNE 

Follow sym links. Fail if the location pointed to by the link does not exist excluding the last location in the path.

M_FS_PATH_NORM_SYMLINKS_FAILDNELAST 

Follow sym links. Fail if only the last location pointed to by the link does not exist.

M_FS_PATH_NORM_HOME 

Normalize ~/ to $HOME.

M_FS_PATH_NORM_NOPARENT 

Do NOT Normalize ../ paths.

◆ M_fs_info_flags_t

How should a path's info be read.

Enumerator
M_FS_PATH_INFO_FLAGS_NONE 

Normal operation. Get all info for the given location.

M_FS_PATH_INFO_FLAGS_FOLLOW_SYMLINKS 

If the location is symlink get the info for the location pointed to by the link and not the link itself.

M_FS_PATH_INFO_FLAGS_BASIC 

Get basic info only. Excludes:

  • User and group.
  • Permissions.

◆ M_fs_file_mode_t

File interaction.

Enumerator
M_FS_FILE_MODE_NONE 

No mode specified.

M_FS_FILE_MODE_READ 

Read.

M_FS_FILE_MODE_WRITE 

Write.

M_FS_FILE_MODE_NOCREATE 

Do not create the file if it does not exist.

M_FS_FILE_MODE_APPEND 

Only write at the end of the file.

M_FS_FILE_MODE_OVERWRITE 

Overwrite the file (truncate) if it exists.

M_FS_FILE_MODE_PRESERVE_PERMS 

Move/Copy use the perms from the original file. This only preserves permissions that can be expressed by an M_fs_perms_t object. ACLs for example will not be persevered.

M_FS_FILE_MODE_NOCLOSEEXEC 

Allow sharing of file descriptors with fork executed processes.

◆ M_fs_file_read_write_t

Read / Write behavior

Enumerator
M_FS_FILE_RW_NORMAL 

Normal operation

M_FS_FILE_RW_FULLBUF 

Read until the given buffer is full or until there is no more data to read. Write all data in the buffer. Normal operation is to return after the system reads/writes what it can. This will cause the read/write to retry until the given all data is read/written.

◆ M_fs_file_seek_t

Seeking within a file.

Enumerator
M_FS_FILE_SEEK_BEGIN 

Seek relative to the beginning of the file.

M_FS_FILE_SEEK_END 

Seek relative to the end of the file .

M_FS_FILE_SEEK_CUR 

Seek relative to the current location

◆ M_fs_file_sync_t

How should data be synced to disk.

Enumerator
M_FS_FILE_SYNC_NONE 

No sync.

M_FS_FILE_SYNC_BUFFER 

Internal write buffer should be synced (fflush)

M_FS_FILE_SYNC_OS 

OS buffer should be synced (fsync)

◆ M_fs_dir_walk_filter_t

Controls the behavior of walk. Specifies how the walk should be performed and what should be stored in the result of the walk.

Enumerator
M_FS_DIR_WALK_FILTER_NONE 

No filters.

M_FS_DIR_WALK_FILTER_FILE 

Include files in the list of entries. Anything that is not another type is considered a file.

M_FS_DIR_WALK_FILTER_DIR 

Include directories in the list of entries.

M_FS_DIR_WALK_FILTER_PIPE 

Include pipes in the list of entries.

M_FS_DIR_WALK_FILTER_SYMLINK 

Include symlinks in the list of entries.

M_FS_DIR_WALK_FILTER_HIDDEN 

Include hidden locations in the list of entries.

M_FS_DIR_WALK_FILTER_RECURSE 

Recurse into directories and include their contents. File system loops (infinite redirects due to symlinks) will be ignored.

M_FS_DIR_WALK_FILTER_FOLLOWSYMLINK 

Should symlinks be followed.

M_FS_DIR_WALK_FILTER_JAIL_FAIL 

Fail walk if redirection outside of base path.

M_FS_DIR_WALK_FILTER_JAIL_SKIP 

Skip entry if redirection outside of base path.

M_FS_DIR_WALK_FILTER_AS_SET 

Only include a given entry once. Symlinks could cause a file or directory to show up multiple times in a walk this will exclude the additional entries. Also, only one symlink to a given entry will be included. For example, if there are two symlinks to the same file one symlink will be ingored.

M_FS_DIR_WALK_FILTER_READ_INFO_BASIC 

Read/store basic info about the entry. Specifically:

  • Is dir.
  • Is hidden.
  • File size.
  • Access time.
  • Last modification time.
  • Creation time.
M_FS_DIR_WALK_FILTER_READ_INFO_FULL 

Read/Store all info about the entry. Specifically:

  • All basic info.
  • User and Group.
  • Permissions.
M_FS_DIR_WALK_FILTER_CASECMP 

The pattern matching should be compared to the path in a case insensitive manner.

◆ M_fs_dir_sort_t

Sorting methods. Some of these methods require the file info. If the file info was not retrieved (walk did not have a M_FS_DIR_WALK_FILTER_READ_INFO_* filter set) all files are considered equal.

Enumerator
M_FS_DIR_SORT_NAME_CASECMP 

Sort by name case insensitive.

M_FS_DIR_SORT_NAME_CMP 

Sort by name case sensitive.

M_FS_DIR_SORT_ISDIR 

Sort by is directory.

M_FS_DIR_SORT_ISHIDDEN 

Sort by hidden status.

M_FS_DIR_SORT_NONE 

Don't sort. This is an option because sorting can have primary and secondary. This allows only a primary sort to be applied.

M_FS_DIR_SORT_SIZE 

Sort by file size.

M_FS_DIR_SORT_ATIME 

Sort by last access time.

M_FS_DIR_SORT_MTIME 

Sort by last modification time.

M_FS_DIR_SORT_CTIME 

Sort by create time.

◆ M_fs_progress_flags_t

Determines what progress information should be reported to the progress callback. Size reporting will increase the amount of time required for processing due to needing to get and calculate totals.

Enumerator
M_FS_PROGRESS_NOEXTRA 

Don't provide optional reporting. Will be overridden by other flags.

M_FS_PROGRESS_COUNT 

Report on number of operations total and completed.

M_FS_PROGRESS_SIZE_TOTAL 

Report the total size for all file operations and the total completed.

M_FS_PROGRESS_SIZE_CUR 

Report the total size for the current file being processed and the total size of the file completed.

◆ M_fs_system_t

Controls how path should be constructed.

Enumerator
M_FS_SYSTEM_AUTO 

Automatically set based on current system.

M_FS_SYSTEM_WINDOWS 

Forcibly use windows logic.

M_FS_SYSTEM_UNIX 

Forcibly use Unix logic.

◆ M_fs_type_t

Types of file objects.

Enumerator
M_FS_TYPE_UNKNOWN 

The location is an unknown type. Typically this means it was not read.

M_FS_TYPE_FILE 

The location is a regular file.

M_FS_TYPE_DIR 

The location is a directory.

M_FS_TYPE_PIPE 

The location is a fifo (pipe).

M_FS_TYPE_SYMLINK 

The location is a symbolic link.