File Concepts: Naming, Attributes, Operations, Types and System

By | November 20, 2021

File Concept

  • A file is a logical collection of information stored on secondary storage such as hard disk.
  • Physically, a file is the smallest allotment of secondary storage device e.g., disk.
  • Logically, a file is a sequence of logical records i.e. a sequence of bits and bytes.
  • Files can be used to contain data and programs (both source and object program).
  • Data files can be numeric, alphabetic, alphanumeric or binary.
  • A file has various attributes like name, type, location, size, protection, time and date of creation etc.

File Naming

  • A file can be given a name for the convenience of its use by its creator.
  • A name is attached to every file so as to uniquely identify it and access it through its name.
  • The exact rules for naming file vary from system to system but all the operating systems allow string of one to eight letters as legal file name.
  • Digits and few special characters are also allowed in file names.
  • Some systems differentiate between uppercase and lower case characters in names, whereas other systems consider the two cases equivalent.
  • For example, UNIX differentiates uppercase letters from the lowercase whereas MS-DOS does not.
  • Thus in UNIX, files-HELLO, hello, Hello and HEllo are different whereas in MS-Do they all represent same file.

File attributes

  • File attributes are required by file management system to manage a file.
  • Few attributes are accessible for users, such as access privileges, name, or size of a file whereas some of them are specifically assigned to file for file system usage.
  • File attributes vary from one operating system to other.
  • No existing system has all of these, but each one is present in some system.
  • The first four attributes shown in table are related to file protection and tell who may access it and who may not.

The flags are bits or short fields that enable or control some specific property:

  1. Hidden flag: Hidden files do not appear in the listing of a file.
  2. Archive flag: Archive flag bit keeps track of whether the file has been backed up.
  3. Temporary flag: This flag allows a file to be marked for automatic deletion when the process that created it terminates.

Some possible file attributes are:

Field Meaning
Protection Who can access a file and in what way (reading, writing, executing).
Password Password needed to access a file. 
Creator Id of a person who created a file. 
Owner Current owner of a file. 
Read-only flag 0 for read/write, 1 for read only.
Hidden flag 0 for normal, 1 for do not display in listings
System flag 0 for normal file, 1 for system file. 
Archive flag 0 has been backed up, 1 for needs to be backed up. 
 ASCII/Binary flag 0 for ASCII file, 1 for binary file 
Random access flag 0 for sequential access only, 1 for random access.
 Temporary flag 0 for normal, 1 for delete on process exit. 
Lock flag 0 for unlocked, non zero for locked. 
 Creation time Date & time of file was created.
 Time of last access Date & time file was last accessed. 
 Time of last change Date & time file was last changed
Current size Number of bytes in file. 
Maximum size Maximum size file may grow to
  • The various times keep tract of when the file was created, most recently used and most recently modifies. 
  • The current size attribute tells how big a file is at present.
  • The maximum size attribute tells the maximum amount of storage reserved for a file in advance. It is used for mainframe operating systems and not in minicomputers and personal computer systems.

File Operations

In  order to store and retrieve the contents of a file, the user manipulates it using various operations or commands. These operations vary from system to system.

Some of the commonly used operations are :

1. CREATE: Create command creates a file with no data. Two steps are involved in creating a file :

(a) First space is allocated to a file in a file system.

(b) Second, an entry for the new file is made in the directory. Thus, a directory entry records the name of the file and its location in the file system.

2. DELETE: When a file is no longer needed, it has to be deleted to free up disk space. There is always a system call for this purpose. In addition, some operating systems automatically delete any file that has not been used for n days. 

3. OPEN: A process must open a file before using it. Operating system opens a file from its location and loads it into the memory for access by the user. File can be opened implicitly by the system or explicitly by user. 

4. CLOSE: When all the accesses are finished, file must be closed in order to store the changes made by different processes permanently and to free up internal table space. Many systems encourage this by imposing a maximum number of open files on processes. 

5. READ: To read from a file, a system call can be issued specifying the name of the file and the address of memory block where the reading has to take place. Files can be read sequentially or randomly. Once the read has taken place, the read pointer is updated. 

6. WRITE: To write into a file, a system call can be issued specifying both the name of the file and the information to be written to the file. The write operation starts from the current location of the file pointer, usually, it starts after the last record. If the current position is the end of the file, the file’s size increases. If the current position Is in the middle of the file, existing data are overwritten and lost forever. 

7. APPEND: This call is restricted form of WRITE, It can only add data to the end of the file.

8. RENAME: It can be used to change the name of any existing file.

9. COPY: It is used to copy the contents of the file into some other file or create another version of file with new name

10. SEEK: For random access files, a method is needed to specify from where to take the data. For this purpose SEEK system call can be used. It repositions the pointer from the current position to a specific place in the file. After this call has completed, data can be read from or written to that position. 

11. TRUNCATE: The user can erase the contents of a file but can keep its attributes This operation allows all the attributes to remain unchanged except for file length. Thus the file’s length is reset to 0 and its space is released.

File Concepts: Naming, Attributes, Operations, Types and System

File Types

In order to support different types of files, operating systems support two part file names. The two parts are : name and an extension. Both are separated by a period (dot). For example, a name of a file can be program. C. In this way, the user and the operating system can tell from the name alone what the type of file is. In MS-DOS, for example, file names are 1 to 8 characters and extension is of 1 to 3 characters. Thus an extension is used to indicate the type of the file and the type of operations that can be done on that file.

Following table shows the various file type, their extension and meaning:

File Type Extension Meaning
Executable file  .exe, .com, .bin  read to run machine language program
Object file .obj, .o  compiled, machine language but not linked. 
Source code file  .java, .c, .cc, .pas, .asm, .a, .ftn represents source code in different languages such as c, java, pascal, assembly language or fortran. 
Batch file  .bat, .sh command to the command interpreter 
  Text file .txt, .doc textual data or documentation.
Library file  .lib, .dll libraries of routines for programmers 
 Backup file .bak used for taking backup of some program file 
 Multimedia file  .mpeg, .mov, .rm  binary file containing audio or audio/video information.

File System

File system is a part of operating system responsible for controlling secondary storage space. File system generally contains the following:

  1. Access methods: These are concerned with the manner in which data stored in files is accessed. 
  2. File management: It is concerned with providing mechanisms for files to be stored, referenced, shared and secured. 
  3. Auxiliary storage management: It is concerned with allocating space for files on secondary storage devices.
  4. File integrity mechanisms: These are concerned with guaranteeing that the information in a file is uncorrupted.

The various functions of file system are :

  1. It enables users to give user defined names, to create, to modify and delete files.
  2. It provides a uniform logical view of data to users rather than physical view i.e. internal structure by giving user friendly interface. 
  3. It enables users to structure their files in a way most appropriate for each application. 
  4. It controls the transferring of data blocks between secondary storage and main memory and also between different files.
  5. It provides semantics or the rules for file sharing among multiple processes and users.
  6. It also allocates and managers space for files on secondary storage devices, such as disks or magnetic tapes. Space management is an important part of file system.
  7. It protects the files from system failures and applies measures for recovery and backup.
  8. It provides security measures for confidential data such as electronic funds or criminal records. 
  9. It also provides encryption and decryption facilities to the users.