File Structure
File Structure
• Below attributes tell who may access it and who may not:
• 1. Protection- Who can access the file and in what way.
• 2. Password: Password needed to access the file
• 3. Creator-ID of the person who created the file.
• 4. Owner- Current owner
File attributes
• Flags are bits or short fields that control or enable some specific property.
• 1. Read Only flag: 0 for read/write, 1 for read only.
• 2. Hidden flag-0 for normal , 1 for do not display the listing.
• 3. System flag-0 for normal, 1 for system file
• 4. Archive flag-0 for has been backed up, 1 for needs to be backed up.
• 5. Random access flag-0 for sequential access only, 1 for random access.
• 6. Temporary flag-0 for normal,1 for delete file on process exit.
• 7. Lock flag-0 for unlocked,1 for locked.
File attributes
• Below attributes are only present in files whose record can be looked
up using the key. They provide the information required to find the
keys.
• 1. Record length- Number of bytes in a record
• 2. Key position- Offset of the key within each record.
• Various attributes keeps times track of when the file was created,
most recently accessed and most recently modified.
• 1. Creation time- Date and time the file was created.
• 2. Time of last access- Date and time of file was last accessed.
• File attributes
• various attributes keeps track of file size
• 1. Current size- Number of bytes in the file
• 2. Maximus size- Number of bytes the file may grow to.
File operations
• create
• The purpose of the call is to announce that the file is coming and to set
some attributes
• Delete
• When the file is no longer needed, it has to be deleted to free up disk
space.
• Open
• The purpose of the open call is to allow the system to fetch the attributes
• Close
• When all accesses are finished the attributes and disk addresses are no
longer needed, so the file should be closed to free up table space
File Operation
• Read
• Data are read from file. Usually the bytes come from the current position.
• Write
• Data are written to the file, usually at the current position
• Append
• This call is restricted form of write. It can only add data to the end of file.
• Seek
• For a random access files, a method is needed to specify from where to
take the data
• Seek repositions the file pointer to a specific place in the file.
File Operation
• Get attributes
• Processes often need to read the file attributes to do their work
• Set attributes
• some of the attributes are user settable and can be changed after the
file has been created. this system call makes that possible.
• Rename
• It frequently happens that a user needs to change the name of an
existing file. This system call makes it possible.
Types of Files
Regular file Vs Directories
• Regular File
• Regular files are the ones that contain user information
• Example: word file, excel file etc...
• Application programs are responsible for understanding the structure
and content of any specific regular file.
• Directories
• Directories are system files for maintaining the structure of the file
system
• To keep track of files, file systems normally have directories or folder.
Different types of files
• 1. ASCII files
• ASCII file consists of line of text.
• Advantage of ASCII files is that they can be displayed and printed as it
is & they can be edited with ordinary text editor.
• If number of programs use ASCII files for input and output, it is easy
to connect the output of one program to the input of another.
• C/C++/Perl/HTML files are all examples of ASCII files.
Different types of files
• 2. Binary files
• Binary files contain formatted information that only certain
applications or processors can understand
• Binary files must be run on the appropriate software or processor
before humans can read them.
• Executable files, compiled programs, spreadsheets, compressed files
and graphic(image) files are all example of binary files.
Different types of files
• 3 Device files
• Under linux and UNIX each and every hardware device is treated as a
file. A device file allow to access hardware devices so that end users
do not need to get technical details about hardware.
• In short, a device file(also called as a special file) is an interface for a
device driver that appears in a file system as if it were an ordinary file.
• This allows software to interact with the device driver using standard
input/output system calls, which simplifies many tasks.
Different types of files
• In Sequential access, process could read all the bytes or records from
a file in order, starting at the beginning but could not skip around and
read them out of order.
• Sequential files could be rewound, however so they could be read as
often as needed.
• These files were convenient when the storage medium was magnetic
tape or CD-ROM.
Files access methods
• Relative path name is used in conjunction with the concept of the working
directory
• User can designate one directory as the current working directory, in which
case, all path names not beginning at the root directory are taken relative
to working directory.
• For example if the current working is /usr/ast, then the file whose absolute
path is /usr/as/mailbox can be referenced simply as mailbox.
• Most operating systems that support a hierarchical directory system have
two special entries in every directory.
• 1. "." or "dot" refers to current directory
• 2. ".." or "dotdot" refers to parent directory
Directory Operations
Opendir
• Directories can be read.
• For example, to list all the files in a directory, a listing program opens
the directory to read out the names of all the files it contains.
• Before a directory can be read, it must be opened.
Closedir
• when a directory has been read, it should be closed to free up space.
Directory Operations
Readdir
• This call returns the next entry in an open directory.
• It was possible to read directories using the usual read system call,
but that approach has the disadvantage of forcing the programmer to
know and deal with the internal structure of directories.
• In contrast, readdir always returns one entry in a standard format, no
matter which of the possible directory structure is being used.
Rename
• In many respects, directories are just like files and can be renamed
the same way files can be.
Directory Operations
• Link
• linking is a technique that allows a file to appear in more than one
directory.
• This system call specified an existing file and a path name, and creates a
link from the existing file to the name specified by the path.
• In this way, the same file may appear in multiple directories.
• Unlink
• A directory entry is removed
• If the file being unlinked is only present in one directory( the normal case),
it is removed from the file system.
• If it is present in multiple directories, only the path name specified is
removed. The others remain.
MBR (Master Boot Record)
• The information related to all file(not the content) is stored in an inode table on the disk.
• For each file, there is an inode entry in table
• Each entry is made up of 64 bytes and contain the detail for that file
• These details are:
• Owner of file
• Group to which the owner belongs
Types of file
• File access permission
• Date and time of last access
• Date and time of last modification
• Size of file
• address of blocks where the file is physically present
Data block
• Advantages
• Relatively simple and efficient
• Easy to get contiguous files
Linked List
• 1. Linear List
• linear list of file names with pointer to the data blocks
• It is simple to program
• It is time consuming to execute
• 2. Hash Table
• It uses hash table-linear list with hash data structure
• It decreases directory search time
• It may cause collision- situations where two file names hash to the same
location.
Efficiency and performance
• 1. First should the entire file system be backup or only part of it? It is
usually desirable to back up only specific directories and everything in
them rather than the entire file system.
• 2. It is wasteful to back up files that have no change since the
previous backup which leads to the idea of incremental dumps.
• 3. third since huge amount of data are typically dumped, it may be
desirable to compress the data before writing them to tape.
• 4. It is difficult to perform a backup on an active file system.
• 5. Making backups introduce many nontechnical problems into an
organization.
Physical dump vs logical dump
Physical dump
• It is started at block 0 of the disk, writes all the disk bocks onto the
output tape in order, and stops when it has copied the last one.
• Such program is so simple that it can probably be made 100% bug
free.
• Main advantage of physical dumping are simplicity and great speed.
Logical dump:
• It is started at one or more specified directories and recursively
dumps all files and directories found there that have changed since
some given base date.
• In logical backup individual files can be backed up and restored as per
the requirements.
File system consistency
• Two kinds of consistency check can be made:
• 1. Blocks
• 2. Files
Block consistency
• To check for block consistency, the program builds two tables, each
one containing a counter for each block, initially set to 0
Block consistency
• If the file system is consistent, each block will have a 1 either in the
first table or in the second table.