--- type: theoretical backlinks: - "[[Memory Management]]" --- A file system consists of two parts - Collection of files - A directory structure -> provides information about all files in the system ## File - Logical view -> the unit of storing data Files are mapped by the OS onto physical nonvolatile devices **Types:** - Data - Numeric - Character - Binary - Program **Attributes**: - Name - Identifier (unique number) - Type[^2] - Location -> pointer - Size - Protection (permissions) - Datetime and user id ### Logical Definition - Named collection of related information - Files may have free form (text files) or can be rigidly formatted[^1] ### Operations - Create - Write - Read - Seek (reposition within file) - Delete - Truncate - shorten or cut off by removing data from the end - Open (load to memory) - Close (unload) ### Open files Tracked by an **open-file table**, counted by **file-open count**. In order to [avoid race conditions](Inter-Process%20Communication.md#Avoiding%20race%20conditions), we need to lock the files somehow. - **Shared lock** -> several processes can acquire concurrently, used for reads - **Exclusive lock** -> writer lock - Mandatory vs. advisory -> access is denied depending on locks held and requested vs. processes can find status of locks and decide what to do ### Structure Could be many: - None - Simple record - Lines - Fixed length - Variable length - Complex - Formatted document - Relocatable load file [^3] ## Directories Collection of nodes containing information about all files. Also resides on disk. **Operations**: - Search for a file - Create a file - Delete a file - List a directory - Rename a file - Traverse file system ### Single level directory A single directory for all users. Clearly, we need unique names, which can become a problem real fast. That shit is gonna grow super big. ### Two-level directory Users have different directories. In Linux -> `/home/user` is separate, allowing for the same file names. Linux, however, uses a multi-level: ### Tree-Structured Directories - Efficient searching - Grouping - Absolute v. relative path ### Acyclic-Graph Have shared subdirectories and files. Symlinks achieve this. ## Symlinks **Hard** vs **Soft**. Hard is a literal copy of the file but keep the same inode info, while soft is just a pointer. >[!IMPORTANT] >We only allow links to files to avoid cycles Every time a new link is added we also use a cycle detection algorithm to determine whether it is OK ## Disk Can be subdivided into **partitions**. Disk/partition can be used **raw** (no file system) or can be **formatted**. The entity containing the file system is known as a volume. > [!NOTE]- Typical fs organization > ![](Pasted%20image%2020250505144352.png) ## Access lists and groups Read, write and execute. Three classes of users on Linux 1. Owner -> 7 (Read Write Execute) 2. Group -> 6 (RW) 3. Public -> 1 (X) --- [^1]: **Columnar**, fixed-format ASCII Files have fixed field lengths, as opposed to **delimited**, i.e. fields can be as large as we want them to [^2]: Extension (.pdf, .txt) as opposed to format, which specifies the [grammar](Regular%20languages.md) of the file [^3]: contains information about where to place different parts of the program in memory.