180 likes | 304 Vues
This document provides a detailed overview of disks, partitions, and filesystems, focusing on the Standard S5 system along with relevant features and functionalities. It covers the structure of filesystems, including boot blocks, super blocks, i-nodes, and directory entries. Key file operations such as linking, unlinking, removing, renaming, and managing symbolic links are explained. The nuances of managing file times, creating and removing directories, and reading directories using various system calls are also included to enhance understanding of filesystem operations.
E N D
Disks, Partitions, and Filesystems Multiple systems in use S5, UFS, others Focus on standard S5 system HD’s divide into partitions, each of which can contain a file system
Filesystems • Filesystems contain boot block(s), a super block, an i-list, directory blocks and data blocks • i-nodes contain most file info • directory blocks contain directory info • data blocks contain contents of file
Directories • tables of filenames and associated i-nodes • directories always contain . and .. as table entries • directories are files, with i-nodes, .etc
i-node • contains all info about file • type, access, size, etc. • pointers to data associated with file • count of links to i-node (hard links) • directory entries pointing to i-node • can be pointed to by multiple directory entries • directory entries must point to i-nodes in same file system
link, unlink, remove, rename Functions • link creates directory entry for existing file • takes pathname, returns 0 OK, -1 error • unlink removes existing directory entry • takes pathname, returns 0 OK, -1 error • remove identical to unlink for files, rmdir for directories • takes pathname, returns 0 OK, -1 error • rename changes names of files/directories • takes oldpath, newpath; returns 0 OK -1 error
link • creates directory entry for existing file • increments link count in i-node • operations atomic • only superuser can create links to directories (avoids filesystem loop problems)
unlink • removes directory entry • decrements link count in i-node • must have wx permission in directory • if sticky bit set, must own file, own directory, or be superuser • file not deleted until link count 0 and file not in use
remove • calls unlink for files, rmdir for directories • ANSI C standard (replacing unlink)
rename Function • renames directory or file • if oldname is file • if newname exists, cannot be directory • newname removed, oldname becomes newname • write permission required for both • if oldname is directory • if newname exists, must be empty directory • newname removed, oldname becomes newname • newname cannot contain oldname in path
Symbolic Links • not pointers to i-nodes • symbolic links contain pathname as data • i-node contains flag indicating symbolic link • not constrained to single filesystem, superuser creation of directory links.
symlink and readlink Functions • symlink creates symbolic link • takes realpath, sympath; returns 0 OK, -1 error • can cross filesystems • can be used for directories by ordinary users • readlink manipulates symlink file itself • takes pathname, *buffer, bufsize • returns # bytes read, -1 error • combines open, read, close on symlink file
File Times • last access time of data • system does not maintain i-node access time • last modification time of data • last modification time of i-node
utime Function • changes access and mod times of files • takes pathname, *utimbuf structure • null pointer sets to current time • requires ownership or write permission • non-null pointer requires ownership or root • returns 0 OK, -1 error
mkdir and rmdir Functions • mkdir creates directories • takes pathname, mode • usually want some execute permission • automatically creates . and .. entries • rmdir removes empty directories • takes pathname • both return 0 OK, -1 error
Reading Directories • format of directories system dependent • opendir - open directory stream • takes pathname, returns DIR *, null on error • readdir - read directory • takes DIR *, returns dirent structure *, null on error or EOD • rewinddir - reset stream to beginning of directory • takes DIR *, returns nothing • closedir - close directory stream • takes DIR *, returns nothing
chdir, fchdir, getcwd Functions • chdir, fchdir set current working directory of process • takes pathname, returns 0 OK, -1 on error • getcwd gets absolute pathname of cwd • takes buffer *, size of buffer; returns buff on success, NULL on error
Special Device Files • block special, character special • identified by major/minor numbers • block special • ramdom access device (hard disk, cdrom, etc.) • character special • sequential access device (tape drive, modem, etc.)
sync and fsync Functions • cause kernal buffers to be flushed • sync schedules a write and returns • Linux waits for completion • takes no arg, returns 0 OK, -1 on error • fsync flushes single file buffer, and waits for return • takes FD, returns 0 OK, -1 on error