Nothing Special   »   [go: up one dir, main page]

6.1 File-Management

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Operating System

By
Mr. Parag R. Sali
Lecturer
Department of Computer Technology
SNJB’s Shri. Hiralal Hastimal ( Jain Brothers)
Polytechnic, Chandwad
Program Name : Computer Engineering Group
Program Code : CO/CM/IF/CW
Semester : Fifth
Course Title : Operating System
Course Code : 22516

6 File Management
File Concept
Computers can store information on various storage media, such as magnetic
disks, magnetic tapes, and optical disks. So that the computer system will be
convenient to use, the operating system provides a uniform logical view of
stored information. The operating system abstracts from the physical
properties of its storage devices to define a logical storage unit, the file. Files
are mapped by the operating system onto physical devices. These storage
devices are usually nonvolatile, so the contents are persistent between
system reboots.
The information in a file is defined by its creator. Many different types of
information may be stored in a file—source or executable programs, numeric or
text data, photos, music, video, and so on. A file has a certain defined structure,
which depends on its type.

A text file is a sequence of characters organized into lines (and possibly pages).

A source file is a sequence of functions, each of which is further organized as


declarations followed by executable statements.

An executable file is a series of code sections that the loader can bring into
memory and execute.
1 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 systems
differentiate between uppercase and lowercase characters in names, whereas
other systems do not. When a file is named, it becomes independent of the
process, the user, and even the system that created it.

For instance, one user might create the file example.c, and another user might
edit that file by specifying its name. The file’s owner might write the file to a USB
disk, send it as an e-mail attachment, or copy it across a network, and it could
still be called example .c on the destination system.
A file’s attributes vary from one operating system to another but typically consist
of these:
• Name. The symbolic file name is the only information kept in human readable
form.
• Identifier. This unique tag, usually 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 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.
• Time, date, 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.

Some newer file systems also support extended file attributes, including
character encoding of the file and security features such as a file checksum.
2 File Operations
A file is an abstract data type. To define a file properly, we need to consider the
operations that can be performed on files. The operating system can provide
system calls to create, write, read, reposition, delete, and truncate files. Let’s
examine what the operating system must do to perform each of these six basic
file operations.
• Creating a file. Two steps are necessary to create a file. First, space in the file
system must be found for the file. Second, an entry for the new file must be
made in the directory.
• Writing a file. To write a file, we make a system call specifying both the name
of the file and the information to be written to 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. The write pointer must be updated whenever a write occurs.
• Reading a file. To read from a file, we use a system call that specifies the
name of the file and where (in memory) the next block of the file should be
put. Again, the directory is searched for the associated entry, and the system
needs to keep a read pointer to the location in the file where the next read
is to take place. 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 currentfile-
position pointer. Both the read and write operations use this same pointer,
saving space and reducing system complexity.
• 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 known 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 delete the file and then recreate it,
this function allows 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 required file operations.
11.1.3 File Types
A common technique for implementing file types is to include the type as part of
the file name. The name is split into two parts—a name and an extension, usually
separated by a period (Figure 6.1). In this way, the user and the operating system
can tell from the name alone what the type of a file is. Most operating systems
allow users to specify a file name as a sequence of characters followed by a period
and terminated by an extension made up of additional characters. Examples
include resume.docx, server.c, and ReaderThread.cpp.
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 programs also use extensions to indicate file types in which
they are interested.

For example,
Java compilers expect source files to have a .java extension, and the Microsoft
Word word processor expects its files to end with a .doc or .docx extension.
4 File Structure

File types also can be used to indicate the internal structure of the file. As
mentioned in Section 11.1.3, source and object files have structures that match
the expectations of the programs that read them. Further, certain files must
conform to a required structure that is understood by the operating system. For
example, the operating system requires that an executable file have a specific
structure so that it can determine where in memory to load the file and what the
location of the first instruction is. Some operating systems extend this idea into a
set of system-supported file structures, with sets of special operations for
manipulating files with those structures.
For example, assume that a system supports two types of files: text files
(composed of ASCII characters separated by a carriage return and line feed) and
executable binary files. Now, if we (as users) want to define an encrypted file to
protect the contents from being read by unauthorized people, we may find
neither file type to be appropriate. The encrypted file is not ASCII text lines but
rather is (apparently) random bits. Although it may appear to be a binary file, it is
not executable. As a result, we may have to circumvent or misuse the operating
system’s file-type mechanism or abandon our encryption scheme.
Some operating systems impose (and support) a minimal number of file
structures. This approach has been adopted in UNIX, Windows, and others. UNIX
considers each file to be a sequence of 8-bit bytes; no interpretation of these bits
is made by the operating system. This scheme provides maximum flexibility but
little support. Each application program must include its own code to interpret an
input file as to the appropriate structure. However, 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.

You might also like