0% found this document useful (0 votes)
3 views11 pages

Unit1-Unix File System Structure-Part2

The Unix File System is a hierarchical structure that organizes files and directories, starting from a root directory denoted by '/'. It features a multi-level directory tree, supports permissions for access control, and includes various file types such as ordinary files, directories, special files, pipes, and sockets. Additionally, system calls in Unix facilitate process control, file management, device management, information maintenance, and inter-process communication.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
3 views11 pages

Unit1-Unix File System Structure-Part2

The Unix File System is a hierarchical structure that organizes files and directories, starting from a root directory denoted by '/'. It features a multi-level directory tree, supports permissions for access control, and includes various file types such as ordinary files, directories, special files, pipes, and sockets. Additionally, system calls in Unix facilitate process control, file management, device management, information maintenance, and inter-process communication.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 11

Unix File System

Structure
Unix File System is a logical method of organizing and
storing large amounts of information in a way that makes it easy
to manage.

A file is the smallest unit in which the information is stored.

Unix file system has several important features.

All data in Unix is organized into files. All files are organized into
directories. These directories are organized into a tree-like
structure called the file system.

Files in Unix System are organized into multi-level hierarchy


structure known as a directory tree.

At the very top of the file system is a directory called “root” which
is represented by a “/”. All other files are “descendants” of root.

The Unix file system is a hierarchical file system used by Unix-


based operating systems to store and organize files and directories.

It is a tree-like structure that starts with a single directory called


the root directory, which is denoted by a forward slash (/)
character.

The Unix file system uses a directory hierarchy that allows for easy
navigation and organization of files.

Directories can contain both files and other directories, and each
file or directory has a unique name.

Unix file system also uses a set of permissions to control access to


files and directories.

Each file and directory has an owner and a group associated with
it, and permissions can be set to allow or restrict access to these
entities.
One of the most important features of the Unix file system is its
support for symbolic links, which are pointers to other files or
directories.

This allows for flexible organization of files and directories without


having to physically move them around.

Overall, the Unix file system is a robust and flexible system


that has been used for decades and continues to be the foundation
for many modern operating systems.

Unix File System

Directories or Files and their Description


D
NAME ESCRIPTION

The slash / character alone denotes the root of the


/
filesystem tree.

Stands for “binaries” and contains certain fundamental


/bin utilities, such as ls or cp, which are generally needed
by all users.

Contains all the files that are required for successful


/boot
booting process.

Stands for “devices”. Contains file representations of


/dev
peripheral devices.
D
NAME ESCRIPTION

Contains system-wide configuration files and system


databases. Originally also contained “dangerous
/etc
maintenance utilities” such as init, but these have
typically been moved to /sbin or elsewhere.

/home Contains the home directories for the users.

Contains system libraries, and some critical files such


/lib
as kernel modules or device drivers.

Default mount point for removable devices, such as


/media
USB sticks, media players, etc.

Stands for “mount”. Contains filesystem mount points.


These are used, for example, if the system uses
/mnt multiple hard disks or hard disk partitions. It is also
often used for remote (network) filesystems, CD-
ROM/DVD drives, and so on.

procfs virtual filesystem showing information about


/proc
processes as files.

The home directory for the superuser “root” – that is,


the system administrator. This account’s home
directory is usually on the initial filesystem, and hence
not in /home (which may be a mount point for another
/root filesystem) in case specific maintenance needs to be
performed, during which other filesystems are not
available. Such a case could occur, for example, if a
hard disk drive suffers physical failures and cannot be
properly mounted.

A place for temporary files. Many systems clear this


directory upon startup; it might have tmpfs mounted
/tmp atop it, in which case its contents do not survive a
reboot, or it might be explicitly cleared by a startup
script at boot time.

/usr Originally the directory holding user home


D
NAME ESCRIPTION

directories,its use has changed. It now holds


executables, libraries, and shared resources that are
not system critical, like the X Window System, KDE,
Perl, etc. However, on some Unix systems, some user
accounts may still have a home directory that is a
direct subdirectory of /usr, such as the default as in
Minix. (on modern systems, these user accounts are
often related to server or system use, and not directly
used by a person).

This directory stores all binary programs distributed


with the operating system not residing in /bin, /sbin or
/usr/bin (rarely) /etc.

Stores the development headers used throughout the


/usr/ system. Header files are mostly used by
include the #include directive in C/C++ programming
language.

Stores the required libraries and data files for


/usr/lib
programs stored within /usr or elsewhere.

A short for “variable.” A place for files that may


/var change often – especially in size, for example e-mail
sent to users on the system, or process-ID lock files.

/var/log Contains system log files.

The place where all the incoming mails are stored.


Users (other than root) can access their own mail only.
/var/mail
Often, this directory is a symbolic link to
/var/spool/mail.

/var/ Spool directory. Contains print jobs, mail spools and


spool other queued tasks.

A place for temporary files which should be preserved


/var/tmp
between system reboots.
Types of Unix Files
The UNIX files system contains several different types

of files
Ordinary Files
An ordinary file is a file on the system that contains data, text, or
program instructions.
 Used to store your information, such as some text you have
written or an image you have drawn. This is the type of file
that you usually work with.
 Always located within/under a directory file.
 Do not contain other files.
 In long-format output of ls -l, this type of file is specified by
the “-” symbol.
Directories
Directories store both special and ordinary files. For users familiar
with Windows or Mac OS, UNIX directories are equivalent to folders.
A directory file contains an entry for every file and subdirectory
that it houses. If you have 10 files in a directory, there will be 10
entries in the directory. Each entry has two components. (1) The
Filename (2) A unique identification number for the file or directory
(called the inode number)
 Branching points in the hierarchical tree.
 Used to organize groups of files.
 May contain ordinary files, special files or other directories.
 Never contain “real” information which you would work
with (such as text). Basically, just used for organizing files.
 All files are descendants of the root directory, ( named / )
located at the top of the tree.
In long-format output of ls –l , this type of file is specified by the “d”
symbol.
Special Files
Used to represent a real physical device such as a printer, tape
drive or terminal, used for Input/Output (I/O) operations. Device or
special files are used for device Input/Output(I/O) on UNIX and
Linux systems. They appear in a file system just like an ordinary file
or a directory. On UNIX systems there are two flavors of special
files for each device, character special files and block special files :
 When a character special file is used for device
Input/Output(I/O), data is transferred one character at a
time. This type of access is called raw device access.
 When a block special file is used for device
Input/Output(I/O), data is transferred in large fixed-size
blocks. This type of access is called block device access.
For terminal devices, it’s one character at a time. For disk devices
though, raw access means reading or writing in whole chunks of
data – blocks, which are native to your disk.
 In long-format output of ls -l, character special files are
marked by the “c” symbol.
 In long-format output of ls -l, block special files are marked
by the “b” symbol.
Pipes
UNIX allows you to link commands together using a pipe. The pipe
acts a temporary file which only exists to hold data from one
command until it is read by another.
A Unix pipe provides a one-way flow of data. The output or result of
the first command sequence is used as the input to the second
command sequence. To make a pipe, put a vertical bar (|) on the
command line between two commands.For example: who | wc -l In
long-format output of ls –l , named pipes are marked by the “p”
symbol.

Sockets
A Unix socket (or Inter-process communication socket) is a
special file which allows for advanced inter-process
communication.

A Unix Socket is used in a client-server application framework. In


essence, it is a stream of data, very similar to network stream (and
network sockets), but all the transactions are local to the
filesystem. In long-format output of ls -l, Unix sockets are marked
by “s” symbol.
Symbolic Link
Symbolic link is used for referencing some other file of the file
system.

Symbolic link is also known as Soft link. It contains a text form of


the path to the file it references. To an end user, symbolic link will
appear to have its own name, but when you try reading or writing
data to this file, it will instead reference these operations to the file
it points to. If we delete the soft link itself , the data file would still
be there.If we delete the source file or move it to a different
location, symbolic file will not function properly. In long-format
output of ls –l , Symbolic link are marked by the “l” symbol (that’s a
lower case L).
Advantages and Disadvantages
Advantages of the Unix file System
 Hierarchical organization: The hierarchical structure of
the Unix file system makes it easy to organize and navigate
files and directories.
 Robustness: The Unix file system is known for its stability
and reliability. It can handle large amounts of data without
becoming unstable or crashing.
 Security: The Unix file system uses a set of permissions
that allows administrators to control who has access to files
and directories.
 Compatibility: The Unix file system is widely used and
supported, which means that files can be easily transferred
between different Unix-based systems.

system calls

A system call is a procedure that provides the interface


between a process and the operating system.

It is the way by which a computer program requests a service from


the kernel of the operating system.

Different operating systems execute different system calls.


In Linux, making a system call involves transferring control
from unprivileged user mode to privileged kernel mode; the
details of this transfer vary from architecture to architecture. The
libraries take care of collecting the system-call arguments and, if
necessary, arranging those arguments in the special form necessary
to make the system call.
System calls are divided into 5 categories mainly :
 Process Control
 File Management
 Device Management
 Information Maintenance
 Communication

Process Control :
This system calls perform the task of process creation, process
termination, etc.
The Linux System calls under this are fork() , exit() , exec().
 fork()
 A new process is created by the fork() system call.
 A new process may be created with fork() without a
new program being run-the new sub-process simply
continues to execute exactly the same program that
the first (parent) process was running.
 It is one of the most widely used system calls under
process management.
 exit()
 The exit() system call is used by a program to
terminate its execution.
 The operating system reclaims resources that were
used by the process after the exit() system call.
 exec()
 A new program will start executing after a call to
exec()
 Running a new program does not require that a new
process be created first: any process may call
exec() at any time. The currently running program is
immediately terminated, and the new program
starts executing in the context of the existing
process.
File Management :
File management system calls handle file manipulation jobs like
creating a file, reading, and writing, etc. The Linux System calls
under this are open(), read(), write(), close().
 open():
 It is the system call to open a file.
 This system call just opens the file, to perform
operations such as read and write, we need to
execute different system call to perform the
operations.
 read():
 This system call opens the file in reading mode
 We can not edit the files with this system call.
 Multiple processes can execute the read() system
call on the same file simultaneously.
 write():
 This system call opens the file in writing mode
 We can edit the files with this system call.
 Multiple processes can not execute the write()
system call on the same file simultaneously.
 close():
 This system call closes the opened file.

Device Management :
Device management does the job of device manipulation like
reading from device buffers, writing into device buffers, etc. The
Linux System calls under this is ioctl().
 ioctl():
 ioctl() is referred to as Input and Output Control.
 ioctl is a system call for device-specific input/output
operations and other operations which cannot be
expressed by regular system calls.
Information Maintenance:
It handles information and its transfer between the OS and the user
program. In addition, OS keeps the information about all its
processes and system calls are used to access this information. The
System calls under this are getpid(), alarm(), sleep().
 getpid():
 getpid stands for Get the Process ID.
 The getpid() function shall return the process ID of
the calling process.
 The getpid() function shall always be successful and
no return value is reserved to indicate an error.
 alarm():
 This system call sets an alarm clock for the delivery
of a signal that when it has to be reached.
 It arranges for a signal to be delivered to the calling
process.
 sleep():
 This System call suspends the execution of the
currently running process for some interval of time
 Meanwhile, during this interval, another process is
given chance to execute
Communication :
These types of system calls are specially used for inter-process
communications.
Two models are used for inter-process communication
1. Message Passing(processes exchange messages with one
another)
2. Shared memory(processes share memory region to
communicate)
The system calls under this are pipe() , shmget() ,mmap().
 pipe():
 The pipe() system call is used to communicate
between different Linux processes.
 It is mainly used for inter-process communication.
 The pipe() system function is used to open file
descriptors.
 shmget():
 shmget stands for shared memory segment.
 It is mainly used for Shared memory
communication.
 This system call is used to access the shared
memory and access the messages in order to
communicate with the process.
 mmap():
 This function call is used to map or unmap files or
devices into memory.
 The mmap() system call is responsible for mapping
the content of the file to the virtual memory space
of the process.

#include<unistd.h>
#include<stdio.h>
#include<fcntl.h>
int main()
{
int fp;
char msg[30]="this is write operation";
char rd_fm_fl[35];
fp=open("test.txt", O_RDWR);
printf("fp = %d",fp);
if(fp != -1)
{
printf("write to file");
write(fp,msg,sizeof(msg));
lseek(fp,0,SEEK_SET);
read(fp,rd_fm_fl,sizeof(msg));
printf("\nThe message written to file is \n %s",rd_fm_fl);
close(fp);
}
return 0;}

You might also like