0% found this document useful (0 votes)
50 views1 page

Example: FD Creat ("Abc - TXT", O - RDONLY, 0666) 0666-RWX To File Owner. 0777-RWX To All Owners. Explanation of Algorithm

The creat system call creates a new file with the specified name and permission modes, returning an integer file descriptor. It searches for the file, truncates it if found to zero size, and assigns an inode and writes the file name and inode in the parent directory. It then initializes the file and inode tables and returns the file descriptor.

Uploaded by

IAGPLS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views1 page

Example: FD Creat ("Abc - TXT", O - RDONLY, 0666) 0666-RWX To File Owner. 0777-RWX To All Owners. Explanation of Algorithm

The creat system call creates a new file with the specified name and permission modes, returning an integer file descriptor. It searches for the file, truncates it if found to zero size, and assigns an inode and writes the file name and inode in the parent directory. It then initializes the file and inode tables and returns the file descriptor.

Uploaded by

IAGPLS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The open system call gives a process access to an existing file, but the creat system call

creates a new file in the system.


The syntax for the creat system call is
fd =creat(pathname, modes); where
pathname ---is a filename,
modes ----give the file permissions if the file being created
fd-, the creat system call returns an integer called the user file descriptor.
In this system call creates new file with the specified name and permission modes.
Example: fd= Creat(“abc.txt”, O_RDONLY,0666);
ExampleS of permission modes in octal number:
0666-RWX to file owner.
0777- RWX to all owners.

Explanation of Algorithm:
 The Kernel searches the specified file and if file already exists then it truncates
the file (File Size Zero) and returns the existing file descriptor slot.
 Kernel assigns an inode for the new file,and then it writes the new file name
component and the inode in the parent directory, the byte offset saved in the u
area. Afterwards, it releases the inode of the parent directory.
 It finally initializes the file table and i-node table.
Algorithm:
I/P: Pathname
O/P: Fd
{
get inode from file system;
if(file already exists)
{
If (permission denied)
{
Return (error);
}

truncate the file(free all blocks);


}

else
{
Assign the i-node to the new file;
Create new entry in the parent entry: File Name & inode no;
Initialize file table and inode table;
}
return (fd);
}

You might also like