Sie sind auf Seite 1von 30

Introduction to Linux

File System
Each node is either a file or a directory of files,
where the later can contain other files and
directories.
You specify a file or directory by its path name,
either the full, or absolute, path name or the one
relative to a location.
The full path name starts with the root, /, and
follows the branches of the file system, each
separated by /, until you reach the desired file
Introduction to Linux

Directories, Files and Inodes


Every directory and file is listed in its parent
directory.
In the case of the root directory, that parent is itself.
A directory is a file that contains a table listing the
files contained within it, giving file names to the
inode numbers in the list.
The information about all the files and directories is
maintained in INODE TABLE
An Inode (Index Nodes) is an entry in the table
containing information about a file (metadata)
including file permissions, size, time
stamp, pointers to files data blocks on the disk etc.
Introduction to Linux
Users, Groups and Access
Permissions
In UNIX/LINUX, there is a concept of user and an
associated group

The system determines whether or not a user or


group can access a file or program based on the
permissions assigned to them.

Apart from all the users, there is a special user


called Super User or the root which has permission
to access any file and directory
Introduction to Linux

Access Permissions
There are three permissions for any file, directory
or application program.

The following lists the symbols used to denote


each, along with a brief description:

r — Indicates that a given category of user can


read a file.

w — Indicates that a given category of user can


write to a file.

x — Indicates that a given category of user can


execute the file.
Introduction to Linux

Access Permissions
Each of the three permissions are assigned to
three defined categories of users.
The categories are:

owner — The owner of the file or


application.
group — The group that owns the file or
application.
others — All users with access to the
system.
Introduction to Linux

Access Permissions
One can easily view the permissions for a file by
invoking a long format listing using the command
ls -l.

For instance, if the user juan creates an executable


file named test, the output of the command ls -l test
would look like this:

-rwxrwxr-x juan student Sep 26 12:25 test


Introduction to Linux

Access Permissions
The permissions for this file are listed are listed at
the start of the line, starting with rwx.

This first set of symbols define owner access.

The next set of rwx symbols define group access

The last set of symbols defining access permitted


for all other users.
Introduction to Linux

Files
A file is a collection of related data stored as a
named unit on the secondary storage.

It can store different types of data such as text,


graphics, database, executable code, sound,
videos etc.

The structure of a file is based on the type of the


file. E.g: a graphic file is an organized collection of
pixels, a database file is a collection of table and
records, and a batch file is a collection of
commands.
Attributes of a File
 Name – only information kept in human-readable form
• Identifier – unique tag (number) identifies file within file
system
• Type – needed for systems that support different types
• Location – pointer to file location on device
• Size – current file size
• Location – A pointer that stores location of file on
device.
• Protection – controls who can do reading, writing,
executing
• Time, date, and user identification – data for
protection, security, and usage monitoring
Introduction to Linux

File Operations
Create file

Open file

Write to file

Read a file

Seek file

Close file

Delete file

Append file

Rename file
Introduction to Linux

File types
File type Extension Meaning
Archive Arc, zip, tar related file compressed and grouped
together into single file for storage

Batch Bat,sh An executable file stores a series of


commands that can be executed with a
single command

Backup file Bak,bkf Stores a copy of the data on the disk,


used for recovering from a system
crash.
Introduction to Linux

File type Extension Meaning

Executable Exe, com, bin Used to run various programs on a


computer
Library Lib, dll Stores libraries of routines for
programmers
Image Bmp, jpeg, gif, Stores images and graphics

Multimedia Mpeg,mp2,mpa Stores audio and video information

System file Inf ,ini, drv Stores system information for loading
and managing different application
Object Obj, o machine language file, precompiled

Text txt, doc Stores textual data


FILE STRUCTURE
1. BYTE SEQUENCE
2. RECORD SEQUENCE
3. TREE STURCTURE
BYTE SEQUENCE

Each file is made up of sequence of 8-bit bytes having no fixed structure.

RECORD SEQUENCE:
A file consists of a sequence of fixed-length records, where an arbitrary
number of records can be read or written to a file. The records cannot be
inserted or deleted in the middle of a file.

10: File Systems 14


TREE STRUCTURE:
a file consists of a disk blocks where each blocks holds a number of records of
varied length.

10: File Systems 15


Introduction to Linux

LINUX File System


Introduction to Linux

File System

The Linux file system looks like an inverted tree


structure.
You start with the root directory, denoted by /, at
the top and work down through sub-directories
underneath it.
FILE ACCESS
ACCESS METHODS:

• SEQUENTIAL ACCESS METHODS


• DIRECT SEQUENTIAL ACCESS METHODS
• INDEXED SEQUENTIAL ACCESS METHODS
SEQUENTIAL ACCESS

When the information in the file is accessed in order, one


record after the other, it is called sequential access. It is
the easiest file access method.

Compilers, multimedia applications, sound files and


editors are the most common examples of the programs
using sequential access.
SEQUENTIAL ACCESS
If files had only one "chunk" of data, life would be simple. But for large files,
the files themselves may contain structure, making access faster.

• Implemented by the file system.


• Data is accessed one record right after the last.
• Reads cause a pointer to be moved ahead by one.
• Writes allocate space for the record and move the pointer to the new
End Of File.
DIRECT ACCESS

The large amount of data can be stored on the disk as a storage


media.
Sequential access of this data in a normal manner would become
very lengthy and slow process.
To overcome this problem, the data on the disk is stores as blocks of
data with index numbers, thus helping to read and write data on the
disk in any order, known as random or direct access.
DIRECT ACCESS

• Method useful for disks.

• The file is viewed as a numbered sequence of blocks or records.

• There are no restrictions on which blocks are read/written in any order.

• User now says "read n" rather than "read next".

• "n" is a number relative to the beginning of file, not relative to an absolute


physical disk location.
Access
Methods
OTHER ACCESS METHODS

Built on top of direct access and often implemented by a user utility.

Indexed ID plus pointer.

An index block says what's in each remaining block or contains pointers to


blocks containing particular items. Suppose a file contains many blocks of
data arranged by name alphabetically.

Example 1: Index contains the name appearing as the first record in each block.
There are as many index entries as there are blocks.

Example 2: Index contains the block number where "A" begins, where "B" begins,
etc. Here there are only 26 index entries.
FILE SYSTEMS INTERFACE
Adams
Example 1: Index contains the
Arthur
name appearing as the first
Asher
record in each block. There are Smith, John | data
as many index entries as there
are blocks.
Smith

Adams Adams | Data


Example 2: Index contains the block Baker Arthur | Data
number where "A" begins, where Charles Asher | Data
"B" begins, etc. Here there are
Baker | Data
only 26 index entries.
Saarnin Saarnin | data

Smith, John | data


ALLOCATION METHODS:

1. CONTIGUOUS ALLOCATION
2. LINKED ALLOCATION
3. INDEXED ALLOCATION
CONTIGUOUS ALLOCATION
• Method: Lay down the entire file on contiguous sectors of the disk. Define by a
dyad <first block location, length >.

a) Accessing the file requires a minimum of


head movement.
b) Easy to calculate block location: block i of
a file, starting at disk address b, is b + i.
c) Difficulty is in finding the contiguous
space, especially for a large file. Problem
is one of dynamic allocation (first fit, best
fit, etc.) which has external fragmentation.
If many files are created/deleted,
compaction will be necessary.

• It's hard to estimate at create time what the


size of the file will ultimately be. What
happens when we want to extend the file ---
we must either terminate the owner of the file,
or try to find a bigger hole.
LINKED ALLOCATION

Each file is a linked list of disk blocks,


scattered anywhere on the disk.

At file creation time, simply tell the directory


about the file. When writing, get a free block
and write to it, enqueueing it to the file
header.

There's no external fragmentation since each


request is for one block.

Method can only be effectively used for


sequential files.

10: File Systems 28


LINKED ALLOCATION

Pointers use up space in each block.


Reliability is not high because any loss
of a pointer loses the rest of the file.

A File Allocation Table is a variation of


this.

It uses a separate disk area to hold the


links.

This method doesn't use space in data


blocks. Many pointers may remain in
memory.

A FAT file system is used by MS-DOS.


INDEXED ALLOCATION

• Each file uses an index block on disk


to contain addresses of other disk
blocks used by the file.
• When the i th block is written, the
address of a free block is placed at
the i th position in the index block.

• Method suffers from wasted space


since, for small files, most of the
index block is wasted. What is the
optimum size of an index block?

• If the index block is too small, we can:


a) Link several together
b) Use a multilevel index

Das könnte Ihnen auch gefallen