File System

File System

Files

  • ll or ls -l

File System Architecture

  • Application <->Kernel <-> Hardware

    • Applications call system-calls to request service
    • Kernel invokes corresponding drivers
  • Purpose of filesystem

    • Represent and organize the system’s storage
    • Four main components:
      • Namespace
        • Naming things and arranging in a hierarchy
      • API
        • System calls for navigating and manipulating nodes
      • Security model
      • Implementation
  • API – System Call – OS Relationship

  • Objects in the filesystem:

    • Files and directories
    • Hardware device files
    • Processes information
  • Pathname

    • Absolute path(start with /)
    • Relative path(start from the current directory)
  • Layout of File Systems

    • hier(7)

  • Mounting file system

    • mount(8)
    • “mount” command
      • Map the mount point of the existing file tree to the root of the newly attached filesystem
      • The previous contents of the mount point become inaccessible
      • mount以後,像是任意門通到另一個世界,原本門後的空間就會看不到,unmount後才可看到原來門後的空間
    • Filesystem table – fstab
      • Automatically mounted at boot time
      • /etc/fstab
        • Filesystem in this file will be checked and mounted automatically when booting
    • umount(8)
    • “umount” command
      • Busy filesystem
        • Someone’s current directory is there or there are opened files
        • Use “umount -f”
        • We can use lsof or fstat like utilities to figure out who makes it busy
  • File Types

    • Directory
      • . and ..
      • mkdir / rmdir
    • UNIX domain socket
      • Created by socket()
      • Be referenced through a filesystem object rather than a network port
    • Symbolic Link
      • A file which points to another pathname
      • ln -s ori-file soft-file`
      • Like “short-cut” in Windows

Inode and File

  • inode
    • A structure that records information of a file
    • ls -i to see each file’s inode number
  • Hard link
    • Associate two or more filenames with the same inode
      • Must in the same partition
    • ln ori-file hard-file
  • Soft (symbolic) link
    • A file which points to another pathname
    • ln -s ori-file soft-file

File Access Mode

  • rwx r-x r-x
    • User, group, other privileges
  • chmod command
    • change access authorities
    • chmod(1)
  • setuid, setgid, sticky bit
    • setuid, setgid on file
      • The effective uid/gid of resulting process will be set to the UID/GID of the file
    • setgid on directory
      • Cause newly created files within the directory to be the same group as directory
    • sticky on directory
      • Do not allow to delete or rename a file unless you are
        – The owner of the file
        – The owner of the directory
        – root
  • Changing File Owner
    • Commands:
      • chown – change user owner
      • chgrp – change group owner