Lesson 7 (File System Structure)

Cards (39)

  • Fille Attributes
    • Name – only information kept in human-readable form
    • Identifier – unique tag (number) identifies file within file system
    • Type – needed for systems that support different types
    • Locationpointer to file location on device
    • Size – current file size
    • Protection – controls who can do reading, writing, executing
    • Time, date, and user identification – data for protection, security, and usage monitoring
    • Information about files are kept in the directory structure, which is maintained on the disk
    • Many variations, including extended file attributes (e.g. checksum)
  • File Operations
    • Create
    • Write – at write pointer location
    • Read – at read pointer location
    • Reposition within file – seek (move the file pointer)
    • Delete – release all file space used by the file and erase the directory entry
    • Truncate – maintain the file attribute but erase the contents in the file
    • Open(F) – search the directory structure on disk for entry F, and move the content of entry to memory
    • Close (F) – move the content of entry F in memory to directory structure on disk
  • who "Opens" a file and when does it occur?
    Before reading/writing a file, kernel must "open" the file.
  • What does "open" file operation do?
    • locate the file on the disk according to its file name (path);
    • establish data structures to share file among different processes
    • allocate file descriptor(ID-used by read/write requests)
  • What are the data needed to manage open files?
    • Open-file table: tracks open files
    • File pointer: pointer to last read/write location, per process that has the file open
    • File-open count: counter of number of times a file is open – to allow removal of data from open-file table when last processes closes it
    • Disk location of the file: cache of data access information
    • Access rights: per-process access mode information
  • What are the 3 data structures in a UNIX system?
    • Per Process Table of Open Files
    • System-wide File Table
    • System-wide V-Node Table (Linux –no V-node, only I-node)
  • What is inside a Per Process Table of Open Files?
    • Each entry for an opened file
    • File descriptor Flag (fd flag): indicates whether the file should be closed upon executing one of the “exec” functions
    • Ptr: point to entry in the System Wide File Table(describes how to access the file)
  • What happens in Per Process Table when a new process is created?
    3 std file is opened
    1. Standard input(stdin, fd=0) eg. keyboard
    2. Standard output(stdout, fd=1) eg. display
    3. Standard error(stderr, fd=2)
  • What is a System Wide Open File TableTable for all opened files for all processes
  • What is a System Wide Open File Table?
    A table for all opened files for all processes
  • What is inside a System Wide Open File Table
    • File Status Flags (file open for):
    • read only (O_RDONLY)
    • write only (O_WRONLY)
    • both read and write (O_RDWR) + (Optional)
    • append on each write (O_APPEND)
    • File offset(position of next read/write)
    • V-node ptr (entry in V-node table) or I-node ptr (entry in I-node table)
  • V-node Table
    Each opened file = only 1 entry in the table
    • V-node info: • Type of file (regular, pipe, directory, etc) • Ptr to function operates such type of file
    • I-node info: • Only for regular & directory file • Owner, access permission, size, access time • Ptr to the actual data blocks on disk for the file
  • Types of Sharing of Files
    1. Type 1: File A is shared via 2 separate file table entries
    2. Type 2: File B is shared via the same file table entry
  • Type 1 Sharing between 2 process
    • File is shared via 2 separate file table entires
    • Each process can have a different file status and offset for the same file (e.g read and write)
  • Type 2 Sharing between 2 processes
    • File is shared via the same file table entry
    • Created via dup or fork where >1 fd point to the the same file table entry
    • Share the same file status (read, write, RW) and offset
  • What does each file's i-node contain?
    • file type
    • access permissions
    • Owner and group owner
    • Size of the file
    • number of links
    • device number of the device where the file is stored
    • time of last access
    • time of last modification
    • time of last change to the i-node
    • block numbers of the blocks in which file is stored
  • how to see file i-node number?
    ls -i <file>
    stat <file>
  • How are file identified in a Unix Kernel?
    By its i-node
  • What does a UNIIX directory file contain and what does it do?
    Unix directory file contains: names of the files, their i-node numbers and contents of the directory file
    Provides a mapping between file name & its i-node number:
    contents of the directory file (“assign1”) would be something like
  • What is (Open) File Locking
    A mechanism that allows one to lock a file and prevent other processes from gaining access to it (provide by some OS and file system)
  • Types of File Locking
    1. Shared Lock: similar to reader lock, Where several processes/user can can access a file simultaneously for reading purposes only.
    2. Exclusive Lock: similar to writer lock, Only one process/user can access a file simultaneously for reading purposes only.
    3. Mandatory Locks: Access is denied by OS depending on locks held and requested.
    4. Advisory – Processes can find status of locks and decide what to do (OS will not enforce but decide by the programmer, programmer can ignore)
  • File Type (Name and Extension)
    FYI
  • Type of File Structure
    • None (no structure) - a sequence of words/bytes
    • Structure:
    • Simple Record Structure (Lines, Fixed Length, Variable Length)
    • Complex Structure (Formatted Doc, Relocatable Load File - e.g executable file)
    • Why do we need structured?
    • The OS needs to determine where in the RAM to load the executable file and where is the location of first instruction
  • Types of File Access Methods
    • Sequential
    • Direct
    • Indexed
  • (Type of Access Method) - Sequential
    • Information in the file is processed in order, one record after the other
    • Related variables: read_next, write_next, reset
  • Type of Access Methods (Others)
    • Can be built on top of base methods
    • Example: creation of an index for the file which contains pointer to the actual disk block • Keep index in memory for fast determination of location of data to be operated on • If index file is too large, create index (in memory) of the index (on disk)
    Example: IBM indexed sequential-access method (ISAM), VMS OS
  • DIrectory Structure
    What is a Directory? A collection of nodes containing information about all files
    Where do they both reside? On the disk
  • Operations Performed on Directory
    • Search for a file (within the directory)
    • Create a file – nano, vi
    • Delete a file - rm
    • List a directory - ls
    • Rename a file - mv
    • Traverse the file system - cd
  • How is a Direrectory Organised?
    • Efficiency – locating a file quickly
    • Naming – convenient to users
    • Two users can have same name for different files
    • user1 in his own directory create a file “xyz.txt”
    • user 2 in his own directory create another file also named it as “xyz.txt”
    • The same file can have several different names
    • Grouping – logical grouping of files by properties, (e.g., all Java programs, all games, …)
  • Types of Directories
    1. Single - Level
    2. Two - Level
    3. Tree - Structured
    4. Acyclic - Graph
    5. General Graph
  • (Types of Directory) Single-Level Directory
    • A single directory for all users
    • ALL files are kept in the same directory
    Benefits:
    • simplest directory structure
    • actions like file creation, searching, file deletion, and updating are quite simple
    Problems:
    • Naming - need to have unique name for all files
    • Grouping - can’t differentiate between groups
  • (Types of Directory) - Two-Level Directory
    • Separate directory for each user
    Features:
    • Path name (i.e user name + file name)
    • Can have same file name for different user
    • Efficient searching
    Disadvantage:
    • No grouping capability: can't create group (sub-folder) under the same user
    • Cannot share: user cannot share a file with another user without permission.
    • Not scalable: files of the same type cannot be kept in the same group
  • (Types of Directory) - Tree-Structured Directories (multi-level)
    Features/Benefits:
    • Efficient Searching: Uses absolute or relative path name
    • Grouping Capabilities: users can define own subdirectory for files of similar type
    • delete/create file/directory is done in current one. deleted a directory deletes the entire subtree rooted by specified directory
    Disadvantage:
    • Inefficient: Files may be saved in numerous directories if they do not fit into the hierarchical structure.
    • Cannot share files between users.
  • (Types of Directory) - Acyclic-Graph Directory
    Features:
    • 2 or more directory entries can lead to the same subdirectory / file and prevents any entries from pointing back to directory structure.
    • Structure allows for file sharing
    • Uses links:
    • symbolic / soft link (specify a file path: logical)
    • hard link (actual link to the same file on the disc from multiple directories: physical).
    • Advantages: Due to different-different paths, searching is simple
    • Disadvantages (when removing):
    • Softlink: a dangling pointer remains.
    • Hardlink: must erase all the references associated with it. 
  • (Type of Directory) General Graph DIrectory
    Features:
    • Cycles are allowed inside directory structure where numerous directories can be derived from more than one parent directory.
    • Commands like, "search" must be used with caution. If cycles are allowed, the search is infinite.
    Advantages: More adaptable than the others
    Disadvantages:
    • It is more expensive than other options.
    • Garbage collection is required. 
    • Hard to figure out how much space the files and folders have used up
  • (Type of Directory) - General Graph Cycle (2)

    How do we guarantee no cycles?
    • Allow only links to file not subdirectories
    • Garbage collection (traversing the entire file system to locate no accessible entry)
    • Every time a new link is added use a cycle detection algorithm to determine whether it is OK
  • File System Mounting
    • A file system (eg. USB) must be mounted before it can be accessed.
    • A unmounted file system is mounted at a mount point.
  • File Protection (Creation and Access Types)
    File owner/creator should be able to control: what can be done and by whom
    Types of access:
    • Read
    • Write
    • Execute
    • Append
    • Delete
    • List
  • File Protection (Access Lists and Groups)
    Mode of access: read, write, execute
    Three classes of users on Unix / Linux: