2. FILE CONCEPT:
What is the file?
The file can be explained as the smallest unit of storage on a computer system. The
user can perform file operations like open, close, read, write, and modify.
File concept
The operating system can provide a logical view of the information stored in the disks, this
logical unit is known as a file. The information stored in files is not lost during power failures.
A file helps to write data on the computer. It is a sequence of bits, bytes, or records, the structure
of which is defined by the owner and depends on the type of the file.
3. A file is a named collection of related information that is recorded on secondary
storage such as magnetic disks, magnetic tapes and optical disks.
In general, a file is a sequence of bits, bytes, lines or records whose meaning is
defined by the files creator and user.
File types define how files and organizational data are stored in a business.
A file type is usually identified by the file extension and the applications
associated with the file.
Each stored file can have multiple file extensions but a single file format.
The operating system can provide a logical view of the information stored in the
disks, this logical unit is known as a file. The information stored in files is not
lost during power failures.
4. TYPES OF THE FILE CONCEPT
File Attributes
File operations
File Types
File Structure
Internal File structure
5. FILE ATTRIBUTES:
• A file is named for the convenience of its human users,and is referred to by its
name.
• A name is usually a string of characters , such as example . c. Some system
differentiate between uppercase and lowercase characters in names , whereas
other system do not.
• When a file is named , it becomes independent of the process , the user , and
even the system that created it.
• The file’s owner might write the file to a USB disk , senf it as an e-mail
attachment or copy it across a network ,and it could still be called example .c
on the destination system.
6. Here are diffe
There are different types of file attributes:
Name: The symbolic file name is the only information kept in human-readable form.
Identifier: This unique tag , usally a number , identifies the file within the file system; it is
the non-human-readable name for the file.
Type : This information is needed for system that support different types of files.
Location : This information is a pointer to a device and to the location of the file on that
device.
Size : The current size of the (in bytes , words , or blocks)and possibly the maximum allowed
size are include in this attribute.
7. Protection: Access-control information determines who can do reading, writing, executing, and so
on.
Time , date , and user identification: This information may be keptor creation last modification and
last use. These data can be useful for protection, security and usage monitoring.
Some newer file system also support extended file attributes ,including character encoding of the file
and security features such as a file checksum.
The information about all files is kept in the directory structure, which also resides on secondary
storage.
Typically a directory entrt consiste of the file’s name and its unique identifier.The identifier in turn
locates the other file attributes.
It may take more than a kilobyte to record this information for each file.
9. FILE OPERATIONS:
A file is a collection of logically related data that is recorded on the secondary storage in the
form of sequence of operations. The content of the files are defined by its creator who is
creating the file. The various operations which can be implemented on a file such as read,
write, open and close etc. are called file operations. These operations are performed by the user
by using the commands provided by the operating system.
Some common operations are as follows:
Creating a file:
This operation is used to create a file in the file system. It is the most widely used operation
performed on the file system. To create a new file of a particular type the associated application
program calls the file system. This file system allocates space to the file. As the file system
knows the format of directory structure, so entry of this new file is made into the appropriate
directory.
Two steps are needed to create a file. First, one is checking whether the space is available, or
not. If the space is available then made an entry for the new file must be made in the directory.
The entry includes the name of the file, the path of the file etc.
10. Writing file:
To write a file, we have to know two things one is the name of the file and the second
is the information or data to be written on the file. Given The name of the file, the system
searches the directory to find the file’s location. The system must keep a write pointer to the
location in the file where the next write is to take place.
Reading a file:
Read operation is performed just to read the data on the file. OS(operating system)
maintains a read pointer, which points to the position up to which the data has been read.
To read a file, first of all, we search the directories for the file. If the file is found, the
system needs to keep a read pointer to the location in the file where the next read is to take
place once the reader has taken place, the read pointer is updated.
11. Repositioning within a file:The directory is searched for the appropriate entry, and the
current-file-position pointer is repositioned to a given value. repositioning within a file need
not involve any actual I/O. This file operation is also know as a file Seek.
Deleting a file:To delete a file ,We search the directory for the named file. Having found the
associated directory entry we release all file ,space, so that it can be reused by other files , and
erase the directory entry.
Truncating a file:The user may want to erase the contents of a file but keep its attributes ,
rather than forcing the user to deleting the file and then recreate it, this function allow all
attributes to remain unchanged –except for file length –but lets the file be reset to length zero
and its file space released.
These six basic operations comprise the minimal set of requried file operations. other
common operations include appending new information to the end of an existing file and
renaming an existing file.
12. Opening a file: It is the common operation performed on the file. Once the file is created, it
must be opened before performing the file processing operations. When the user wants to open
a file, it tells the operating system to invoke the open system call and passes the file name to
the file system.
Renaming a file: This operation is used to rename the existing file.
Deleting files: To delete a file, first of all, search the directory for the named file, then
release the file space and erase the directory entry.
Appending a file: This operation adds data to the end of the file.
Closing a file: When the processing of the file is complete, it should be closed so that all
the changes made permanent and all the resources occupied should be released. In
closing, it deallocates all the internal descriptors that were created when the file was
opened.
13. In summary ,several pieces of information are associated with an open file.
File pointer : On systems that do not include a file offset as part of the read () and write ()
system calls, the system must track the last read write location as a current file position
pointer. This pointer is unique to each process operating on the file and therefore must be
kept separate from the on-disk file attributes.
File-Open Count: As file are closed, the operating system must reuse its open-file table
entries, or it could run out of space in the table. Multiple processes may have opened a file.
And the system must wait for the last file to close before removing the open-file table entry.
The file-open count tracts the number of opens and close and reaches zero on the last close.
The system can then remove the entry.
14. Disk location of the file: Most file operations require the system to modify data within the
file. The information needed to locate the file on disk is kept in memory so that the system
does not have to read it from disk for each operation.
Access rights: Each process opens a file in an access mode. This information is stored on
the per-process table so the operating system can allow or deny subsequent I/O requests.
some operating system provide facilities for locking an open file .
The various operations can be performed on a file like reading, writing, opening, closing,
etc. These operations are called file operations.
The user performs file operations with the help of commands provided by the operating
system.
The lock() method of the filechannel is used to acquire the lock.
15.
16. File types:
When we design a file system –indeed, an entrie operating system we always consider
whether the operating system should recognize and support file types.
If an operating system recognizes the type of a file it can then operate file types.
File type refers to the ability of the operating system to distinguish different types of
file such as text files source files and binary files etc. Many operating systems support
many types of files.
It refers to the ability of the operating system to differentiate various types of files like
text files, binary, and source files.
However, Operating systems like MS_DOS and UNIX has the following type of files.
A common technique for implementing file types is to include the type as part of the file
name.
17. The system uses the extension to indicate the type of the file and the type of operations that can
be done on that file.
Only a file with a.com, .exe, or. sh extension can be executed for instance.
The .com and .exe files are two forms of binary executable files , whereas the .sh file is a shell
script() containing in ASCII format, commands to the operating system.
Application program also use extensions to indicate files types in which they are interested.
18.
19. File structure:
A File Structure should be according to a required format that the operating system can
understand.
•A file has a certain defined structure according to its type.
•A text file is a sequence of characters organized into lines.
•A source file is a sequence of procedures and functions.
•An object file is a sequence of bytes organized into blocks that are understandable by
the machine.
•When operating system defines different file structures, it also contains the code to
support these file structure. Unix, MS-DOS support minimum number of file structure.
20. • File System provide efficient access to the disk by allowing data to be stored,
located and retrieved in a convenient way.
• A file System must be able to store the file, locate the file and retrieve the file.
• Most of the Operating Systems use layering approach for every task including file
systems. Every layer of the file system is responsible for some activities.
• When an application program asks for a file, the first request is directed to the
logical file system.
• The logical file system contains the Meta data of the file and directory structure.
• If the application program doesn't have the required permissions of the file then
this layer will throw an error. Logical file systems also verify the path to the file.
21. • Generally, files are divided into various logical blocks.
• Files are to be stored in the hard disk and to be retrieved from the hard disk. Hard disk
is divided into various tracks and sectors.
• Therefore, in order to store and retrieve the files, the logical blocks need to be mapped
to physical blocks.
• This mapping is done by File organization module. It is also responsible for free space
manage men.
• Once File organization module decided which physical block the application program
needs, it passes this information to basic file system.
• The basic file system is responsible for issuing the commands to I/O control in order to
fetch those blocks.
22. • A data structure is a specialized format for organizing, processing, retrieving
and storing data.
• There are several basic and advanced types of data structures, all designed to
arrange data to suit a specific purpose.
• Data structures make it easy for users to access and work with the data they
need in appropriate ways.
• A file has a certain defined structure according to its type.
• A text file is a sequence of characters organized into lines.
• A source file is a sequence of procedures and functions.
• An object file is a sequence of bytes organized into blocks that are
understandable by the machine.
23. Internal File Structure:
Internally , locating an offset within a file can be complicated for the operating
system.
Disk system typically have a well - defined block size determined by the size of a
sector.
All disk I/O is performed in units of one block and all blocks are the same size.
It is unlikely the physical record size will exactly match the length of the desired
logical record.
Logical records may even vary in length . Packing a number of logical records into
physical blocks is a common solution to this problem.
24. For example ,the UNIX operating system defines all files to simply streams of
bytes.
Each byte is individually addressable by its offset from the beginning and end of
the file.
In this case , the logical records size is 1byte.The file system automatically packs
and unpacks bytes into physical disk blocks 512 bytes per blocks as necessary.
The logical records size , physical block size and packing technique determine how
many logical records are in each physical blocks.
The packing can be done either by the user’s application program or by the
operating system .
In either case , the file may be considered a sequence of blocks.
25. Current position
beginning
end
rewind Read or write
Because disk space is always allocated in blocks , some portion of the last blocks of each
file is generally wasted.
If each block 512 bytes, for example , then a file of 1,949 bytes would be allocated four
blocks.
Sequential access file