Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem.

Similar presentations


Presentation on theme: "CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem."— Presentation transcript:

1 CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem

2 CSC 660: Advanced Operating SystemsSlide #2 Topics 1.Filesystems 2.Filenames and Pathnames 3.File Attributes 4.File Operations 5.Virtual Filesystem 6.VFS Objects 7.Processes and Files

3 CSC 660: Advanced Operating SystemsSlide #3 Why filesystems? Physical DiskFilesystem Access byBlocksBytes AddressingBlock #Pathname SecurityNoneACLs ReliabilityCorruption on crashRobust response to system failures.

4 CSC 660: Advanced Operating SystemsSlide #4 Tree Structure / binboottmpusrvar lsgrub binlibX11R6 vmlinuz menu.lst less zip binlib xclockxterm

5 CSC 660: Advanced Operating SystemsSlide #5 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/X11R6/bin/xclock

6 CSC 660: Advanced Operating SystemsSlide #6 File Attributes Filename and Data Location File Type –Regular files –Directories –Device (block + char) files –IPC files Ownership Access Control List Locking Size Timestamps

7 CSC 660: Advanced Operating SystemsSlide #7 File Operations Create Delete Open Close Read Write Append Seek Get Attributes Set Attributes Rename

8 CSC 660: Advanced Operating SystemsSlide #8 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

9 CSC 660: Advanced Operating SystemsSlide #9 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

10 CSC 660: Advanced Operating SystemsSlide #10 Open File Table struct files_struct { atomic_t count; spinlock_t file_lock; int max_fds; 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]; };

11 CSC 660: Advanced Operating SystemsSlide #11 Opening and Closing #include 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 */

12 CSC 660: Advanced Operating SystemsSlide #12 Reading and Writing #include 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 */

13 CSC 660: Advanced Operating SystemsSlide #13 Virtual Filesystem

14 CSC 660: Advanced Operating SystemsSlide #14 Classes of Filesystems Disk-based filesystems –Linux (ext2, ext3, reiserfs) –UNIX (ufs, minix, JFS, XFS) –MS (FAT, VFAT, NTFS) and other proprietary –ISO9660 CD-ROM, UDF DVD Network filesystems –NFS, AFS, CIFS Special filesystems –Procfs, sysfs

15 CSC 660: Advanced Operating SystemsSlide #15 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.

16 CSC 660: Advanced Operating SystemsSlide #16 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.

17 CSC 660: Advanced Operating SystemsSlide #17 VFS Objects

18 CSC 660: Advanced Operating SystemsSlide #18 struct super_block TypeFieldDescription struct list_heads_listSuperblock linked list dev_ts_devDevice identifier u_longs_blocksizeBlock size in bytes u_chars_dirtDirty (modified) flag struct super_operations * s_opSuperblock methods struct semaphores_lockSuperblock semaphore struct list_heads_inodesList of all inodes struct list_heads_ioInodes waiting for write struct list_heads_filesList of file objects

19 CSC 660: Advanced Operating SystemsSlide #19 struct inode TypeFieldDescription struct list_headi_listInode linked list struct list_headi_dentryList of dentries to this inode inode_operations*i_opInode methods u_longi_inoInode number atomic_ti_countReference count umode_ti_modeACL for file u_longi_nlinkNumber of hard links uid_t,gid_ti_{uid,gid}UID and GID of owner loff_ti_sizeFile size in bytes struct timespeci_[amc]timeLast access, modify, change

20 CSC 660: Advanced Operating SystemsSlide #20 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)

21 CSC 660: Advanced Operating SystemsSlide #21 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

22 CSC 660: Advanced Operating SystemsSlide #22 struct dentry TypeFieldDescription atomic_td_countUsage count spinlock_td_lockLock for this dentry struct inode*d_inodeCorresponding inode struct dentry_operations *d_opDentry methods struct list_headd_lruList of unused dentries. struct list_headd_childDir dentries of same parent. struct list_headd_subdirsSubdirectory dentries. struct list_headd_aliasDentries w/ same inode.

23 CSC 660: Advanced Operating SystemsSlide #23 File Objects In-memory representation of open files. Created in response to open() call. Destroyed in response to close() call. Multiple file objects can exist for same file. Different processes can open same file. File object records process-specific status info (seek point, access mode.)

24 CSC 660: Advanced Operating SystemsSlide #24 struct file TypeFieldDescription struct list_headf_listLinked list of file objects struct dentry*f_dentryAssociated dentry object atomic_tf_countUsage count u_intf_flagsFlags specified on open() struct file_operations * f_opFile methods (open, read, write, readdir, ioctl) mode_tf_modeFile access mode loff_tf_posFile offset u_intf_{uid,gid}User’s UID and GID intf_errorError code

25 CSC 660: Advanced Operating SystemsSlide #25 References 1.Daniel P. Bovet and Marco Cesati, Understanding the Linux Kernel, 3 rd edition, O’Reilly, 2005. 2.Robert Love, Linux Kernel Development, 2 nd edition, Prentice-Hall, 2005. 3.Claudia Rodriguez et al, The Linux Kernel Primer, Prentice-Hall, 2005. 4.Peter Salzman et. al., Linux Kernel Module Programming Guide, version 2.6.1, 2005. 5.Avi Silberchatz et. al., Operating System Concepts, 7 th edition, 2004. 6.Andrew S. Tanenbaum, Modern Operating Systems, 3 rd edition, Prentice-Hall, 2005.


Download ppt "CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem."

Similar presentations


Ads by Google