summaryrefslogtreecommitdiffhomepage
path: root/docs/tex/nefs.tex
blob: 37e43d13497f4d85dcda20e51d89252d1a9d5a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
\documentclass{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{titlesec}
\usepackage{fancyhdr}
\usepackage{caption}
\usepackage{graphicx}

\definecolor{codegray}{gray}{0.95}
\lstset{
  backgroundcolor=\color{codegray},
  basicstyle=\ttfamily\small,
  breaklines=true,
  frame=single,
  tabsize=4,
  language=C++,
  showstringspaces=false
}

\title{NeFS: New Extended File System Specification}
\author{Amlal El Mahrouss}
\date{2025}

\begin{document}

\maketitle

\section{Overview}
NeFS (New Extended File System) is am embedded file system designed to operate over low-level block storage (AHCI/ATA) with a modular architecture. It supports catalogs (like files or directories), forks (similar to macOS data/resource forks), and a formatting mechanism using EPM (Extended Partition Map).

\section{Key Components}

\subsection*{Mountpoint and Drive Access}
\begin{itemize}
  \item `kMountpoint`: Global mountpoint interface to access drives.
  \item `DriveTrait`: Interface used to abstract block-level access.
\end{itemize}

\subsection*{Core Structures}
\begin{longtable}{|l|p{11cm}|}
\hline
\textbf{Structure} & \textbf{Purpose} \\
\hline
NEFS\_FORK\_STRUCT & Represents a data fork (stream of bytes attached to a catalog). \\
\hline
NEFS\_CATALOG\_STRUCT & Represents metadata of a file or directory, including fork pointers. \\
\hline
NEFS\_ROOT\_PARTITION\_BLOCK & Metadata describing a NeFS partition. \\
\hline
EPM\_PART\_BLOCK & EPM descriptor for bootable partition support. \\
\hline
\end{longtable}

\subsection*{Key Functions}

\begin{itemize}
  \item \texttt{CreateCatalog()} — Creates a file or directory catalog.
  \item \texttt{CreateFork()} — Adds a fork to a catalog, with LBA linking.
  \item \texttt{FindCatalog()} — Finds a catalog by traversing sibling links.
  \item \texttt{FindFork()} — Locates a fork by name under a catalog.
  \item \texttt{WriteCatalog()} — Writes a fork's data to the correct offset.
  \item \texttt{Format()} — Initializes a NeFS + EPM partition on a drive.
  \item \texttt{ReadCatalog()} — Reads back a fork's data.
  \item \texttt{RemoveCatalog()} — Marks a catalog as deleted and updates partition metadata.
\end{itemize}

\section{Design Overview}

\subsection*{Fork Management}
Forks are chained using `NextSibling` pointers and are scanned linearly to find unallocated entries. Forks contain:
\begin{itemize}
  \item Fork name
  \item Catalog name
  \item Flags (e.g., created/deleted)
  \item Data size and offset
  \item Sibling pointers (Next, Previous)
\end{itemize}

\subsection*{Catalog Management}
Catalogs act like files or directories. Each has:
\begin{itemize}
  \item Name and type (file/dir)
  \item Data and resource forks
  \item Status flags
  \item Chaining via sibling pointers
\end{itemize}
Catalog creation attempts to find a parent first, then finds a free block to allocate the new catalog structure.

\subsection*{Partition Formatting}
The `Format()` function sets up the NeFS partition and optionally writes an EPM descriptor if bootable. It:
\begin{enumerate}
  \item Verifies the drive
  \item Initializes partition metadata (sector size, catalog start, etc.)
  \item Writes the root directory
\end{enumerate}

\section{Error Handling}
Errors are written to a global error register using `err\_global\_get()`. Common codes include:
\begin{itemize}
  \item \texttt{kErrorDiskIsCorrupted}
  \item \texttt{kErrorFileExists}
  \item \texttt{kErrorFileNotFound}
  \item \texttt{kErrorUnimplemented}
\end{itemize}

\section{Limitations and Notes}
\begin{itemize}
  \item No read/write locking or access concurrency.
  \item Assumes in-memory buffers for fork writing.
  \item Seek/Tell operations are not implemented — only bulk read/write.
  \item Supports one mountpoint at a time.
\end{itemize}

\section{Future Work}
\begin{itemize}
  \item Implement streaming I/O with Seek/Tell.
  \item Support multiple mountpoints or drives.
  \item Improve metadata journaling and recovery features.
\end{itemize}

\end{document}