Files
claude-os/apps/ls/ls.c
AI d1bf69ce0d 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
2026-02-23 14:26:52 +00:00

39 lines
877 B
C

/**
* @file ls.c
* @brief List directory contents.
*
* Lists entries in the current working directory (from the CWD
* environment variable). Uses the SYS_READDIR syscall to enumerate
* directory entries.
*/
#include "syscalls.h"
int main(void) {
/* Check for an explicit path argument first */
char cwd[128];
if (getenv("ARG1", cwd, sizeof(cwd)) < 0 || cwd[0] == '\0') {
/* No argument; use the current working directory */
if (getenv("CWD", cwd, sizeof(cwd)) < 0) {
cwd[0] = '/';
cwd[1] = '\0';
}
}
char name[128];
uint32_t idx = 0;
int32_t type;
while ((type = readdir(cwd, idx, name)) >= 0) {
puts(name);
if (type == 2) {
/* Directory: append / indicator */
putchar('/');
}
putchar('\n');
idx++;
}
return 0;
}