You are on page 1of 57

System Software

Jimmy Mathew
jimmym@rajagiritech.ac.in
Department of Information Technology
Rajagiri School of Engineering and Technology
1

J Mathew RSET
MODULE 3
INFORMATION MANAGEMENT

2
2
J Mathew RSET
References
1. “System software – An introduction to system programming”,
Leland L Beck, 3rd edition

2. “System programming and operating system”, D M


Dhamdhere

3. “Operating system”, Peterson & Silberschatz, Addison Wesley

4. “Design of UNIX operating system”, Maurice J Bach

5. “UNIX system programming”, Stevens

6. “Operating System”, Dietal H M

3
J Mathew RSET
Self study topics
1. Details of basic file system calls

2. Pipes

3. Device management in UNIX

4
J Mathew RSET
Module overview
1. File system

2. Directory structure

3. Basic file system calls

4. File protection

5. Allocation methods

6. Disk blocks and inodes in UNIX

7. Device management

5
J Mathew RSET
File system
File system provides the followings


File naming freedom


File sharing


Protection against illegal file accesses


Reliable storage of files in directories

6
J Mathew RSET
File system
File system access is implemented by two data structures

1. File label

2. File control block (FCB)

7
J Mathew RSET
File system
File label


Contains information of size and location of the file


VTOC – Volume Table Of Contents


VTOC – contains all file labels existing in a disk volume

8
J Mathew RSET
File system
General fields of an FCB

9
J Mathew RSET
File system
General NTFS file system

10
J Mathew RSET
File system
General FAT file system

11
J Mathew RSET
File system
General comparison between FAT and NTFS

12
J Mathew RSET
File system
Example of an FCB content for an image file

13
J Mathew RSET
Directory structure
Examples

14
J Mathew RSET
Directory structure
Examples

15
J Mathew RSET
Directory structure
Directory structure in UNIX

16
J Mathew RSET
Directory structure
Directory structure in UNIX

17
J Mathew RSET
Directory structure
Directory structure in UNIX

18
J Mathew RSET
Directory structure
Directory – contains information about files

Each user has his own directory to keep files

Supports same file names in multiple directory

Master Directory – contains information about user


directories

Information in file label can be stored in directory entry

19
J Mathew RSET
Directory structure
Directory entry


File name


Location information


Protection information


Flags

20
J Mathew RSET
Directory structure
Directory structure provides a hierarchy of directories and
files

It provides a generalized syntax for accessing files

A directory can be considered as a file

21
J Mathew RSET
Directory structure
Directory hierarchies


Files are grouped


Users can create files or directories


All directories can be distinguished with a flag

22
J Mathew RSET
Directory structure
Current and Home directories


Current directory - User's directory at a specific time


Only applicable to terminal / command systems


How about current directory in MS Windows OS?


Home directory – The first directory allocated for user to
access


Every user has separate home directory


Every user starts with his home directory as the current
directory
23
J Mathew RSET
Directory structure
Access paths


A user access his files by providing file name


Another user's file can be accessed as
<user_name> → <file_name>


Access path - an unambiguous way to refer a file


Absolute access path and relative access path


Relative access path – access path related to current
directory


Absolute access paths - path starts from the root
24
J Mathew RSET
Directory structure
Links – A direscted connection in FS between two files

(<from_file>, <to_file>, <link_name>)

Directory mount points – Certain files in FS hierarchy

– mount(<FS_name>, <mount_point_name>)

– unmount(<FS_name>, <mount_point_name>)

Mount point useful when more than one FS exists in the


system

Used in distributed system to access files in a remote


machine
25
J Mathew RSET
Basic file system calls
OPEN


fd = open(pathname, flags, modes);


fd – file descriptor

READ


number = read(fd, buffer, count);

WRITE


number = write(fd, buffer, count);

26
J Mathew RSET
Basic file system calls
FILE AND RECORD LOCKING


For mutually exclusive access


File locking and record locking

LSEEK


To adjust the position of the file


position = lseek(fd, offset, reference);


Reference can be from the beginning of a file, or from the
current position in file or from end of the file

27
J Mathew RSET
Basic file system calls
CLOSE


Closes an open file


close(fd);


When a process exits, the file gets closed

CREAT


fd = creat(pathname, modes);

MKNOD

– Creates special files in the system, pipes, device files and


directories 28
J Mathew RSET
Basic file system calls
MKNOD


Creates special files in the system, pipes, device files and
directories


mknod(pathname, type and permissions, dev);

CHDIR


Changes current directory, moves to another directory


chdir(pathname);

CHROOT

– chroot(pathname); // to change the root directory 29


J Mathew RSET
Basic file system calls
CHOWN


Changes owner and group permissions


chown(pathname, owner, group);

CHMOD


Changes modes or access permissions


chmod(pathname, mode);

30
J Mathew RSET
Basic file system calls
STAT / FSTAT


Queries the status of a file


File type owner, access permissions, file size, number of
links, inode number, and file access times


stat(pathname, statbuffer);


fstat(fd, statbuffer);

31
J Mathew RSET
Basic file system calls
PIPES


FIFO – First in First out


To provide synchronization between the processes


pipe(fdptr);


Open, Write and Read

32
J Mathew RSET
Basic file system calls
DUP


Copies a file descriptor to a user file descriptor table


Returns new file descriptor


It works for all types of files


newfd = dup(fd);

33
J Mathew RSET
Basic file system calls
MOUNT and UNMOUNT


To mount and unmount file systems


mount(device pathname, directory pathname, options);


Example: mount(“/dev/dsk1”, “/usr”, 0);


unmount(device pathname);

34
J Mathew RSET
Basic file system calls
LINK


Links a file to a new name


link(source filename, target filename);


Source file – name of an existing file


Target file – New name created


Example: link(“/usr/src/util/sys”, “/usr/include/sys”);

35
J Mathew RSET
Basic file system calls
UNLINK


Removes a directory entry for a file


unlink(pathname);


Example: unlink(“myfile”);


Any further call to “myfile” will be an error


Race condition: Another process may access the file,
which is going to be unlinked from the directory entry


To avoid race condition, the file should be locked first

36
J Mathew RSET
Basic file system calls
RMDIR


Removes a directory after all its contents become empty


No files should be present in the directory


Race condition can occur


To avoid race condition, the directory can be locked

37
J Mathew RSET
File protection
Protection info field in directory entry

Access control list

– (<user_name>, <list_of_access_privileges>)

38
J Mathew RSET
Allocation methods
Contiguous file allocation method – Adapted by early file
systems

Each file as single contiguous area

Application should provide exact area required by each file

Fragmentation of disk space

Later, non contiguous allocation adapted

Each file is given fixed size memory blocks

Dynamic file allocation possible

39
J Mathew RSET
Allocation methods
Linked allocation


File as a linked list of disk blocks


Each disk block has two fields

1. Data field

2. Control information field


Data field – contains file data


Control information field – address of next disk block
allocated to this file


Free list – Group of free disk blocks 40
J Mathew RSET
Allocation methods

41
J Mathew RSET
Allocation methods

42
J Mathew RSET
Allocation methods

Simple to implement


Low overheads for allocation or deallocation


It supports sequential files


Reliability is poor


Correction of one pointer can cause loss of data


Direct access files cannot be accessed efficiently

43
J Mathew RSET
Allocation methods
Indexed allocation


Close resemblance to virtual memory systems


A file is allocated as an integral number of disk blocks of
fixed size


File map table FMT – data structure for each file


Each entry of FMT points to each disk block allocated


Each disk block has data field


Location field of a directory - points to file map tables

44
J Mathew RSET
Allocation methods

DSM – Disk Status Map


Each entry of DSM represents whether disk block is free or
allocated


DSM has single bit entry

Advantages and disadvantages of indexed allocation


Improved reliability


Correction of any link may cause partial damage


Access to sequential file is less efficient


Direct file access is more efficient 45
J Mathew RSET
Disk blocks & inodes in UNIX
Every file in UNIX has a unique inode

Inode contains


File owner identifier


File type (character, block, FIFO, etc.)


File access rights


File access times


Number of links to the file


File size
46

Table of disk addresses
J Mathew
(Location of the file's data)
RSET
Disk blocks & inodes in UNIX
Kernel converts file path to inode

47
J Mathew RSET
Disk blocks & inodes in UNIX
Inode gets modified, if file content gets modified

Inode gets modified with other actions, like change in


author, group, access permissions, etc.

To process a file, content of inode is copied to an in-core


inode

48
J Mathew RSET
Disk blocks & inodes in UNIX
In-core inode contains the following informations


Status of inode, if locked


If any process waiting for inode


Inode is dirty or modified from original


Content of the file is dirty or modified from the original


The file is a mount point


Device number of device which contains the file


Inode number
49

Reference count J -Mathew
number of instances
RSET
of the file
Disk blocks & inodes in UNIX
If inode is locked, other processes get denied access

A flag to register that some processes are waiting for inode

A flag to register inode content modified

50
J Mathew RSET
Disk blocks & inodes in UNIX
Accessing inodes


File name and inode number as identifier


An inode will be allocated from free list and locks it


Disk block num = ((inode num – 1) / number of inodes per
block) + start address


Inode offset = ((inode num – 1) modulo (number of inodes
per block)) * size of disk inode

51
J Mathew RSET
Disk blocks & inodes in UNIX
Releasing inodes


Reference count is checked


If count == 0, in-core inode is written back to disk


Kernel places the inode in the free list


Kernel releases all data blocks associated with the file

52
J Mathew RSET
Disk blocks & inodes in UNIX
Allocation of disk blocks


Kernel allocates disk blocks from file system


Direct data blocks and indirect data blocks


Super blocks – an array of free disk blocks


Mkfs –

• Make file system

• Utility program

• Arranges disk blocks as a linked list


53
J Mathew RSET
Disk blocks & inodes in UNIX

54
J Mathew RSET
Disk blocks & inodes in UNIX

Mkfs – allocates disk blocks which are nearer to the
previous allocated blocks


It reduces disk access time


No sorting of block numbers done


Alloc – algorithm to allocate a disk block


Free – algorithm to free a disk block

55
J Mathew RSET
Disk blocks & inodes in UNIX

Three major differences between inode allocation and disk
block allocation

1) Kernel can check if an inode is free by inspecting its


content, like file type field. In disk blocks, contents
cannot describe it.

2) Disk block can hold list of free other disk blocks. Inodes
have no space to store a list of inode information.

3) Disk blocks will be consumed quickly than inodes. Hence


access to the disk blocks should be time efficient.

56
J Mathew RSET
Module summary
1. File system

2. Directory structure

3. Basic file system calls

4. File protection

5. Allocation methods

6. Disk blocks and inodes in UNIX

7. Device management

57
J Mathew RSET

You might also like