# swayam0611/xv6-addinglseek architecture

> Architecture diagram of the GitHub repository swayam0611/xv6-addinglseek, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/swayam0611/xv6-addinglseek
- Repository: https://github.com/swayam0611/xv6-addinglseek

## Overview

This is xv6 with an added lseek system call. The principal workflow is a user running trylseek from the shell: the user-facing API enters the syscall dispatch path, which reaches the kernel implementation to adjust an inode-backed file offset. The implementation supports SEEK_SET, SEEK_CUR, and SEEK_END, checks bounds, locks the inode, and rejects pipes. The README documents these relationships and the test workflow; source excerpts do not show the syscall implementation itself, so the graph does not infer lower-level calls beyond those documented.

Main entry points: [`sysfile.c`](https://github.com/swayam0611/xv6-addinglseek/blob/main/sysfile.c) (Seek handler), [`trylseek.c`](https://github.com/swayam0611/xv6-addinglseek/blob/main/trylseek.c) (Seek demo), [`syscall.c`](https://github.com/swayam0611/xv6-addinglseek/blob/main/syscall.c) (Syscall dispatch), [`sh.c`](https://github.com/swayam0611/xv6-addinglseek/blob/main/sh.c) (xv6 shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_user["User programs"]
  node_shell["xv6 shell<br/>[sh.c]"]
  node_trylseek["Seek demo<br/>[trylseek.c]"]
  node_userapi["User API<br/>[user.h]"]
end

subgraph group_syscall["System call path"]
  node_syscallabi["Syscall numbers<br/>[syscall.h]"]
  node_dispatch["Syscall dispatch<br/>[syscall.c]"]
  node_seekimpl["Seek handler<br/>[sysfile.c]"]
  node_seekmodes["Seek modes<br/>[fcntl.h]"]
end

subgraph group_storage["File storage"]
  node_fileobject["Open file state<br/>[file.h]"]
  node_inodefs["Inode filesystem<br/>[fs.c]"]
  node_diskcache["Block cache<br/>[bio.c]"]
end

node_operator(("Shell user"))

node_operator -->|"runs commands"| node_shell
node_shell -->|"runs demo"| node_trylseek
node_trylseek -->|"calls lseek"| node_userapi
node_userapi -->|"enters syscall"| node_dispatch
node_syscallabi -->|"registers call"| node_dispatch
node_dispatch -->|"dispatches lseek"| node_seekimpl
node_seekimpl -->|"uses seek modes"| node_seekmodes
node_seekimpl -->|"checks file type"| node_fileobject
node_seekimpl -->|"locks inode"| node_inodefs
node_trylseek -.->|"tests seek results"| node_inodefs

click node_shell "https://github.com/swayam0611/xv6-addinglseek/blob/main/sh.c"
click node_trylseek "https://github.com/swayam0611/xv6-addinglseek/blob/main/trylseek.c"
click node_userapi "https://github.com/swayam0611/xv6-addinglseek/blob/main/user.h"
click node_syscallabi "https://github.com/swayam0611/xv6-addinglseek/blob/main/syscall.h"
click node_dispatch "https://github.com/swayam0611/xv6-addinglseek/blob/main/syscall.c"
click node_seekimpl "https://github.com/swayam0611/xv6-addinglseek/blob/main/sysfile.c"
click node_seekmodes "https://github.com/swayam0611/xv6-addinglseek/blob/main/fcntl.h"
click node_fileobject "https://github.com/swayam0611/xv6-addinglseek/blob/main/file.h"
click node_inodefs "https://github.com/swayam0611/xv6-addinglseek/blob/main/fs.c"
click node_diskcache "https://github.com/swayam0611/xv6-addinglseek/blob/main/bio.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shell,node_trylseek,node_userapi,node_operator toneBlue
class node_syscallabi,node_dispatch,node_seekimpl,node_seekmodes toneAmber
class node_fileobject,node_inodefs,node_diskcache toneMint
```

## Components

### User programs

- [xv6 shell](https://github.com/swayam0611/xv6-addinglseek/blob/main/sh.c): `sh.c`
- [Seek demo](https://github.com/swayam0611/xv6-addinglseek/blob/main/trylseek.c): `trylseek.c`
- [User API](https://github.com/swayam0611/xv6-addinglseek/blob/main/user.h): `user.h`

### System call path

- [Syscall numbers](https://github.com/swayam0611/xv6-addinglseek/blob/main/syscall.h): `syscall.h`
- [Syscall dispatch](https://github.com/swayam0611/xv6-addinglseek/blob/main/syscall.c): `syscall.c`
- [Seek handler](https://github.com/swayam0611/xv6-addinglseek/blob/main/sysfile.c): `sysfile.c`
- [Seek modes](https://github.com/swayam0611/xv6-addinglseek/blob/main/fcntl.h): `fcntl.h`

### File storage

- [Open file state](https://github.com/swayam0611/xv6-addinglseek/blob/main/file.h): `file.h`
- [Inode filesystem](https://github.com/swayam0611/xv6-addinglseek/blob/main/fs.c): `fs.c`
- [Block cache](https://github.com/swayam0611/xv6-addinglseek/blob/main/bio.c): `bio.c`

### Other components

- **Shell user**

## Connections

- Shell user → xv6 shell: runs commands (evidence: `README`)
- xv6 shell → Seek demo: runs demo (evidence: `README`)
- Seek demo → User API: calls lseek (evidence: `README`)
- User API → Syscall dispatch: enters syscall (evidence: `README`)
- Syscall numbers → Syscall dispatch: registers call (evidence: `README`)
- Syscall dispatch → Seek handler: dispatches lseek (evidence: `README`)
- Seek handler → Seek modes: uses seek modes (evidence: `README`)
- Seek handler → Open file state: checks file type (evidence: `README`)
- Seek handler → Inode filesystem: locks inode (evidence: `README`)
- Seek demo → Inode filesystem: tests seek results
