You are on page 1of 15

File Concepts

BY

S I N D H U J A A K – 2 0 PA 2 2

S H I N D H U – 2 0 PA 2 2
What is File ?
A file is a collection of related information (Logically related entities) that
is stored on secondary storage.it is a sequence of bits, bytes, lines, or records, the
meaning of which is defined by the file’s creator and user.

File System:-
File system is the most visible aspect. which is provides the on-line storage
and access to both dada and programs of the OS and all the users of the
computer system.
It consists three part:-
 Files (storing related data)
 directory structure (which organizes the files )
 Partitions (separate physically or logically large collection of directories)
Types of files:-
A file has a certain defined structure, which depends on its type.
DataFile – It may be numeric, alphabetic ,alphanumeric or binary. files may
be free form, such as text files.
TextFile – It is a Sequence of characters organized into lines.
SourceFile – It is a subroutines and functions, each of which is further
organized as declarations followed by executable statements.
ObjectFile – It is a sequence of bytes organized into blocks understandable by
the systems linker
ExecutableFile – It is a series of code sections that the loader can bring into
memory and execute.
File Attributes:-
When a file is named it becomes independently of the process, it varies from one
operating system to another but it consists of the following,
Name - The symbolic file name is the only information kept in humanreadable
form.
Identifie - This unique tag, usually a number, identifies the file within the
file system;( non-human-readable )
Type - This information is needed for systems 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 file (in bytes, words, or blocks) and possibly
the maximum allowed size are included in this attribute.
Protection - Access-control information determines who can do reading,
writing, executing, and so on.
Timestamps and user identification - This information may be kept for
creation, last modification, and last use. These data can be useful for protection,
security, and usage monitoring.

File Operations:-
A file is an abstract data type. The operating system can provide system calls to
create, write, read, reposition, delete, and truncate files.
The following seven basic file operations are performed by the OS,
Creating a File:-
Two steps,
 Space in file system must be found for the file.
 An Entry for new file must be made in the directory.
Writing a File:-
To write a file, system call are made specifying both
 The name of the file and,
 The information to be written to the file.
The system must keep a write pointer to the location in the file where the next
write is to take place if it is sequential. The write pointer must be updated.
whenever a write occurs.
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
involves any actual I/O. this file operation is also known as a File Seek.
Reading a file :-
To read from a file, we use a system call that specifies the file handle and where
(in memory) the next block of the file should be put. Again, the system needs to keep
a read pointer to the location in the file where the next read is to take place, if
sequential. Once the read has taken place, the read pointer is updated. Because a
process is usually either reading from or writing to a file, the current operation
location can be kept as a per-process current-file-position pointer. Both the read and
write operations use this same pointer, saving space and reducing system complexity.
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 or mark as free the directory entry. Note that some systems allow
hard links—multiple names (directory entries) for the same file. In this case the
actual file contents is not deleted until the last link is deleted.
Truncating a file :-
The user may want to erase the contents of a file but keep its attributes. Rather
than forcing the user to delete the file and then recreate it, this function allows all
attributes to remain unchanged—except for file length. The file can then be reset to
length zero, and its file space can be released.
Opening a file:-
Rather than have all file operations specify a file name, causing the operating
system to evaluate the name, check access permissions, and so on, all operations
except create and delete require a file open() first. If successful, the open call returns
a file handle that is used as an argument in the other calls.
File Types:-
 When we design a file system, we must ensure whether the operating
system support the file type. Then only we can operate the file in
reasonable ways.
 operating systems allow users to specify a file name. the name is
split into two parts : a name (sequence of characters) followed by
period and terminated by an extension(type).
 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.
 .com and .exe - Binary executable files.
 .sh - Containing shell script in ASCII format, commands to the
operating system.
In macOS ,the application files has .app extension.
creator attribute is set by the Os when create() call.
A file produced by a word processor has the word processor’s name as its
creator. When the user opens that file, by double-clicking the mouse on the icon
representing the file, the word processor is invoked automatically, and the file is
loaded, ready to be edited.
The UNIX system uses a magic number stored at the beginning of some binary
files to indicate the type of data in the file.
File Structure:-
 All type of files have some specific structure for operating system
understanding.

 Before run a file, we must ensure the type of the is supported by the Os.

 Each application program must include its own code to interpret an input file
as to the appropriate structure. all operating systems must support at least
one structure, that of an executable file, so that the system is able to load and
run programs.
Internal File Structure:-
 Disk systems typically have a well-defined block size determined by the size
of a sector, and all blocks are the same size.
 If each block were 512 bytes, for example, then a file of 1,949 bytes would
be allocated four blocks (2,048 bytes); the last 99 bytes would be wasted.
 It will cause internal fragmentation.
Thank You

You might also like