Banker's algorithm
algorithm is worst-case: as if processes were run sequentially
a system in a safe state can never deadlock
peripheral devices: many properties
disk device: 3-tuple addressing (cylinder, platter, sector)
filesystem: data structure on top of block sequence
Unix-based systems: hierarchical system of directories & files
file attributes: metadata (data about the data)
file formats
file operations
openclosereadwritetelllseekioctlfcntlcreat(2) vs. open(2)
creat(const char *pathname, int flags)open(const char *pathname, int flags, mode_t mode)
opening file is more complex than one might expect
flags: symbolic values, powers of 2 (bitwise operations, values ored together)
O_RDONLY, O_WRONLY, O_RDWRO_APPEND, O_CREAT, O_EXCL, O_TRUNC, ...mode: permission bits
chmod(2)file operations
open: open fileclose: close file, release kernel resourcesread: read specified #bytes, advance file pointerwrite: write specified #bytes, advance file pointertell: return current position of file pointerlseek: reposition file pointerioctl: device-specific operation (general interface)fcntl: file (kernel data structure) parametersrepositioning the file pointer: off_t lseek(int fd, off_t offest, int whence);
SEEK_SET (O): from beginning (positive offset)SEEK_CUR (1): from current position (positive or negative offset)SEEK_END (2): from end (negative offset)llseek(2): obsolete system call for 32-bit systems to use 64-bit file addressing
int ioctl(int fd, unsigned long request, ...)
man 4 tty: teletype (dumb terminal: keyboard & screen)man 4 sd: SCSI disksadvisory file locks: flock(2)
metadata syscalls
unlink (delete file)renamestatutimehigher-level File I/O (userland standard library)
C (stdio library):
FILE *fopen(char *fname, char *mode);
fread(void *p, size_t size, size_t nmemb, FILE *stream);
fwrite(const void *p, size_t size, size_t nmemb, FILE *stream);
fclose(FILE *stream);
C++ (streams):
filestream f(fname, ios:in);
filestream f(fname, ios:out);
f << buf;
f >> buf;
f.close()
Java:
FileInputStream inputStream = new FileInputStream(fileName);
ObjectInputStream input = new OjectInputStream(inputStream.getInputStream());
Object obj = input.objectRead();
FileOputStream outputStream = new FileOutpuStream(filename);
ObjectOutputStream output = new ObjectOutputStream(outputStream.getOutputStream());
output.objectWrite(obj);
f.close()
mmap(2)