|
miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
|


Go to the source code of this file.
Classes | |
| struct | vfs_inode_info |
| struct | vfs_statfs |
| struct | vfs_ops |
| struct | filesystem_type |
| struct | vfs_mount |
| struct | vfs_file |
Macros | |
| #define | VFS_MAX_FDS 64 /* max open files per task */ |
| #define | VFS_PATH_MAX 256 /* max path length */ |
| #define | VFS_FD_STDIN 0 |
| #define | VFS_FD_STDOUT 1 |
| #define | VFS_FD_STDERR 2 |
| #define | VFS_FIRST_OPEN_FD 3 |
| #define | VFS_FILE_TYPE_REG 1 |
| #define | VFS_FILE_TYPE_DIR 2 |
| #define | VFS_FILE_TYPE_PIPE 3 /* anonymous pipe backed by ring buffer */ |
| #define | VFS_FILE_TYPE_SYMLINK 4 /* symbolic link; used by lstat to detect symlink targets */ |
| #define | VFS_FILE_TYPE_CHAR 5 /* character device node */ |
| #define | VFS_FILE_TYPE_BLK 6 /* block device node */ |
| #define | VFS_FILE_TYPE_SOCKET 7 /* BSD-style socket backed by lwIP PCB */ |
| #define | VFS_FILE_TYPE_UNIX_SOCKET 8 /* AF_UNIX socket backed by unix_sock_t */ |
| #define | VFS_DEVICE_NONE 0 |
| #define | VFS_DEVICE_TTY 1 |
| #define | VFS_DEVICE_NULL 2 |
| #define | VFS_MAX_FS_TYPES 16 |
| #define | VFS_MAX_MOUNTS 16 |
Typedefs | |
| typedef struct vfs_inode_info | vfs_inode_info_t |
| typedef struct vfs_statfs | vfs_statfs_t |
| typedef struct vfs_ops | vfs_ops_t |
| typedef struct filesystem_type | filesystem_type_t |
| typedef struct vfs_mount | vfs_mount_t |
| typedef struct vfs_file | vfs_file_t |
Functions | |
| int | register_filesystem (const char *name, int(*mount)(const char *source, const char *target, const void *data)) |
| int | vfs_mount_fstype (const char *fstype, const char *source, const char *target, const void *data) |
| int | vfs_register_mount (const char *point, vfs_ops_t *ops, uint32_t root_ino) |
| int | vfs_mount_count (void) |
| const vfs_mount_t * | vfs_get_mount (int idx) |
| int | vfs_path_devno (const char *path) |
| int | vfs_fd_devno (int fd) |
| void | vfs_mount (vfs_ops_t *ops) |
| int | vfs_open (const char *path, int flags, int mode) |
| int | vfs_read (int fd, void *buf, uint32_t len) |
| int | vfs_readdir (int fd, vfs_dirent_cb_t cb, void *ud) |
| int | vfs_write (int fd, const void *buf, uint32_t len) |
| int | vfs_close (int fd) |
| int | vfs_unlink (const char *path) |
| int | vfs_rename (const char *oldpath, const char *newpath) |
| int | vfs_rmdir (const char *path) |
| int | vfs_mkdir (const char *path, int mode) |
| int | vfs_stat (const char *path, vfs_inode_info_t *out) |
| int | vfs_statfs (const char *path, vfs_statfs_t *out) |
| int | vfs_fstatfs (int fd, vfs_statfs_t *out) |
| int | vfs_fstat (int fd, vfs_inode_info_t *out) |
| int | vfs_lstat (const char *path, vfs_inode_info_t *out) |
| int | vfs_symlink (const char *path, const char *target) |
| int | vfs_chmod (const char *path, uint16_t mode) |
| int | vfs_mknod (const char *path, uint16_t mode, uint32_t dev) |
| int | vfs_readlink (const char *path, char *buf, uint32_t bufsiz) |
| #define VFS_DEVICE_NONE 0 |
| #define VFS_DEVICE_NULL 2 |
| #define VFS_DEVICE_TTY 1 |
| #define VFS_FD_STDERR 2 |
| #define VFS_FD_STDIN 0 |
| #define VFS_FD_STDOUT 1 |
| #define VFS_FILE_TYPE_BLK 6 /* block device node */ |
| #define VFS_FILE_TYPE_CHAR 5 /* character device node */ |
| #define VFS_FILE_TYPE_DIR 2 |
| #define VFS_FILE_TYPE_REG 1 |
| #define VFS_FILE_TYPE_SOCKET 7 /* BSD-style socket backed by lwIP PCB */ |
| #define VFS_FILE_TYPE_UNIX_SOCKET 8 /* AF_UNIX socket backed by unix_sock_t */ |
| #define VFS_FIRST_OPEN_FD 3 |
| #define VFS_MAX_FDS 64 /* max open files per task */ |
| #define VFS_MAX_FS_TYPES 16 |
| #define VFS_MAX_MOUNTS 16 |
| #define VFS_PATH_MAX 256 /* max path length */ |
| typedef struct filesystem_type filesystem_type_t |
| typedef struct vfs_file vfs_file_t |
| typedef struct vfs_inode_info vfs_inode_info_t |
| typedef struct vfs_mount vfs_mount_t |
| typedef struct vfs_statfs vfs_statfs_t |
| int register_filesystem | ( | const char * | name, |
| int(* | mount )(const char *source, const char *target, const void *data) ) |


| int vfs_chmod | ( | const char * | path, |
| uint16_t | mode ) |
vfs_chmod() - Change the permission bits of a file by absolute path. @path: Absolute path to the file. @mode: New permission bits (low 12 bits only; type bits are preserved).


| int vfs_close | ( | int | fd | ) |
vfs_close() - Release an open file descriptor, flushing write data to disk. @fd: File descriptor to close (0 to VFS_MAX_FDS-1).
If the file was opened with write flags and ops->flush is set, calls ops->flush(inode) to write back the final inode state, then calls ata_flush() to push the ATA write-back cache to stable storage. Clears the in_use flag in the calling task's fd_table entry.
vfs_close() - Release an open file descriptor, flushing write data to disk. @fd: File descriptor to close.
If the file was opened with write flags and ops->flush is set, calls ops->flush(inode) to write back the final inode state, then calls ata_flush() to push the ATA write-back cache to stable storage (EXT2W-07).


| int vfs_fd_devno | ( | int | fd | ) |


| int vfs_fstat | ( | int | fd, |
| vfs_inode_info_t * | out ) |
vfs_fstat() - Get metadata from an open file descriptor. @fd: Open file descriptor. @out: Output struct populated on success.
vfs_fstat() - Get file metadata from an open file descriptor. @fd: Open fd (must be VFS_FIRST_OPEN_FD <= fd < VFS_MAX_FDS, in_use). @out: Populated with inode, ftype, size on success.


| int vfs_fstatfs | ( | int | fd, |
| vfs_statfs_t * | out ) |


| const vfs_mount_t * vfs_get_mount | ( | int | idx | ) |

| int vfs_lstat | ( | const char * | path, |
| vfs_inode_info_t * | out ) |
vfs_lstat() - Look up file metadata by absolute path WITHOUT following symlinks. @path: Absolute path. @out: Output struct populated on success.


| int vfs_mkdir | ( | const char * | path, |
| int | mode ) |
vfs_mkdir() - Create a directory by absolute path. @path: Absolute path of the new directory (e.g., "/tmp/newdir"). @mode: Permission bits (accepted, passed through to ops->mkdir).


vfs_mknod() - Create a device special file by absolute path. @path: Absolute path of the new device node. @mode: EXT2_S_IFCHR|perms or EXT2_S_IFBLK|perms. @dev: Encoded device number (major<<8)|minor.


| void vfs_mount | ( | vfs_ops_t * | ops | ) |
vfs_mount() - Register a filesystem's operations table (backwards-compat shim). @ops: Pointer to a vfs_ops_t struct with lookup, read, and readdir function pointers. Must point to static storage valid for the kernel lifetime.
Calls vfs_register_mount("/", ops) to mount the filesystem at root. Kept for backwards compatibility — prefer vfs_register_mount() for new code.
vfs_mount() - Store the filesystem ops table at root "/" (backwards-compat shim). @ops: Pointer to filesystem ops (must have lookup, read, readdir set).
Calls vfs_register_mount("/", ops). Kept for backwards compatibility.

| int vfs_mount_count | ( | void | ) |

| int vfs_mount_fstype | ( | const char * | fstype, |
| const char * | source, | ||
| const char * | target, | ||
| const void * | data ) |
vfs_mount_fstype() - Look up a registered filesystem type and mount it. @fstype: Filesystem type name (e.g. "ext2", "sysfs"). @source: Device/source string forwarded to the mount callback (may be NULL). @target: Absolute mount point path (e.g. "/", "/sys"). @data: Filesystem-specific options pointer forwarded to the mount callback (may be NULL for pseudo-filesystems that need no extra parameters).


| int vfs_open | ( | const char * | path, |
| int | flags, | ||
| int | mode ) |
vfs_open() - Open or create a file by absolute path. @path: Absolute path to the file or directory (e.g., "/etc/passwd"). @flags: O_RDONLY (0), O_WRONLY (1), O_CREAT (0x0200). O_CREAT creates file if missing. @mode: File permission bits (accepted but ignored; all files created with 0644).
Calls g_mounted_ops->lookup() to resolve the path to typed inode metadata. If O_CREAT is set and file not found, creates a new file via ext2_create(). Allocates a file descriptor in the calling task's fd_table (per-thread; up to VFS_MAX_FDS=16 concurrent open files). Initialises the vfs_file_t entry with offset=0 and the resolved inode metadata.
vfs_open() - Open or create a file by absolute path. @path: Absolute path. @flags: O_RDONLY (0), O_WRONLY (1), O_CREAT (0x0200). O_CREAT creates file if missing. O_TRUNC (0x0400): Truncate existing regular file to zero on open. @mode: File permission bits for O_CREAT (lower 9 bits used; 0 → 0644 default). Write permission on the parent directory is enforced before creation.
Resolves path through the mount table using longest-prefix match. If O_CREAT is set and lookup fails: parses the parent path, looks up parent inode, and calls the FS create op to allocate a new inode and directory entry.


| int vfs_path_devno | ( | const char * | path | ) |


| int vfs_read | ( | int | fd, |
| void * | buf, | ||
| uint32_t | len ) |
vfs_read() - Read bytes from an open file descriptor. @fd: File descriptor returned by vfs_open. @buf: Destination buffer. @len: Maximum number of bytes to read.
Dispatches to g_mounted_ops->read() with the fd's inode number and current offset. Advances the offset by the number of bytes read.
vfs_read() - Dispatch a read to the mounted filesystem. @fd: Open file descriptor. @buf: Destination buffer. @len: Byte count requested.
Validates fd in range and in_use. Calls fd_table[fd].ops->read() with the stored inode and current offset. Advances offset by bytes_read.


| int vfs_readdir | ( | int | fd, |
| vfs_dirent_cb_t | cb, | ||
| void * | ud ) |
vfs_readdir() - Iterate directory entries from an open directory fd. @fd: File descriptor of an open directory (must have ftype == VFS_FILE_TYPE_DIR). @cb: Callback invoked per entry (name, name_len, inode, file_type, ud). @ud: Opaque user data forwarded to @cb.
Dispatches to g_mounted_ops->readdir() with the fd's inode number and current directory offset.
vfs_readdir() - Dispatch directory iteration to the mounted filesystem. @fd: Open file descriptor (must be a directory; ftype == VFS_FILE_TYPE_DIR). @cb: Entry callback. @ud: Opaque user data for @cb.
Validates fd and ftype. Calls fd_table[fd].ops->readdir() with the stored inode, forwarding @cb and @ud.


| int vfs_readlink | ( | const char * | path, |
| char * | buf, | ||
| uint32_t | bufsiz ) |
vfs_readlink() - Read symlink target into buf without following. @path: Absolute path to a symlink inode. @buf: Output buffer (NOT null-terminated per POSIX). @bufsiz: Size of buf.


vfs_register_mount() - Register a filesystem at a mount point. @point: Absolute mount point path (e.g. "/", "/tmp"). Copied into mount table. @ops: Pointer to vfs_ops_t with at least lookup, read, readdir set.
Stores entry in g_mounts[]. Up to VFS_MAX_MOUNTS=8 mounts supported. @root_ino: Starting inode for path resolution (pass 0 for fs-default).
vfs_register_mount() - Register a filesystem at a mount point. @point: Absolute mount point path (e.g. "/", "/tmp"). Copied into mount table. @ops: Pointer to vfs_ops_t with at least lookup, read, readdir set.
Stores entry in g_mounts[]. Up to VFS_MAX_MOUNTS=8 mounts supported.


| int vfs_rename | ( | const char * | oldpath, |
| const char * | newpath ) |
vfs_rename() - Rename or move a file or directory. @oldpath: Absolute path of the source. @newpath: Absolute path of the destination.
Both paths must be on the same mounted filesystem (EXDEV otherwise). If @newpath already exists as a file it is atomically replaced. Directories cannot be overwritten (returns ENOTEMPTY).


| int vfs_rmdir | ( | const char * | path | ) |
vfs_rmdir() - Delete an empty directory by absolute path. @path: Absolute path of the directory to remove.
Resolves the mount point for @path, looks up the parent directory inode, then calls ops->rmdir(parent_ino, dirname).


| int vfs_stat | ( | const char * | path, |
| vfs_inode_info_t * | out ) |
vfs_stat() - Look up file metadata by absolute path. @path: Absolute path. @out: Output struct populated on success.
vfs_stat() - Look up file metadata by absolute path. @path: Absolute path to query. @out: Populated with inode, file_type, size on success.


| int vfs_statfs | ( | const char * | path, |
| vfs_statfs_t * | out ) |


| int vfs_symlink | ( | const char * | path, |
| const char * | target ) |
vfs_symlink() - Create a symbolic link at path pointing to target. @path: Absolute path of the new symlink. @target: Symlink target string (stored as-is; may be relative or absolute).


| int vfs_unlink | ( | const char * | path | ) |
vfs_unlink() - Delete a file by absolute path. @path: Absolute path of the file to remove (e.g., "/tmp/foo.txt").
Resolves the mount point for @path, looks up the parent directory inode, then calls ops->unlink(parent_ino, filename). Immediate deletion.


| int vfs_write | ( | int | fd, |
| const void * | buf, | ||
| uint32_t | len ) |
vfs_write() - Write bytes to an open file descriptor. @fd: File descriptor returned by vfs_open with O_WRONLY. @buf: Source buffer. @len: Number of bytes to write.
Dispatches to g_mounted_ops->write() with the fd's inode and current offset. Advances offset by the number of bytes written.
vfs_write() - Dispatch a write to the mounted filesystem. @fd: Open file descriptor with O_WRONLY flag. @buf: Source buffer. @len: Byte count to write.
Validates fd. Calls fd_table[fd].ops->write() with the stored inode and current offset. Advances offset and updates size if write extends file.

