Monday, April 9, 2012

SA class 4


File system

using 'ls -l' command to get details
Ex.
-rw-r--r-- 1 xatierlike xatierlike 1631 2011-09-14 02:16 class1
    file type
    file access mode             # rwx for read, write, execute
    numbers of inodes
    file user owner
    filegroup owner
    file size
    file last modify time
    file name


file system achitecture
    pathname
    file tree
    mounting
    file type


inode and file
    link
    'ln' command


file access mode
    changing file owner
    freebsd bonus flags  # to protect your important files


file system architecture
                system call
    Application <=========> kernel <=> hardware

    process1, process2, process3....     [user mode]
  -----------------------------------------------------
    virtual file system                  [system mode]
     |
    device drivers ---> devices


purpose of file system
    represent and organize the system's storage
    namespace
    API
    security model
    implementation


system call via APIs
    OS will do the detail jobs


relationship of  API, system call, OS

                   +-- user appication ---
  user        APIs |                     ^
  mode             V                     |
------------------- system call interface ---------------------
  kernel           |                     |
  mode             +---> do some magic  -+





objects in the filesystems
    files and directories
    hardware device files (under /dev/... )
    processes information
    Interprocess communication (IPC)
    shared memory segments (SHM)

    we can uer filesystem interface to access such objects
    Ex. open, read, write, close, seek ... etc.


pathname
    where it is?
    absolute path => start from /
    relative path => start from your current directory

    contrains of pathname
        single componetn <= 255 char
        single absolute path <= 1024 char


file tree
    the data struct of files in your system
    / (root)
    some important directories under root
    /bin & /sbin      user utilities and system programs
    /dev              device
    /etc              system configurations and scripts
    /home             where you live
    /mnt              for system admins to  mount something
    /proc             images and running process
    /usr
        lib           standard libraries for porgrams
        libexec
        obj
        bin, sbin     local executalbe programs
        src           souce files
        include       libraries header files
        local         something loacl
        ports         fucking 'make install clean'

    /var              a lot of things
        db            database
            pkg       database for pkg and ports
            ports
        log           system log
        mail          your mailbox


    learn more:
        http://www.freebsd.org/doc/handbook/dirstructure.html


mointing file system
    'mount' command
    most are disk partitions
    network file servers (NFS)
    memory disk emulators  # man mdconfig
    kernel components


    for a new harddisk
        sysinstall
            configuration
                fdisk lable
                   fd or swap


    mount /dev/ad2sle /home2
    Note: you should mount it on a empty direction


    /etc/fstab
        auto mount at boot time

    'umount' command
     usage:
        unmount {node | devoce}
        Ex. unmount /dev/ad0s1e
        unmount -f                   # force unmount
        lsof / fstat


file types                       # the first character of 'ls -l'
    - regular file
    b block device
    c character device
    d directory
    l symbolic link
    s socket
    p named pipe


'file' command
    determine file type
    /usr/ports/sysutils/file


directory
    .  and ..
        current directory and your father directory
    mkdir / rmdir
        make directory
        remove directory

socket
    created by socket()
    local to a particular host
    be referenced through filesystem object rather than a network port

        process A      process B
           | write      ^
           V            | read
     +----------------------------+
     |      socket buffer         |
     |      [UNIX kernel]         |
     +----------------------------+



named pipe      # FIFO
    'mkfifo' command


link
    symbolic link
    ln -s src dest

inode
    a structure that records info of a file
    'ls -i' to see each file's inode number

    the inode structure
        mode
        owners
        timestamps
        size block
        count
        direct blocks
        single indirect
        double indirect
        triple indirect

filesystem
    boot blocks
    super block
    inode blocks
    date blocks


hardlink and symbolic link
    hardlink
        associate two or more filenames with same inode
        must in the same partition
        ln src dest

    symbolic link
        A file which points to another pathname
        ln -s src dest


file access mode
    rwx for read, write, and exectue   #value 421
    Ex.    rwxr-xr-x, 733
    user, group, other privileges

    'chmod' command
        chmod access-string file
        -R recursivily
    directory must be x then you can cd into it

class          operator        access type
--------------------------------------------
u(user)          +(add)                r
g(group)         -(remove)             w
o(other)         =(set exact)          x
a(all)


setuid, setgid, sticky bit
    the effective uid/gid will be set to the UID/GID of the file
    setuid
        passwd, chsh, crontab
    setgid
        top, fstat, write
    sticky on directory (/tmp)
        do not allow to delete or rename a file unless you are
            the owner of the file
            the owner of the directory
            root

umask
    shell built-in command
    inference the degault permissions given to the files newly created
    777 or 666 xor umask value

change file owner
    'chown' command
    'chgrp' command
    -R recursivily
    Ex.
        chown foo bar
        chown user:grp bar

FreeBSD bonus flags
    'chflags' command
    ls -ol
    'schg' flag to protect important files






No comments:

Post a Comment