This repository contains the implementation of a software bridge between the file-related system calls inside the OS/161 kernel and their functionality within the VFS. Upon completion, the OS/161 system will support running a single user-level application with basic file I/O operations.
The primary focus of this project is to:
- Understand the OS/161 kernel architecture.
- Implement the required file-based system calls:
open,read,write,lseek,close, anddup2. - Design robust system call interfaces and structures.
Optionally, an advanced implementation includes process-related system calls and the ability to run multiple applications.
-
Basic Project:
- Transform OS/161 into an operating system capable of running compiled user-level programs.
- Implement part of the interface between user-mode programs and the kernel.
- Provide support for system calls related to file manipulation.
-
Advanced Project (Optional):
- Add process-related system calls.
- Allow concurrent execution of multiple processes.
The following system calls are implemented:
open()read()write()lseek()close()dup2()
All system calls are designed to gracefully handle error conditions as per the OS/161 man pages, ensuring the system remains stable under various scenarios.
stdin(0) can remain unattached.stdout(1) andstderr(2) are attached to the console device (con:).- Programs can use
dup2()to change these descriptors.
The System/161 simulator can execute user-level C programs compiled using os161-gcc, producing MIPS executables. A variety of pre-existing programs are available in the following directories:
userland/binuserland/testbinuserland/sbin
New programs for testing purposes can be added by modifying the Makefile and creating directories similar to the existing ones.
- Plan Before Coding: A robust design was developed before implementation, focusing on understanding the problem and determining the relationship between components.
- Focus on State Management: System calls are primarily about managing file descriptors and filesystem state.
- Scalability: While the basic project assumes single-process execution, the implementation was designed to support future multi-process capabilities.
- File Descriptor Management: Each process maintains its own file descriptor table. Shared state (e.g., open file table) is designed to be concurrency-safe for future multi-process extensions.
- Kernel/User Space Interface: System calls were designed to handle erroneous arguments and prevent user programs from crashing the kernel.
- Kernel function prototypes are defined in
kern/include/syscall.horkern/include/file.h. - Implementations are located in
kern/syscall/file.c.
The implementation utilizes the existing VFS layer for low-level file operations, focusing on designing and managing higher-level abstractions such as file descriptors and process-specific state.
- Error Handling: Ensure that your syscalls return the correct values or error codes as specified in the OS/161 man pages.
- Standard Input/Output: Modify
runprogram()to initializestdoutandstderrcorrectly. - Memory Management: Your implementation must be memory-leak-free.