





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






























15-410, F’ 1
Dave Eckhardt & Todd Mowry Contributions from n Rahul Iyer L31_Filesystem
15-410, F’ 2
Today n Chapter 10, File system interface n Ok to skip: remote/distributed (10.5.2!!) Also read Chapter 13 n Might help demystify readline() some
15-410, F’ 4
Name – 14 characters? 8.3? 255? n Unicode? ASCII? 6-bit? RADIX-50? Identifier – “file number” (usually internal) Type (or not) – hint for launching app, or not Location – device, block list Size – two meanings (next lecture) Protection – Who can do what? Time, date, last modifier – monitoring, cleaning up
15-410, F’ 5
BSD Unix n archived n nodump n append-only (by user/by operating system) n immutable (by user/by operating system) MacOS n icon color Plan 9 n Identity of most recent mutator
15-410, F’ 7
Users will read/write files n Not being able to defies the point in having them So, how do you read from and write to one? n read(“README.dox”, input_buffer, num_bytes); n What's the problem with this?
15-410, F’ 8
Users will read/write files n Not being able to defies the point in having them So, how do you read from and write to one? n read(“README.dox”, input_buffer, num_bytes); n What's the problem with this? n read(“README.dox”, input_buffer, num_bytes, start_loc); n What's the problem with this? What's the solution?
15-410, F’ 10
“In-core” file state – avoid going to disk repeatedly n Mirror of on-disk structure n File number, size, permissions, modification time, ... n Housekeeping info n Back pointer to enclosing file system n Pointer to disk device hosting the file n Who holds locks on ranges of file n How to access file (vector of methods) n Pointer to file's type-specific data Shared when file is opened multiple times
15-410, F’ 11
“Open file” state – result of one open() call n Results are retained for use by multiple I/O calls n Pointer to underlying “open file” n Credentials of process (when it opened the file) n Access mode (read vs. write, auto-append, ...) n Cursor position Shared by multiple processes n “copied” by fork() n inherited across exec()
15-410, F’ 13
int fd1, fd2, fd3; off_t pos2, pos3; char buf[10]; fd1 = open(“foo.c”, O_RDONLY, 0); fd2 = dup(fd1); fd3 = open(“foo.c”, O_RDONLY, 0); read(fd1, &buf, sizeof (buf)); pos2 = lseek(fd2, 0L, SEEK_CUR); / 10 / pos3 = lseek(fd3, 0L, SEEK_CUR); / 0 /
15-410, F’ 14
0 1 2 3 4 5
r/o r/w r/o pos 10 r/o pos 0
15-410, F’ 16
What's in a file? n Stream of bytes? n What character set? US-ASCII? Latin-1? Unicode? n Stream of records? n Array of records? Tree of records? Record structure? n End of “line” n CR, LF, CR+LF n Fixed-length? Varying? Bounded?
15-410, F’ 17
Program loader needs to know about executables n “Magic numbers” in first two bytes n obsolete A.OUT types - OMAGIC, NMAGIC, ZMAGIC n ELF n #! - script Otherwise, array of bytes n User/application remembers meaning (hopefully!) For a good time... n Try the “file” command n Read /usr/share/misc/magic or /usr/share/file/magic n Marvel at the dedication of the masses – 16,000 lines!
15-410, F’ 19
Provided by OS or optional program library Sequential n Like a tape n read() next, write() next, rewind() n Sometimes: skip forward/backward Direct/relative n Array of fixed-size records n Read/write any record, by #
15-410, F’ 20
File contains records Records contain keys Index maps keys ⇒ records n Sort data portion by key n Binary search in multi-level list Fancy extensions n Multiple keys, multiple indices n Are we having a database yet? n Missing: relations, triggers, consistency, transactions, ... n Unix equivalent: dbm/ndbm/gdbm/bdb/...