File Systems Flashcards
secondary storage
backs up main memory
usually a disk
file systems provide
a mechanism for storage of data and programs on the disk and accessing them
files are mapped by OS to physical address
different storage devices
- some transfer a character or a block of character at a time
- some can be accessed sequentially/randomly
- some transfer data synchronously/asynchronously
- some can be read-only/read-write
essential requirements for long-term information storage
- It must be possible to store a very large amount of information
- Information must survive termination of process using it
- Multiple processes must be able to access information concurrently
file system
- A way to organise and (persistently) store information
- An abstraction over storage devices:
- Hard disk, SSD, network, RAM, …
- Organised in files and (typically) directories
file system flow
user program syscall -> virtual fs -> page cache -> fs driver (FAT, NFTS…) -> buffer cache ->storage
files
- Abstract storage nodes, i.e. logical storage unit
- a file is a named collection of related information that is recorder on secondary storage
file types
regular: directories, soft links
special: device files, metadata…
file structure
OS perspective: files as streams of bytes
program’s perspective: archives, executables, etc.
file naming
extensions
name length
case sensitivity
once a file is named it becomes independent
file types
- executable
- object
- source
- batch
- text
- word processors
- library
8.print or view - archive
- multimedia
executable file
exe, com, bin or none
ready-to-run machine language program
object
obj, o
compiled machine language, not linked
source code
c, cpp, java, py
j
batch
bat, sh
commands to the command interpreter
text
txt, doc
word processor
wp, doc, rtf
library
lib, a
libraries f routines for programmes
print or view
ps, pdf, jpg
ASCII or binary in a format for printing or viewing
archive
arc, zip, tar
related files grouped into one file sometimes compressed for archiving and storage
multmedia
mp3,m mp4, avi
binary file containing audio or A/V info
MAC OS X file identification
each file has a type specified with it to identify its type
UNIX file identification
magic number stored at the beginning of some files to indicate the type
file attributes
name: human readable
identifier
type
location
size
creation date
last modified
…
Where are file attributes stored?
in file control block
file operations
- create & delete
- open & close
- read & write
- append
- seek
- get & set attributes
- rename
creating a file
- check if space is available and find spot for it
- make an entry in the directory
writing a file
- system call with the name of the file and the info to write
- OS finds the file
- write from the write pointer
- update pointer
reading a file
- sys call name of the file and which part to read
- OS locates the file
- read from the pointer
- update pointer
seek a file
- OS finds the file
- current-file-position pointer is repositioned to a given value
deleting a file
- OS finds the file
- release the space occupied by that file
truncating a file
- keep all attributes same except file length → set to zero
- release the file space
ENOENT
file doesn’t exist
EBADF
bad file descriptor
opening a file returns
a handel (file descriptor) for future operations
unlink(“file”)
removing a file
rename(“file”, “new_name”)
renaming
chmod(“file”, 0755)
change file permission
chown(“file”, uid, gid)
change owner
sequential file access
- information is processed in order
- most common method in editors, compilers etc.
- read: read next → advance pointer
- write: write next → appends to the end of the file → move pointer to new end of file
direct file access (relative access)
- the file is viewed as a numbered sequence of blocks or records
- great for accessing large amount of information → databases
- read: read n → reads from block n
- write: write n → writes to block n
directories
- Data structures organising and maintaining information about files
- Often stored as file entries with special attributes
- disk is split into: partitions/slices/minidisk → combined to form volumes
- each volume can be treated as a virtual disk → allows running multiple OSs and having multiple file systems
- partition: directory + files