System programming files and directories

Pdf File 117.66 KByte, 9 Pages

SYSTEM PROGRAMMING: FILES AND DIRECTORIES

Onur Tolga S?ehitog lu

METU, CEng 536 Lecture notes Octobe, 2006

Filesystem

Filesystem

System Programming: Files and Directories

? Hierarchical structure of directories rooted by /

? A filesystem is a directory and file structure laying on the same logical entity (memory or disk partition, network resource).

? Different Unix based filesystems available like: ufs, sys5fs, xfs, ext2, ext3,... ? Other foreign filesystems are implemented: dosfs, vfat, ntfs, iso9660,...

? Network filesystems does not keep data structures but maps them to remote services: nfs, rfs, smbfs,...

? Memory based filesystems are kept on main memory: tmpfs, ramfs,...

CEng 536 Lecture Notes

2

Filesystem

/

System Programming: Files and Directories

bin

dev

usr

home

/dev/dsk/c0t0d0s0

etc bin local

/dev/dsk/c0t0d0s6

bin etc lib

guest onur

/dev/dsk/c0t0d0s7

server:/shared/local

CEng 536 Lecture Notes

3

inodes

System Programming: Files and Directories

inodes

? vnode is the generic name for all fs types. Unix style fs's have i-nodes.

? For each file, there is a corresponding block keeping the vital information for accessing file called inode.

? inodes keep: filetype, permissions,number of hard links to file, owner uid, owner gid, size in bytes, access time, change time, modify time, addresses to data blocks

? What about filenames? They are inside data blocks of directories

? Directories are special typed filetypes including filename/inode pairs in data blocks.

? Data is stored in data blocks, inode of the file points to all data blocks of a file.

CEng 536 Lecture Notes

4

Accessing a File

System Programming: Files and Directories

Accessing a File

? A file name like /home/onur/test.c ? Start from the root, "/" directory, access its i-node, get data block, load

it. ? home exists, get i-node repeat above for that i-node. ? onur exists, get i-node and repeat above for that ? test.c exists, get i-node ? get data blocks, open file

CEng 536 Lecture Notes

5

Links

System Programming: Files and Directories

Links

? Two type of links: hard links and soft links exist.

? hard links: Two directory entry can map to same i-node, thus same file. Transparent to user.

? soft links: A special file type, symbolic link exists. Data block contains a relative path. Kernel continue traversing by loading symbolic links. Not transparent, process can distinguish the link file and the original file.

? Hard links are faster but restricted: only can link a file in the same fs (inodes are unique to fs). Cyclic reference problems cannot be tracked. Only system administrator can link to a directory.

? Soft links can link file in another fs. They can dangle (original file can be deleted while link still exists). Cyclic references can be avoided by countint the maximum number of visited link.

CEng 536 Lecture Notes

6

Download Pdf File