Exercise 2:
$ ls –al junk
-rwx------ 1 sdivakaran registered_users 12 Feb 2 18:39 junk
Owned by sdivakaran with read write and execute permissions and was created on 2nd Feb 18:39pm and has one link.
$ ln junk new_junk
Creates a new link to junk (creates an alias to junk)
$ls –al junk
-rwx------ 2 sdivakaran registered_users 12 Feb 2 18:39 junk
Notice the number of links has increased from 1 to 2.
$chmod 755 junk
-rwxr-xr-x 2 sdivakaran registered_users 12 Feb 2 18:39 junk
The owner has rwx, group has wx and others have rx permissions.
$du junk
4 junk
This gives the number of 1k blocks allocated to junk.
$ls -i junk
129682942 junk
The inode number of junk is 129682942. i-node is a structure that stores meta data about the file including the data blocks allocated to the file data.
129682942 du junk
and its implication on file sizes and organization
File system = data structures for organizing directories and accessing the file services;
A file system in UNIX has the following structure (Maurice J. Bach [2])
The boot block occupies the beginning of a file system, typically the first sector, and may contain the bootstrap code that is read into the machine to boot, or initialize, the operating system. Although only one boot block is needed to boot the system, every file system has a (possibly empty) boot block.
The super block describes the state of a file system — how large it is, how many files it can store, where to find free space on the file system, and other information.
The i-node list contains the meta data (name, owner, permissions, list of data blocks allocated to that file, access details) corresponding to different files in the file system.
The data blocks start at the end of the inode list and contain file data and administrative data. An allocated data block can belong to one and only one file in the file system.
Exercise 3:
$ du junk
4 junk
junk uses a 1k blocks
$df
Filesystem 1K-blocks Used Available Use% Mounted on-
2063075328 857255936 1100997632 44% /home/sdivakaran
4. Accessing Files and Directories
5. File as an Abstract Data Type (Will be discussed Later)
We can view a file as an abstract data type and classify them into “internal” operations (low level kernel functions) and “external” operations (file system calls). In this document we will focus on a subset of external operations
that involve key file system services.
· File creation/deletion/opening/closing : open, close, creat, pipe, link, unlink, dup;
· Accessing file attributes or meta data : stat, chdir, chmod, chroot, mkdir;
· File access : read, write, lseek.
The figure below gives an overview of both internal and external file operations
(Maurice J. Bach [2])
6. References
The UNIX Programming Environment by Brian W. Kernighan and Rob Pike, Prentice Hall Software Series, 1984.
The Design of the UNIX Operating System by Maurice J. Bach, Prentice Hall Software Series, 1986.
File System Interface by Prof. Don Heller, Lecture Notes of CMPSC 473, Operating System Design and Construction.