14
FILES AND FILESYSTEMS UNIX Programming 2014 Fall by Euiseong Seo

FILES AND FILESYSTEMS

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: FILES AND FILESYSTEMS

FILES AND FILESYSTEMS UNIX Programming 2014 Fall by Euiseong Seo

Page 2: FILES AND FILESYSTEMS

Filesystem of UNIX

¨  Basic purpose of filesystem is to represent and organize system storage resources

¨  But, UNIX filesystem provides more! ¤ Think about /proc directory

¨  Even memory and devices are represented as files in UNIX filesystem

Page 3: FILES AND FILESYSTEMS

Pathnames

¨  Absolute path names ¤ Begins with preceding “/”

¨  Relative path names ¤ Begins without “/” ¤  Interpreted starting at CWD

¨  Each directory name must be shorter than 255 bytes ¨  Total path length must be shorter than 4095 bytes ¨  - or / characters are not allowed in file or directory

names

Page 4: FILES AND FILESYSTEMS

Storage and Filesystem

Ext4 NTFS FAT32 NilFS

Various storage device

Unified block device interface

Diverse filesystems

Page 5: FILES AND FILESYSTEMS

Storage, Filesystem and VFS

Ext4 NTFS FAT32 NilFS

Unified block device interface

Unified virtual filesystem interface

/proc /sys

Pseudo filesystem interface

Page 6: FILES AND FILESYSTEMS

NTFS on HDD

Storage, Filesystem and VFS

root

bin tmp etc user

ls ps passwd User A User B

Ext4 on SSD Ext4 on HDD

Ext4 on HDD

Page 7: FILES AND FILESYSTEMS

Mount and Unmount

root

bin tmp etc user

ls ps passwd

Ext4 on SSD Ext4 on HDD

Ext4 on HDD

Page 8: FILES AND FILESYSTEMS

NTFS on HDD

Mount and Unmount

root

bin tmp etc user

ls ps passwd User A User B

Ext4 on SSD Ext4 on HDD

Ext4 on HDD

Mount! mount point

Page 9: FILES AND FILESYSTEMS

Mount

¨  A partition is a basic unit of mount ¨  A mount point is a normal directory ¨  Mount maps a mount point to the root of the newly

attached filesystem ¨  Previous contents of the mount point become

inaccessible as long as another filesystem is mounted there

¨  mount -t ext4 /dev/sda3 /mnt

Page 10: FILES AND FILESYSTEMS

Unmount

¨  Unmount detaches a mounted filesystem from its mount point

¨  Contents in mount point become accessible again after unmount

¨  unmount /mnt ¨  Unmount is allowable only when no processes have

open files in mounted filesystem ¤ fuser command shows the user of a filesystem ¤ unmount -l conducts lazy release

Page 11: FILES AND FILESYSTEMS

Device Files

¨  Everything is a file in UNIX ¤ Process ¤ Memory ¤ Device

¨  Device file ¤ Let programs communicate with the system’s hardware ¤ Abstract messy details of device interfaces

Page 12: FILES AND FILESYSTEMS

Device Files

Device

Device Driver

Virtual File System

User Applications

User Level

Kernel Level

Hardware Level

Page 13: FILES AND FILESYSTEMS

Permission Revisited

¨  chmod command for permission adjustment ¤ chmod MODE FILE

n Mode consists of “entity(+|-)permission” n Regex of MODE is (u|g|o|a)(\+|-)[wrx]+

¤ chmod OCTAL-MODE FILE n Mode can be represented by a 3-digit octal number n First digit for user, second for group, and third for others n First bit for r, second for w, and third for x permission n  chmod 755 myscript.sh

Page 14: FILES AND FILESYSTEMS

Sticky Bit

¨  Permission for file creation and removal in a directory is determined by the “W” permission of the directory

¨  If you want to allow users to create files in a directory freely, and to remove only their files, what is the solution? ¤ Sticky bit! ¤ chmod a+t directory