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/   1
File Attributes

-   Name

-   Type

-   Location

-   Size

-   Protection

-   Time, Date and User Identification




                 http://raj-os.blogspot.in/   2
File Attributes

Name

  -    Given by the user

  -    Only information that is kept in human readable form

Type

         -   Information required by systems that support different
         types




                             http://raj-os.blogspot.in/               3
File attributes

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

                         http://raj-os.blogspot.in/   4
File Attributes

Protection

      -   Access control information

          ( read, write and execute privileges )




                          http://raj-os.blogspot.in/   5
File Attributes

Time, date and user identification

      -       Creation

      -       Last modification

      -       Last use

  (Useful for protection, security and usage monitoring )




                         http://raj-os.blogspot.in/         6
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/   7
Basic File Operations


1. Creating a file


  •    Allocation of space for the file in the file system


  •    Making an entry for the new file in the directory




                          http://raj-os.blogspot.in/         8
Basic File Operations

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

                        http://raj-os.blogspot.in/   9
Basic File Operations
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



                          http://raj-os.blogspot.in/     10
Basic File Operations


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




                          http://raj-os.blogspot.in/   11
Basic File Operations


5.Deleting a file

•   Search the directory for the named file

•   Release all file space


•   Erase the directory entry




                             http://raj-os.blogspot.in/   12
Basic File Operations

6. Truncating a file

• File contents erased

• Name and attributes of file unchanged




                         http://raj-os.blogspot.in/   13
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/     14
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/      15
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/         16
Other Desirable Operations


Most file operations involve searching the directory for the

entry associated with the named file




                       http://raj-os.blogspot.in/         17
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/    18
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/               19
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/                20
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/              21
File Type             Usual extension                           Function

Executable      Exe, com, bin or none                   Ready to run machine
                                                        language 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            Wp, tex, rrf etc                        Various word processor
Processor                                               formats
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/                                    22
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/             23
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/         24
File Type

To implement file types, include the type as part of
the file name
For Ex : letters , documents




                   http://raj-os.blogspot.in/      25
File Type


The file name is split into two parts

      -      a name

      -      an extension




                       http://raj-os.blogspot.in/   26
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/      27
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/       28
Summary
In this class, you have learnt
- file concept
- Understand file operations
- Know various file types




                       http://raj-os.blogspot.in/   29

File management53(1)

  • 1.
    File Management Organization ofdata - 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/ 1
  • 2.
    File Attributes - Name - Type - Location - Size - Protection - Time, Date and User Identification http://raj-os.blogspot.in/ 2
  • 3.
    File Attributes Name - Given by the user - Only information that is kept in human readable form Type - Information required by systems that support different types http://raj-os.blogspot.in/ 3
  • 4.
    File attributes 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 http://raj-os.blogspot.in/ 4
  • 5.
    File Attributes Protection - Access control information ( read, write and execute privileges ) http://raj-os.blogspot.in/ 5
  • 6.
    File Attributes Time, dateand user identification - Creation - Last modification - Last use (Useful for protection, security and usage monitoring ) http://raj-os.blogspot.in/ 6
  • 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/ 7
  • 8.
    Basic File Operations 1.Creating a file • Allocation of space for the file in the file system • Making an entry for the new file in the directory http://raj-os.blogspot.in/ 8
  • 9.
    Basic File Operations 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 http://raj-os.blogspot.in/ 9
  • 10.
    Basic File Operations 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 http://raj-os.blogspot.in/ 10
  • 11.
    Basic File Operations 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 http://raj-os.blogspot.in/ 11
  • 12.
    Basic File Operations 5.Deletinga file • Search the directory for the named file • Release all file space • Erase the directory entry http://raj-os.blogspot.in/ 12
  • 13.
    Basic File Operations 6.Truncating a file • File contents erased • Name and attributes of file unchanged http://raj-os.blogspot.in/ 13
  • 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/ 14
  • 15.
    Basic file operationscan 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/ 15
  • 16.
    Other Desirable Operations Allowthe 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/ 16
  • 17.
    Other Desirable Operations Mostfile operations involve searching the directory for the entry associated with the named file http://raj-os.blogspot.in/ 17
  • 18.
    To Avoid ConstantSearching • 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/ 18
  • 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/ 19
  • 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/ 20
  • 21.
    Other File Operations Mostsystems 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/ 21
  • 22.
    File Type Usual extension Function Executable Exe, com, bin or none Ready to run machine language 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 Wp, tex, rrf etc Various word processor Processor formats 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/ 22
  • 23.
    File Type One majorconsideration 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/ 23
  • 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/ 24
  • 25.
    File Type To implementfile types, include the type as part of the file name For Ex : letters , documents http://raj-os.blogspot.in/ 25
  • 26.
    File Type The filename is split into two parts - a name - an extension http://raj-os.blogspot.in/ 26
  • 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/ 27
  • 28.
    File Type The extensiontells 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/ 28
  • 29.
    Summary In this class,you have learnt - file concept - Understand file operations - Know various file types http://raj-os.blogspot.in/ 29