<<

Systems Inodes

• Abstraction • Which disk blocks go with which file. – Directories and Files instead of disks • Inode: Data structure for bookkeeping • Protection – List of Blocks – File or • Project: Simple -like – Link Count – Other information…owner/permissions

Inode Structure • Direct and Indirect Blocks Inodes

• Advantages: – Fast access for small files (majority) – Supports large files – Supports sparse files Directories Super Block

• Like a file: List of files and directories • Contains the layout of the Disk – name – Size of Disk – inode number – Number of Inodes • Can read it like a file – Number of Data Blocks • Always has least 2 entries: – Where inodes start, where data blocks start, etc…. – “.” current directory – “..” parent directory

Disk Layout Super blocks (cont.) • typedef struct { • char signature[SIGN_SIZE]; /* Signature */ Boot Block (Our OS == entire image) • int size; /* Size of file system in blocks */ Super Block • int root_inode; /* Inode no. of root directory */ Inode Blocks • int inode_start; /* First block for inodes */ Allocation Bitmap • int inode_blocks; /* Number of inode blocks */ Allocation data Blocks • int bitmap_start; /* First block for bitmap */ • int bitmap_blocks; /* Number of blocks used to store the bitmap */ • int alloc_start; /* First block managed by the allocater */ • int num_blocks; /* Number of blocks for allocation */ • int free_blocks; /* Number of free blocks: Note: IGNORE this since we do not want to update superblock frequently. */ • } superblock; Project Formatting()

• System calls to access file system • a file system: – mkfs: Formatting – superblock – link, unlink: – Mark inodes and data blocks to be free – open: file creation – Create root directory – close, read, write, lseek: file access – initialize user table – , chdir, : directory stuff – : information about a file or directory • fsck: Check integrity of file system – provided

File Creation / Deletion File Access

• link: to a file • open: create file if it does not exist – create a link to an existing file • read: – hard vs soft link • write: • unlink: Delete a file if link count == 0 • lseek: position in file – delete directory entry • close: free file descriptor Example: mkdir() Directories

int fs_mkdir(char *file_name) { • Mkdir: make a directory if (file_name exists) return ERROR; – create an entry in parent directory /* allocate data block */ – create two directories: “.”, “..” /* allocate inode */ /* set directory entries for ‘.’, ‘..’ */ • rmdir: remove directory if empty /* set inode entries appropriately * • chdir: change the current directory /* update parent */ return SUCCESS – For relative path names }

Doing the Assignment

• Most under environment – Use a file to simulate a disk (make lnxsh) – code is provided (*Fake files) • Should be able to move right over to our OS. • Shell supports – System calls for File System – Commands like “”, “”, “create” (create foo 200)