Skip to content

Implement filesystem syscalls (open/read/write/lseek/close) #60

@pbalduino

Description

@pbalduino

Goal

Implement filesystem-related system calls, wiring them through the VFS layer to provide POSIX-like file operations.

Context

This layer connects userspace file operations to the kernel VFS system, enabling user programs to work with files and directories.

Definition of Done

  • File operations: open, read, write, lseek, close syscalls
  • Directory operations: opendir, readdir, closedir functionality
  • Metadata operations: stat, fstat, access syscalls
  • File creation: creat, mkdir, unlink, rmdir syscalls
  • File positioning: lseek with SEEK_SET, SEEK_CUR, SEEK_END
  • Error handling: Proper errno setting and error propagation
  • Security: Basic permission checking and validation

Syscall Implementation

File Operations

Directory Operations

Metadata Operations

Implementation Details

  • Add syscall numbers to syscall table
  • Implement syscall handlers that validate parameters
  • Wire syscall handlers to VFS operations
  • Add proper error handling and errno setting
  • Implement file descriptor validation
  • Add userspace pointer validation for safety

File Descriptor Management

  • Extend existing fd table for file operations
  • Handle fd allocation, deallocation, and reuse
  • Support standard descriptors (stdin=0, stdout=1, stderr=2)
  • Implement fd limits and resource management

Permission and Security

  • Basic permission checking (read/write/execute)
  • Path validation and canonicalization
  • Protection against directory traversal attacks
  • Proper handling of special files and devices

Error Handling

  • Standard errno values (ENOENT, EACCES, EINVAL, etc.)
  • Consistent error propagation from VFS to userspace
  • Proper cleanup on error conditions
  • Resource leak prevention

Files to Create/Modify

  • syscall/fs_syscalls.c - Filesystem syscall implementations
  • syscall/syscall_table.c - Add new syscall numbers
  • include/syscall_numbers.h - Define syscall constants
  • vfs integration points

Userspace Interface

  • Update syscall number definitions for userspace
  • Provide basic libc-style wrappers
  • Add error handling examples
  • Create simple file operation examples

Testing Strategy

  • Test basic file operations (create, read, write, delete)
  • Test directory operations (create, list, delete)
  • Test error conditions (invalid paths, permissions)
  • Test file positioning and seeking
  • Test concurrent file access

POSIX Compatibility

  • Follow POSIX semantics where possible
  • Standard return values and error codes
  • Compatible file descriptor behavior
  • Standard file permission model

Dependencies

  • VFS layer implementation
  • Extended syscall dispatcher
  • Userspace memory validation
  • Process file descriptor tables

Related Issues

Part of filesystem support stack - enables userspace file operations.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions