http://raj-os.blogspot.in/ 1
File Management Organization of data
- Creating a file
- Storing a file in required directory
- Removing a file
- Opening a file
- Closing a file
- Maintaining of file details
- Name, Type, location, size , date and time of creation or modification
- File Protection
http://raj-os.blogspot.in/ 2
File Attributes
- Name
- Type
- Location
- Size
- Protection
- Time, Date and User Identification
http://raj-os.blogspot.in/ 3
Name
- Given by the user
- Only information that is kept in human readable form
Type
- Information required by systems that support different
types
File Attributes
http://raj-os.blogspot.in/ 4
Location
- A pointer to a device and to the
location of the file on that device
Size
- Current size of file (in bytes or words )
- Max size allowed
File attributes
http://raj-os.blogspot.in/ 5
Protection
- Access control information
( read, write and execute privileges )
File Attributes
http://raj-os.blogspot.in/ 6
Time, date and user identification
- Creation
- Last modification
- Last use
(Useful for protection, security and usage monitoring )
File Attributes
http://raj-os.blogspot.in/ 7
Basic File Operations ( Minimal Set )
1. Creating a file
2. Repositioning within a file
3. Deleting a file
4. Truncating a file
5. Reading a file
6. Writing a file
http://raj-os.blogspot.in/ 8
1. Creating a file
• Allocation of space for the file in the file system
• Making an entry for the new file in the directory
Basic File Operations
http://raj-os.blogspot.in/ 9
2. Writing a file
• Use a system call specifying
- Name of the file
- Information to be written
• Search directory for the associated entry
• Keep a write pointer
• Update write pointer after every write
Basic File Operations
http://raj-os.blogspot.in/ 10
3. Reading a file
• Use a system call specifying
- Name of the file
- Address where to put the contents read
• Search directory for the associated entry
• Keep a read pointer
• Update read pointer after every read
Basic File Operations
http://raj-os.blogspot.in/ 11
4. Repositioning within a file
• Also known as file seek operation
• Search directory for the appropriate entry
• Set current-file-position to a given value
Basic File Operations
http://raj-os.blogspot.in/ 12
5.Deleting a file
• Search the directory for the named file
• Release all file space
• Erase the directory entry
Basic File Operations
http://raj-os.blogspot.in/ 13
6. Truncating a file
• File contents erased
• Name and attributes of file unchanged
Basic File Operations
http://raj-os.blogspot.in/ 14
Other File Operations• Appending
• Renaming
Appending
Add some information at the end of the file
Renaming Name of file changed
All other attributes unchanged
http://raj-os.blogspot.in/ 15
Basic file operations can be combined to implement other
operations
Ex : Creating a copy of a file
- Create a new file
- Read from old file
- Write to new file
http://raj-os.blogspot.in/ 16
Other Desirable Operations
Allow the user to get and set the various attributes of a file
Ex : i) get the file length
ii) set file attributes like file’s owner
http://raj-os.blogspot.in/ 17
Other Desirable Operations
Most file operations involve searching the directory for the
entry associated with the named file
http://raj-os.blogspot.in/ 18
To Avoid Constant Searching
• Many systems open a file when file first is used
• The operating system keeps a small table called the
Open file table
• Open file table contains information about open files
• When a file operation is requested, an index into the
open file table is used
http://raj-os.blogspot.in/ 19
Other File Operations
When a file is no longer actively used, it is closed by
the process and the O.S. removes its entry in the
Open file table
http://raj-os.blogspot.in/ 20
Other File Operations
• Some systems implicitly open a file when it is first referenced
• Close it automatically when the program that opened the file
terminates
http://raj-os.blogspot.in/ 21
Other File Operations
Most systems require that a file be opened explicitly by the
programmer with a system call ( open ) before that file can be
used
http://raj-os.blogspot.in/ 22
File Type Usual extension Function
Executable Exe, com, bin or none Ready to run machinelanguage program
Object obj, o Compiled, machine language, not linked
Source code c, p, pas, f77, asm, a Source code in various languages
Batch bat, sh Commands to the command interpreter
Text txt, doc textual data,documents
Word Processor
Wp, tex, rrf etc Various word processorformats
Library Lib, a Libraries of routines
Print or view ps, dvi, gif ASCII or binary file in a format for printing or viewing
Archive arc, zip, tar Related group of files for archiving or storage
Fig : Common File Types
http://raj-os.blogspot.in/ 23
File Type
One major consideration in designing a file system, and the
entire operating system, is whether the operating system should
recognize and support file types
http://raj-os.blogspot.in/ 24
File Type
• If the operating system recognizes the type of a file
• it can then operate on the file in reasonable ways
• Ex : An attempt to print a binary-object form of a
program file can be prevented
http://raj-os.blogspot.in/ 25
File Type
To implement file types, include the type as part of
the file name
For Ex : letters , documents
http://raj-os.blogspot.in/ 26
File Type
The file name is split into two parts
- a name
- an extension
http://raj-os.blogspot.in/ 27
File Type
• The file name is usually separated from the
extension by a period ( dot ) character
Ex : paycalc. cpp
• The name can consists up to 8 characters followed
by a period
http://raj-os.blogspot.in/ 28
File Type
The extension tells what the file type is
• Extension can be up to 3 characters
• System uses the extension to indicate the type of the
file
• Type of operations that can be done on that file
For ex : .com , .exe & .bat extension are executable
file
http://raj-os.blogspot.in/ 29
Summary In this class, you have learnt - file concept
- Understand file operations
- Know various file types