SLIDE 2 2
Files: The User’s Point of View
– ascii - human readable – binary - comput er only readable – “magic number” or ext ension (execut able, c-f ile … )
– sequent ial (f or charact er f iles, an abst ract ion of I / O of serial device such as a modem) – random (f or block f iles, an abst ract ion of I / O t o block device such as a disk)
– t ime, prot ect ion, owner, hidden, lock, size ...
File Operat ions
- Creat e
- Delet e
- Tr uncat e
- Open
- Read
- Writ e
- Append
- Seek - f or r andom access
- Get at t r ibut es
- Set at t r ibut es
Example: Unix open()
int open(char *path, int flags [, int mode])
- path is name of f ile
- flags is bit map t o set swit ch
– O_RDONLY, O_WRONLY… – O_CREATE t hen use mode f or per ms
- on success, ret urns index
- on f ailure, ret urns -1
Unix open() - Under t he Hood
int fid = open(“blah”, flags); read(fid, …); User Space Syst em Space stdin stdout stderr ...
1 2 3
File Structure ... ... File Descriptor (where blocks are) (at t ribut es) (index) (P er process) (P er device)
Example: Windows CreateFile()
- Ret urns f ile obj ect handle:
HANDLE CreateFile ( lpFileName, // name of file dwDesiredAccess, // read-write dwShareMode, // shared or not lpSecurity, // permissions ... )
- File obj ect s used f or all: f iles,
direct ories, disk drives, port s, pipes, socket s and console
File Syst em I mplement at ion
P rocess Cont rol Block Open File P
Ar r ay Open File Table File Descript or Table (in memory copy,
device) (per process) Disk File sys info File descriptors
Copy f d to mem
Directories
Data Next up: f ile descr ipt or s!