L5/6: Files and Directories Flashcards
Six Main Topics
in the
Systems Programming Class
Program Development
Files and Directories
Tool Building
Processes
Networking
OS Implementation
Shell Command Equivalents:
mv
From stdio.h library:
rename( old_filepath, new_filepath);
Equivalent to:
%mv old new
Shell Command Equivalents:
ln
From unistd.h library:
link( old_filepath, new_filepath);
Equivalent to:
%ln old new
Shell Command Equivalents:
rm
From unistd.h library:
unlink( “old_file” );
Equivalent to:
%rm old_file
Shell Command Equivalents:
rm -r
From stdio.h library:
remove( “old_file” );
Equivalent to:
%rm -r old_file
Shell Command Equivalents:
cp
No direct method.
Use read/write File I/O operations
to copy old file to new.
Equivalent to:
%cp old new
Shell Command Equivalents:
cd
From unistd.h library:
chdir( “path” );
Equivalent to:
%cd path
Shell Command Equivalents:
mkdir
From unistd.h library:
mkdir( “newpath”, 0777);
Note: Not sure what the 0777 flag does
Equivalent to:
%mkdir newpath
Shell Command Equivalents:
rmdir
From unistd.h library:
rmdir( “path”);
Equivalent to:
%rmdir path
unistd.h
Methods that are equivalent to
common shell commands (5)
- link()
- equivalent to “ln”
- unlink()
- equivalent to “rm”
- chdir()
- equivalent to “chdir”
- mkdir()
- equivalent to “mkdir”
- rmdir()
- equivalent to “rmdir”
Physical Disk Organization:
Partition Sections
- boot and superblocks
- ilist
- contains inodes
- datablocks
Physical Disk Organization:
inode structure
An inode consists of
- a status block
- addresses to multiple data blocks
Physical Disk Organization:
Key Points
- Disk is arranged into blocks
- some for data
- some for management
- Each inode corresponds to one file and the data blocks associated with that file
- Physical layout is not consecutive, file blocks can be all over the place
How many data blocks can an inode point to?
13
How do inodes handle larger file sizes?
- The inode only has 13 pointers, so an indirect approach is used
- File blocks can each contain many pointers
- Pointers are classified into levels L0, L1, L2, …
- This allows a hierarchy of blocks to be created to handle arbitrary file sizes
- Level L0 is a pointer that points directly to an actual datablock
- L1 points to a block of L0 pointers, L2 to a block of L1 pointers, and so on.