Add sysfs VFS driver, SYS_OPEN/CLOSE syscalls, cat app
Sysfs: - New VFS driver mounted at /sys that lets kernel drivers expose virtual text files via namespace registration - Drivers call sysfs_register(name, ops, ctx) with list/read/write callbacks for their namespace - IDE driver registers 'ide' namespace exposing per-device attributes: model, type, channel, drive, sectors, sector_size - Tested: ls /sys -> ide, ls /sys/ide -> hdd1 cd1, cat /sys/ide/hdd1/model -> QEMU HARDDISK Syscalls: - Added SYS_OPEN (11) and SYS_CLOSE (12) for file I/O from userspace - Extended SYS_READ/SYS_WRITE to handle VFS file descriptors (fd >= 3) - Updated userspace syscalls.h with open()/close() wrappers Apps: - New 'cat' app: reads and displays file contents via open/read/close - Updated 'ls' to accept path argument via ARG1 env var - Updated shell to pass ARG1 env var to external commands
This commit is contained in:
@@ -24,6 +24,8 @@ typedef int int32_t;
|
||||
#define SYS_GETENV 8
|
||||
#define SYS_SETENV 9
|
||||
#define SYS_READDIR 10
|
||||
#define SYS_OPEN 11
|
||||
#define SYS_CLOSE 12
|
||||
|
||||
static inline int32_t syscall0(int num) {
|
||||
int32_t ret;
|
||||
@@ -103,6 +105,25 @@ static inline int32_t readdir(const char *path, uint32_t idx, char *name) {
|
||||
return syscall3(SYS_READDIR, (uint32_t)path, idx, (uint32_t)name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a file by path.
|
||||
* @param path File path.
|
||||
* @param flags Open flags (currently unused, pass 0).
|
||||
* @return File descriptor (>= 3) on success, -1 on failure.
|
||||
*/
|
||||
static inline int32_t open(const char *path, uint32_t flags) {
|
||||
return syscall2(SYS_OPEN, (uint32_t)path, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a file descriptor.
|
||||
* @param fd File descriptor.
|
||||
* @return 0 on success, -1 on failure.
|
||||
*/
|
||||
static inline int32_t close(int32_t fd) {
|
||||
return syscall1(SYS_CLOSE, (uint32_t)fd);
|
||||
}
|
||||
|
||||
/* Basic string operations for user-space */
|
||||
static inline uint32_t strlen(const char *s) {
|
||||
uint32_t len = 0;
|
||||
|
||||
Reference in New Issue
Block a user