CSC 660 Advanced OS Virtual Filesystem CSC 660
- Slides: 24
CSC 660: Advanced OS Virtual Filesystem CSC 660: Advanced Operating Systems 1
Topics 1. 2. 3. 4. 5. 6. 7. Filesystems Filenames and Pathnames File Attributes File Operations Virtual Filesystem VFS Objects Processes and Files CSC 660: Advanced Operating Systems 2
Why filesystems? Access by Physical Disk Filesystem Blocks Bytes Addressing Block # Pathname Security ACLs None Reliability Corruption on crash Robust response to system failures. CSC 660: Advanced Operating Systems 3
Tree Structure / bin boot ls tmp usr bin grub lib var X 11 R 6 less vmlinuz menu. lst bin zip xclock CSC 660: Advanced Operating Systems lib xterm 4
Filenames and Pathnames • Filenames – Human-readable identifier for data. – File suffixes have special meanings in Windows. • Directories – Store lists of filename/location mappings. • Pathnames – Identify file in directory hierarchy. – Ex: /usr/X 11 R 6/bin/xclock CSC 660: Advanced Operating Systems 5
File Attributes • Filename and Data • Location • File Type – – • • • Regular files Directories Device (block + char) files IPC files Ownership Access Control List Locking Size Timestamps CSC 660: Advanced Operating Systems 6
File Operations • • • Create Delete Open Close Read Write • • • CSC 660: Advanced Operating Systems Append Seek Get Attributes Set Attributes Rename 7
File Descriptors User process reference to a file. A non-negative integer unique to process. Returned by open or creat system calls. Used as argument to other file system calls. View with: ls –l /proc/self/fd Common file descriptors: 0 STDIN 1 STDOUT 2 STDERR CSC 660: Advanced Operating Systems 8
Process File Context • Root directory – Usually /, but can change for security. • Current working directory – Default location for file commands. – Relative pathnames are relative to CWD. • Open file table – Maps file descriptors to kernel file objects. – files_struct member of task_struct CSC 660: Advanced Operating Systems 9
Open File Table struct files_struct { atomic_t count; spinlock_t file_lock; int max_fdset; int next_fd; struct file ** fd; fd_set *close_on_exec; fd_set *open_fds; fd_set close_on_exec_init; fd_set open_fds_init; struct file * fd_array[NR_OPEN_DEFAULT]; }; CSC 660: Advanced Operating Systems 10
Opening and Closing #include <fcntl. h> #include <unistd. h> int open(char *path, int oflag); /* Common flags: O_RDONLY, O_WRONLY, O_CREAT Returns FD on success, -1 on failure */ int close(int filedes); /* Returns 0 on success, -1 on failure */ CSC 660: Advanced Operating Systems 11
Reading and Writing #include <unistd. h> ssize_t read(int fd, void *buf, size_t nbytes); /* Returns # bytes read, 0 if EOF, -1 error */ ssize_t write(int fd, void *buf, size_t nbytes); /* Returns # bytes written, -1 on error */ off_t lseek(int fd, off_t offset, int whence) /* Whence: SEEK_SET (f/ 0) or SEEK_CUR (f/ current) Returns new file offset, -1 on error */ CSC 660: Advanced Operating Systems 12
Virtual Filesystem CSC 660: Advanced Operating Systems 13
Classes of Filesystems • Disk-based filesystems – Linux (ext 2, ext 3, reiserfs) – UNIX (ufs, minix, JFS, XFS) – MS (FAT, VFAT, NTFS) and other proprietary – ISO 9660 CD-ROM, UDF DVD • Network filesystems – NFS, AFS, CIFS • Special filesystems – Procfs, sysfs CSC 660: Advanced Operating Systems 14
VFS Objects • superblock – Represents a mounted filesystem. • inode – Represents a specific file. • dentry – Represents a directory entry, a single path comp. • file – Represents an open file associated w/ a process. CSC 660: Advanced Operating Systems 15
VFS Objects • Directories are files – Directories are handled by file objects. – dentry objects are path components, not dirs. • Each object contains an operations object – Define methods kernel invokes on object. – Defined as struct of function pointers. • What if a fs doesn’t have a type of object? – Objects of that type made on the fly for VFS. CSC 660: Advanced Operating Systems 16
VFS Objects CSC 660: Advanced Operating Systems 17
struct super_block Type struct list_head dev_t u_long Field s_list s_dev s_blocksize Description Superblock linked list Device identifier Block size in bytes u_char struct super_operations * struct semaphore struct list_head s_dirt s_op Dirty (modified) flag Superblock methods s_lock s_inodes s_io s_files Superblock semaphore List of all inodes Inodes waiting for write List of file objects CSC 660: Advanced Operating Systems 18
struct inode Type struct list_head inode_operations Field i_list i_dentry *i_op Description Inode linked list List of dentries to this inode Inode methods u_long atomic_t umode_t u_long uid_t, gid_t loff_t struct timespec i_ino i_count i_mode i_nlink i_{uid, gid} i_size i_[amc]time Inode number Reference count ACL for file Number of hard links UID and GID of owner File size in bytes Last access, modify, change CSC 660: Advanced Operating Systems 19
Inode Operations int create(struct inode *dir, struct dentry *dentry, int mode) struct dentry *lookup(struct inode *dir, struct dentry *dentry) int link(struct dentry *old, struct inode *dir, struct dentry *dentry) int unlink(struct inode *dir, struct dentry *dentry) int symlink(struct inode *dir, struct dentry *dentry, const char *symname) int mkdir(struct inode *dir, struct dentry *dentry, int mode) int rmdir(struct inode *dir, struct dentry *dentry) int rename(struct inode *old_dir, struct dentry *old, struct inode *new_dir, struct dentry *new) int readlink(struct dentry *dentry, char *buffer, int buflen) CSC 660: Advanced Operating Systems 20
Dentry Objects • Path components – Ex: /bin/vi has 3 dentries: /, etc, and vi • Not an on-disk data structure – Constructed on fly from pathname string. – Cached by the kernel to avoid re-construction. • States – Used: corresponds to valid inode in use. – Unused: valid inode not currently used (cached). – Negative: invalid path, no corresponding inode CSC 660: Advanced Operating Systems 21
struct dentry Type atomic_t spinlock_t struct inode Field d_count d_lock *d_inode Description Usage count Lock for this dentry Corresponding inode struct dentry_operations struct list_head *d_op Dentry methods d_lru d_child d_subdirs d_alias List of unused dentries. Dir dentries of same parent. Subdirectory dentries. Dentries w/ same inode. CSC 660: Advanced Operating Systems 22
struct file Type struct list_head struct dentry atomic_t Field f_list *f_dentry f_count Description Linked list of file objects Associated dentry object Usage count u_int struct file_operations * mode_t loff_t u_int f_flags f_op Flags specified on open() File methods (open, read, write, readdir, ioctl) f_mode f_pos f_{uid, gid} f_error File access mode File offset User’s UID and GID Error code CSC 660: Advanced Operating Systems 23
References 1. 2. 3. 4. 5. 6. Daniel P. Bovet and Marco Cesati, Understanding the Linux Kernel, 3 rd edition, O’Reilly, 2005. Robert Love, Linux Kernel Development, 2 nd edition, Prentice-Hall, 2005. Claudia Rodriguez et al, The Linux Kernel Primer, Prentice-Hall, 2005. Peter Salzman et. al. , Linux Kernel Module Programming Guide, version 2. 6. 1, 2005. Avi Silberchatz et. al. , Operating System Concepts, 7 th edition, 2004. Andrew S. Tanenbaum, Modern Operating Systems, 3 rd edition, Prentice-Hall, 2005. CSC 660: Advanced Operating Systems 24
- Pathname lookup in linux's virtual filesystem
- Csc 660
- Csc 660
- Csc 660
- Csc 660
- Csc 660
- Csc 660
- Posix filesystem
- Ubi filesystem
- Art 660 cc
- 90300 in standard form
- Healthscope benefits customer service
- Geoliner 660
- O'rta asrlarda jismoniy tarbiya
- Has virtual functions and accessible non-virtual destructor
- Trigonometric
- Csc form no. 33-a revised 2018
- Simplify trig identities worksheet
- Language html
- 4-5 graphing other trigonometric functions answers
- Csc 405
- Csc picture size in inches
- Csc 375
- Csc 135
- Csc 340