
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth look into the unix file system, focusing on the posix api and file descriptors. Topics covered include file and directory concepts, i-nodes, file descriptors, and error handling. The document also discusses the use of the restart library for simplifying read and write operations.
Typology: Study notes
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























The Unix File System Lawrence Angrave Midterm statistics http://www.cs.uiuc.edu/class/fa06/cs241/MidTerm.pdf
API... open? stat? Why so many options in open? How do I make my code robust? What concepts underpin the POISX filesystem API? What exactly is a file, directory...? I-node?
Unicode file Typed Fields and Records Key indices Unified. Get the contents of a file as bytes #include <unistd.h> ssize_t read(int fildes, void *buf, size_t nbyte);
Don't need to read entire file ... Grab bytes into your buffer ... Next call to read will read next unread byte Can even read the bytes of a 'directory'
Upon successful completion, read(), readv(), and pread() return the number of bytes actually read and placed in the buffer. The system guarantees to read the number of bytes requested if the descriptor references a normal file that has that many bytes left before the end-of-file, but in no other case.
Return 0: End of File Return -1: Check errno and act accordingly e.g. EINTR; restart Return +N: # bytes placed into buffer
Integer file descriptor POSIX open() Let's dig deeper... ... Errors and options ... Directory organization & implementation ... How does O/S Manage file descriptors?
fd=open("/tmp/1.txt", options ); if(fd <1) error (e.g. File doesn't exist) r=read(fd,buffer,sizeof(buffer)) handle special cases (eof,restart, media errors) close(fd); free up resources
ENOENT : O_CREAT is not set and the named file does not exist. Or, a directory component in pathname does not exist or is a dangling symbolic link.
Pathnames -> travserse directories Imposes a hierarchy on files Files can be referenced from more than one directory Organization of files useful for security
Meta-information about a file modification and access time Kind of file (e.g. Directory | regular file?) Support for symbolic links