DOC PREVIEW
UNO CSCI 8530 - System Call Implementation

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

11The Tempo/32 Operating SystemPart 9System Call ImplementationThe Tempo Filesystem2Filesystem – Quick Review• Filesystem is “object” with methods for managing named collections of data• Methods usually called open, close, read, write, etc.• Semantics (unique to each type)– Naming conventions– File sharing– Size limitations– Creation/deletion rules–Protection– Reliability– Efficiency/Performance–Etc.3Tempo Filesystem• Tree-structured filesystem similar to UNIX (e.g. two file types: regular and directory).• Files are identified by a path that consists of zero or more names separated by ‘/’; names are limited to 15 chars (ex. /abcdefghijklmno/X3.c)• No concept (yet) of a “working directory”, so no concept (yet) of a “relative” path.• Maximum file size is 70,656 bytes (currently).• There is no concept of a username or date and time associated with files.• No facility for “mounting” drives or partitions.4Filesystem Calls – Review• open(path,mode) – opens the file at path returning a file descriptor• creat(path) – creates a new file at path, open for writing• read(fd,buff,count) – reads countbytes from fd into buff• write(fd,buff,count) – writes count bytes to fd from buff• seek(fd,offset,start) – positions file fd so next I/O is at start [begin / current / end] + offset• mkdir(path) – make a directory at path• close(fd) – close open file fd• remove(path) – delete (or mark for deletion) the file at path• stat(path,buf), fstat(fd,buf) – get file (path or fd) metainformation• rename(oldname,newname) – rename a file• opencon(void) – open console for I/O• setconmode(fd,mode) – set console mode (raw or cooked)5Tempo Filesystem Basics• The disk contains:– the “superblock,” which identifies the type of filesystem, its size, and the logical block number (LBN) of the first unused block; also contains the root directory entry.– a linked list of unused disk blocks (with the head pointer in the superblock)– directory blocks containing directory entries– data blocks – executables, data, etc.6Superblock Format• char fsident[8] – “fsys1.0”• unsigned nblocks – # blocks in filesystem• unsigned freeblk – first free disk block• struct dirent rootde – root directory entry• char rsvd[432] – unused27Directory Entry Format• unsigned char dflag –– 0x00 = unused entry– 0x01 = regular file– 0x02 = directory• char fname[15] – file name, padded with ‘\0’• unsigned fsize – file size, in bytes (always a multiple of 512 for directories)• unsigned dir[10] – block nums of first 10 blocks• unsigned indir – block num of blk with 128 additional block pointers8Sytem-Wide Open File Cache• Every open file in the system is recorded in an entry of the ‘fdesc’ array (defined in kernel/fs.c).• There are NFDESC entries in this array, each of which is of type ‘struct FDESC’ (defined in h/types.h).• If multiple processes have the same file open, there is only one entry in the fdesc array for the file. This guarantees that changes to the file’s directory entry will be recorded in only one place.9struct FDESCstruct FDESC { /* system-wide, one entry per open file */int nrefs; /* ref count */unsigned int flags;unsigned int blockno; /* block containing dir entry */unsigned int offset; /* 'blockno' offset of dir entry */struct dirent de; /* "in-core" directory entry */};The ‘flags’ entry can contain any or all of these bits:FDE_DIRTY – the directory entry has changed since it was read from diskFDE_RMPEND – removal is pending for the fileFDE_LOCKED – the entry is locked by a process performing an operation10Per-Process Open File Info.• Each process (in the process table entry) has an array (fd) in which entries for its open files are recorded.• Each of these entries (of type struct FD, defined in h/types.h) gives:– how the file was opened (read/write/etc.)– the index in the system-wide fdesc array of file information– the offset in the file where the next read/write will take place11FileXFileYUnusedFile ZFileYFileAFileCFileBFileZFileZUnusedUnused012301230123Process P1Process P2Process P3fdesc arrayEntry for file XEntry for file AUnusedEntry for file YEntry for file BEntry for file ZEntry for file CUnused…nrefs = 1nrefs = 1nrefs = 0nrefs = 2nrefs = 1nrefs = 3nrefs = 1nrefs = 0Relation between per-process open file entries and the fdesc array entries. Note that process P3 has FileZopen twice.Per-Process Information System-wide Open File Information12SuperblockRoot DirBlk 0FileAFileBEmptyFileDDirX…Data for FileA.0Data for FileB.0Data for FileB.1Data for FileD.0Data for FileD.9…Indirs for FileDData for FileD.10Data for FileD.11FileXFileYEmptyDirFFileZ…FreeFreeFreeThe root directory contains:FileA (<= 512 bytes)FileB between 513 and 1024 bytes)FileD (between 5121 and 5632 bytes)DirXDirectory DirX contains:FileX, FileY, DirF, and FileZA Small Filesystem313Block Size Observations - 1• Each “block” in the current filesystem is just one sector: 512 bytes.• A file can have at most 138 total blocks– 10 direct blocks (10 “direct” pointers)– 128 indirect blocks (1 block of 4-byte pointers)• Thus the maximum file size is 138 × 512 = 70,656 bytes.• The average wasted space in a regular file is half a block, or 256 bytes.14Block Size Observations - 2• Changing the block size to 4K bytes (8 sectors) would give 1034 blocks– 10 direct blocks– 1024 indirect blocks (4096 ÷ 4 = 1024)• The maximum file size is now 1034 × 4096 = 4,235,264 bytes.• The average wasted space in a regular file increases to 2048 bytes.15Following a Path• Many file operations require locating its directory entry. For example, to locate file ‘DirX/FileY’ we must:– Parse the path to obtain its components– Search the blocks of the root directory for DirX– Search the blocks of DirX for FileY• Each search operation has to sequentially read the blocks of the directory being examined.16SuperblockRoot DirBlk 0FileAFileBEmptyFileDDirX…Data for FileA.0Data for FileB.0Data for FileB.1Data for FileD.0Data for FileD.9…Indirs for FileDData for FileD.10Data for FileD.11FileXFileYEmptyDirFFileZ…FreeFreeFreeOpening /DirX/FileYStep 1: Read first block of root directory (the superblock is always in memory)17SuperblockRoot DirBlk 0FileAFileBEmptyFileDDirX…Data for FileA.0Data for FileB.0Data for FileB.1Data for


View Full Document

UNO CSCI 8530 - System Call Implementation

Download System Call Implementation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view System Call Implementation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view System Call Implementation 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?