0% found this document useful (0 votes)
20 views

Files Sysmte System Call

The Linux file system uses system calls to manage files and file metadata. The key data structures are the super block, which stores file system properties and free block/inode lists, and the inode table, which stores file metadata. The open, read, write, create, and close system calls manipulate file descriptors and associated file and inode table entries to access and manage files.

Uploaded by

vivek
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Files Sysmte System Call

The Linux file system uses system calls to manage files and file metadata. The key data structures are the super block, which stores file system properties and free block/inode lists, and the inode table, which stores file metadata. The open, read, write, create, and close system calls manipulate file descriptors and associated file and inode table entries to access and manage files.

Uploaded by

vivek
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Linux File system System Calls

Super block
• consists of
- the size of the file system
- the number of free blocks in the file system
- a list of free blocks available on the file system
- the index of the next free block in the free block list
- the size of the inode list
- the number of free inodes in the file system
- a list of free inodes in the file system
- the index of the next free inode in the free inode list
- lock fields for the free block and free inode lists
- a flag indicating that the super block has been modified
Algorithm for open
Open
• Fd=open(pathname, flags, modes);
– Pathname : file name
– Flags : type of the open
– Modes : file permission (esp for creat)
– Returns an integer called the user file descriptor
Data structures for open
Process B: fd1= open(''/etc/passwd", O_RDONLY);
fd2 ,.,. open("private", O_RDONLY);

Process A:
Read
• The syntax of the read system call is
number = read(fd, buffer, count)

-fd is the file descriptor returned by open


-buffer is the address of the data structure
-Count is the number of bytes the user wants to read
-number is the number of bytes actually read
Write() system call
• The syntax for the write system call is
number = write(fd, buffer, count);
• where the meaning of the variables fd, buffer,
count, and number are the same as they are
for the read system call.
• The algorithm for writing a regular file is
similar to that for reading a regular file.
Create()
• The creat system call creates a new file in the
system. The syntax for the creat system call is
fd - creat(pathname, modes) ;
• Where the variables pathname, modes, and fd
mean the same as they do in the open system
call.
Close()
• The syntax for the close system call is
close(fd);
– where fd is the file descriptor for the open file.
• The kernel does the close operation by
manipulating the file descriptor and the
corresponding file table and inode table
entries. If the reference count of the file table
entry is greater than 1
Process B: fd1= open(''/etc/passwd", O_RDONLY);
fd2 ,.,. open("private", O_RDONLY);

Process A:
Tables after closing a file
Cp program
Cp …

You might also like