SlideShare a Scribd company logo
UNIX FILES
By : Sunil Kumar R.M
1Sunil Kumar R.M Assistant Professor RLJIT
UNIX FILES
• Files are the building blocks of any operating
system.
user executes a command in UNIX
the UNIX kernel fetches the corresponding
executable file and loads its instruction text to
memory
 and creates a process to execute the
command on your behalf.
2Sunil Kumar R.M Assistant Professor RLJIT
File Types
• A file in a UNIX or POSIX system may be one of
the following types:
– Regular file
– Directory file
-- FIFO file
– Character device file
-- Block device file
3Sunil Kumar R.M Assistant Professor RLJIT
Regular File
– Text file or binary file
i.e both can be executable files (.exe) with
suitable permissions. Ex :pdf, .txt etc
How to create?
using editors(vi editor)
How to delete?
using rm command.
4Sunil Kumar R.M Assistant Professor RLJIT
Directory files
• Folder.
• Tree structure.
• HOW TO CREATE?
– mkdir command
» Example mkdir /usr/sunil/file1
HOW TO delete?
-- rmdir /usr/sunil/file1
We can also display the contents of directory using ls
command
5Sunil Kumar R.M Assistant Professor RLJIT
FIFO files
• Used in Interprocess communication (IPC)
buffer
Process1 ------------------------------------------ Process2
(pipe/named pipe)
CREATE?
• mkfifo /usr/sunil/fifo_pipe
• mknod /usr/sunil/fifo_pipe p
6Sunil Kumar R.M Assistant Professor RLJIT
DEVICE FILES
• Block device files.
ex: floppy disk, hard disk.
• Character device files.
• Ex: line printer, keyboard, modem etc.
CREATE?
Syntax:
$mknod path c/b major minor
name device # device #
Ex: $ mknod /usr/sunil/file1 C 115 20
7Sunil Kumar R.M Assistant Professor RLJIT
Device files 2
• Major device no :
– Index to Kernel table
• Device driver function addresses.
• Minor device no:
– Integer no that is a parameter to the device driver
function
8Sunil Kumar R.M Assistant Professor RLJIT
Symbolic link files
• Supported by Unix but not by posix
– It contains a path name that refers to another file
/file system that can be local/remote.
– Creating symbolic link file
• $ ln -s usr/sunil/abc usr/rljit/xyz
9Sunil Kumar R.M Assistant Professor RLJIT
The UNIX and POSIX File Systems
• tree-like hierarchical file system.
• Name MAX
• PathMAX
• Posix name and path
• Hard link
10Sunil Kumar R.M Assistant Professor RLJIT
11Sunil Kumar R.M Assistant Professor RLJIT
The UNIX and POSIX File Attributes
• 1) File type - specifies what type of file it is.
• 2) Access permission - the file access
permission for owner, group and others.
• 3) Hard link count - number of hard link of
the file
• 4) Uid - the file owner user id.
• 5) Gid - the file group id
• . 6) File size - the file size in bytes.
12Sunil Kumar R.M Assistant Professor RLJIT
The UNIX and POSIX File Attributes
• 7) Inode no - the system inode no of the file.
8) File system id - the file system id where the
file is stored.
• 9) Last access time - the time, the file was last
accessed.
• 10) Last modified time - the file, the file was
last modified.
• 11) Last change time - the time, the file was
last changed.
13Sunil Kumar R.M Assistant Professor RLJIT
14Sunil Kumar R.M Assistant Professor RLJIT
Inodes in UNIX System V
• inode table, which keeps tracks of all files
– Inode record(attributes,inode no, physical
address)
– It’s a u i ue id.
– Why os does ’t sto e file a e
– Directory file content.
– Who gives inode no and when?
15Sunil Kumar R.M Assistant Professor RLJIT
• Directory is a record oriented file.
• Record data type is struct dirent in UNIX V and
POSIX.1, and struct dirent in BSD UNIX
Directory files
16Sunil Kumar R.M Assistant Professor RLJIT
• A hard link is a UNIX path name for a file
• To create hard link ln command is used
ln /usr/abc/old.c /usr/xyz/new.c
• Symbolic link is also a means of referencing a
file
• To create symbolic link ln command is used
with option –s
ln –s /usr/abc/old.c /usr/xyz/new.c
Hard and symbolic links
17Sunil Kumar R.M Assistant Professor RLJIT
• Cp command creates a duplicated copy of file
to another file with a different path name
• Where as ln command saves space by not
duplicating the copy here the new file will
have same inode number as original file
Difference : cp and ln command
18Sunil Kumar R.M Assistant Professor RLJIT
Difference : hard link and symbolic link
Hard link Symbolic link
Does not create a new
inode
Create a new inode
Cannot link directories
unless it is done by root
Can link directories
Cannot link files across
file systems
Can link files across file
system
Increase hard link count
of the linked inode
Does not change hard
link count of the linked
inode
19Sunil Kumar R.M Assistant Professor RLJIT
• Files are indentified by path names
• Files must be created before they can be
used.
• open system call  returns a file descriptor
APPLICATION PROGRAM INTERFACE
TO FILES(API)
20Sunil Kumar R.M Assistant Professor RLJIT
• OPEN_MAX
• READ and WRITE
• Stat and fstat file attributes
• File attributes are changed using chmod,
chown, utime and link system calls
• Hard links are removed by unlink system call
21Sunil Kumar R.M Assistant Professor RLJIT
22Sunil Kumar R.M Assistant Professor RLJIT
• user executes a command -> process(kernel)
command execution
• process data structures: file descriptor table is
one among them
• File descriptor table OPEN_MAX entries,
and it records all files opened by the process
UNIX KERNEL SUPPORT FOR FILES
23Sunil Kumar R.M Assistant Professor RLJIT
• Whenever an open function is called the
kernel will resolve the pathname to file inode
• Open call fails and returns -1 (file inode not exist
/the process lacks appropriate permissions)
Kernel support to open system call
24Sunil Kumar R.M Assistant Professor RLJIT
rc=1
rc=2
r
rc=1
rw
rc=1
w
rc=1
File descriptor table
File table Inode table
25Sunil Kumar R.M Assistant Professor RLJIT
• Else a series of steps follow
• The kernel will search the file descriptor
table and look for first unused entry, which is
returned as file descriptor of the opened file
• The kernel will scan the file table, which is
used to reference the file If an unused entry
is found then
26Sunil Kumar R.M Assistant Professor RLJIT
1. The p o ess’s file des ipto ta le e t y will e set
to point to file table entry
2. The file table entry will be set to point to inode
table entry where the inode record of file is present
3. The file table entry will contain the current file
pointer of the open file
4. The file table entry will contain an open mode
which specifies the file is opened for read- only
,write-only etc.
5. Reference count of file table is set to 1.
6. The reference count of the in-memory inode of file
is increased by 1.
27Sunil Kumar R.M Assistant Professor RLJIT
• The kernel will use the file descriptor to index
the p o ess’s file des ipto ta le to fi d file
table entry to opened file
• It checks the file table entry to make sure that
the file is opened with appropriate mode
• The kernel will use the file pointer used in file
table entry to determine where the read
operation should occur in file
Kernel support : read system call
28Sunil Kumar R.M Assistant Professor RLJIT
• The kernel will check the type of file in the
inode record and invokes an appropriate
driver function to initiate the actual data
transfer with a physical file
• If the process calls lseek function then the
changes are made provided the file is not a
character device file, a FIFO file, or a symbolic
link file as they follow only sequential read
and write operations
29Sunil Kumar R.M Assistant Professor RLJIT
1. The kernel will set the corresponding
descriptor table entry to unused
2. It decrements the reference count in file
table entry by 1.if reference count !=0 then
go to 6
3. File table entry is marked unused
4. The reference count in file inode table entry
by 1.if reference count !=0 then go to 6
Kernel support : close system call
30Sunil Kumar R.M Assistant Professor RLJIT
5. If hard link count is non zero, it returns a
success status, otherwise marks the inode
table entry as unused and and deallocates all
the physical disk storage
6. It returns the process with a 0 (success )
status
31Sunil Kumar R.M Assistant Professor RLJIT
32Sunil Kumar R.M Assistant Professor RLJIT
33Sunil Kumar R.M Assistant Professor RLJIT
rc=1
rc=2
r
rc=1
rw
rc=1
w
rc=1
File descriptor table
File table Inode table
34Sunil Kumar R.M Assistant Professor RLJIT

More Related Content

PPTX
Linux process management
PPTX
Process management in linux
PDF
Operating systems system structures
PPTX
Threads .ppt
PPT
Memory Management in OS
PPT
Os Threads
PPTX
Concurrency
PPT
OS Components and Structure
Linux process management
Process management in linux
Operating systems system structures
Threads .ppt
Memory Management in OS
Os Threads
Concurrency
OS Components and Structure

What's hot (20)

PPT
Chapter 13 - I/O Systems
PPT
Chapter 2 - Operating System Structures
PPTX
Boot process
PDF
Lesson 2 Understanding Linux File System
PPTX
Kernel. Operating System
PPT
Basic 50 linus command
PPTX
Linux System Programming - File I/O
PPTX
Storage Management
PDF
Os services
PPSX
Real Time Operating System
PPTX
Unix operating system architecture with file structure
PPTX
Unix
PPTX
i/o interface
PPTX
Multi Processors And Multi Computers
PPTX
process control block
PPTX
evolution of operating system
PDF
PDF
OS Memory Management
PPTX
Synchronization in distributed computing
Chapter 13 - I/O Systems
Chapter 2 - Operating System Structures
Boot process
Lesson 2 Understanding Linux File System
Kernel. Operating System
Basic 50 linus command
Linux System Programming - File I/O
Storage Management
Os services
Real Time Operating System
Unix operating system architecture with file structure
Unix
i/o interface
Multi Processors And Multi Computers
process control block
evolution of operating system
OS Memory Management
Synchronization in distributed computing
Ad

Similar to Unix files (20)

PPT
Unit 7
PPTX
2nd unit part 1
PPT
2ab. UNIX files.ppt JSS science and technology university
PPTX
MODULE 3.1 updated-18cs56.pptx
PPTX
unix details file system, architecture, directory
PPTX
Unix / Linux Operating System introduction.
PPTX
Examining Linux File Structures
PPTX
Introduction to Unix
PPTX
Shells commands, file structure, directory structure.pptx
PPT
files-inodes in Unix programming in computer science and engineering.ppt
PPTX
Unix training session 1
PPTX
Introduction to Unix Concets.pptx
PPTX
Introduction to Unix Concets.pptx
PDF
AOS Lab 1: Hello, Linux!
PPT
Unit 2.1 Introduction to Kernel.ppt (Kernel Services and Architecture)
PPTX
Chapter 2 Introduction to Unix Concepts
PDF
Unix system programming
PDF
PPTX
File types atul namdeo
PDF
Programming Embedded linux
Unit 7
2nd unit part 1
2ab. UNIX files.ppt JSS science and technology university
MODULE 3.1 updated-18cs56.pptx
unix details file system, architecture, directory
Unix / Linux Operating System introduction.
Examining Linux File Structures
Introduction to Unix
Shells commands, file structure, directory structure.pptx
files-inodes in Unix programming in computer science and engineering.ppt
Unix training session 1
Introduction to Unix Concets.pptx
Introduction to Unix Concets.pptx
AOS Lab 1: Hello, Linux!
Unit 2.1 Introduction to Kernel.ppt (Kernel Services and Architecture)
Chapter 2 Introduction to Unix Concepts
Unix system programming
File types atul namdeo
Programming Embedded linux
Ad

Recently uploaded (20)

PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Welding lecture in detail for understanding
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Geodesy 1.pptx...............................................
PPT
Project quality management in manufacturing
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
web development for engineering and engineering
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
PPT on Performance Review to get promotions
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Welding lecture in detail for understanding
CH1 Production IntroductoryConcepts.pptx
Geodesy 1.pptx...............................................
Project quality management in manufacturing
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
CYBER-CRIMES AND SECURITY A guide to understanding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
web development for engineering and engineering
R24 SURVEYING LAB MANUAL for civil enggi
Foundation to blockchain - A guide to Blockchain Tech
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPT on Performance Review to get promotions
Operating System & Kernel Study Guide-1 - converted.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf

Unix files

  • 1. UNIX FILES By : Sunil Kumar R.M 1Sunil Kumar R.M Assistant Professor RLJIT
  • 2. UNIX FILES • Files are the building blocks of any operating system. user executes a command in UNIX the UNIX kernel fetches the corresponding executable file and loads its instruction text to memory  and creates a process to execute the command on your behalf. 2Sunil Kumar R.M Assistant Professor RLJIT
  • 3. File Types • A file in a UNIX or POSIX system may be one of the following types: – Regular file – Directory file -- FIFO file – Character device file -- Block device file 3Sunil Kumar R.M Assistant Professor RLJIT
  • 4. Regular File – Text file or binary file i.e both can be executable files (.exe) with suitable permissions. Ex :pdf, .txt etc How to create? using editors(vi editor) How to delete? using rm command. 4Sunil Kumar R.M Assistant Professor RLJIT
  • 5. Directory files • Folder. • Tree structure. • HOW TO CREATE? – mkdir command » Example mkdir /usr/sunil/file1 HOW TO delete? -- rmdir /usr/sunil/file1 We can also display the contents of directory using ls command 5Sunil Kumar R.M Assistant Professor RLJIT
  • 6. FIFO files • Used in Interprocess communication (IPC) buffer Process1 ------------------------------------------ Process2 (pipe/named pipe) CREATE? • mkfifo /usr/sunil/fifo_pipe • mknod /usr/sunil/fifo_pipe p 6Sunil Kumar R.M Assistant Professor RLJIT
  • 7. DEVICE FILES • Block device files. ex: floppy disk, hard disk. • Character device files. • Ex: line printer, keyboard, modem etc. CREATE? Syntax: $mknod path c/b major minor name device # device # Ex: $ mknod /usr/sunil/file1 C 115 20 7Sunil Kumar R.M Assistant Professor RLJIT
  • 8. Device files 2 • Major device no : – Index to Kernel table • Device driver function addresses. • Minor device no: – Integer no that is a parameter to the device driver function 8Sunil Kumar R.M Assistant Professor RLJIT
  • 9. Symbolic link files • Supported by Unix but not by posix – It contains a path name that refers to another file /file system that can be local/remote. – Creating symbolic link file • $ ln -s usr/sunil/abc usr/rljit/xyz 9Sunil Kumar R.M Assistant Professor RLJIT
  • 10. The UNIX and POSIX File Systems • tree-like hierarchical file system. • Name MAX • PathMAX • Posix name and path • Hard link 10Sunil Kumar R.M Assistant Professor RLJIT
  • 11. 11Sunil Kumar R.M Assistant Professor RLJIT
  • 12. The UNIX and POSIX File Attributes • 1) File type - specifies what type of file it is. • 2) Access permission - the file access permission for owner, group and others. • 3) Hard link count - number of hard link of the file • 4) Uid - the file owner user id. • 5) Gid - the file group id • . 6) File size - the file size in bytes. 12Sunil Kumar R.M Assistant Professor RLJIT
  • 13. The UNIX and POSIX File Attributes • 7) Inode no - the system inode no of the file. 8) File system id - the file system id where the file is stored. • 9) Last access time - the time, the file was last accessed. • 10) Last modified time - the file, the file was last modified. • 11) Last change time - the time, the file was last changed. 13Sunil Kumar R.M Assistant Professor RLJIT
  • 14. 14Sunil Kumar R.M Assistant Professor RLJIT
  • 15. Inodes in UNIX System V • inode table, which keeps tracks of all files – Inode record(attributes,inode no, physical address) – It’s a u i ue id. – Why os does ’t sto e file a e – Directory file content. – Who gives inode no and when? 15Sunil Kumar R.M Assistant Professor RLJIT
  • 16. • Directory is a record oriented file. • Record data type is struct dirent in UNIX V and POSIX.1, and struct dirent in BSD UNIX Directory files 16Sunil Kumar R.M Assistant Professor RLJIT
  • 17. • A hard link is a UNIX path name for a file • To create hard link ln command is used ln /usr/abc/old.c /usr/xyz/new.c • Symbolic link is also a means of referencing a file • To create symbolic link ln command is used with option –s ln –s /usr/abc/old.c /usr/xyz/new.c Hard and symbolic links 17Sunil Kumar R.M Assistant Professor RLJIT
  • 18. • Cp command creates a duplicated copy of file to another file with a different path name • Where as ln command saves space by not duplicating the copy here the new file will have same inode number as original file Difference : cp and ln command 18Sunil Kumar R.M Assistant Professor RLJIT
  • 19. Difference : hard link and symbolic link Hard link Symbolic link Does not create a new inode Create a new inode Cannot link directories unless it is done by root Can link directories Cannot link files across file systems Can link files across file system Increase hard link count of the linked inode Does not change hard link count of the linked inode 19Sunil Kumar R.M Assistant Professor RLJIT
  • 20. • Files are indentified by path names • Files must be created before they can be used. • open system call  returns a file descriptor APPLICATION PROGRAM INTERFACE TO FILES(API) 20Sunil Kumar R.M Assistant Professor RLJIT
  • 21. • OPEN_MAX • READ and WRITE • Stat and fstat file attributes • File attributes are changed using chmod, chown, utime and link system calls • Hard links are removed by unlink system call 21Sunil Kumar R.M Assistant Professor RLJIT
  • 22. 22Sunil Kumar R.M Assistant Professor RLJIT
  • 23. • user executes a command -> process(kernel) command execution • process data structures: file descriptor table is one among them • File descriptor table OPEN_MAX entries, and it records all files opened by the process UNIX KERNEL SUPPORT FOR FILES 23Sunil Kumar R.M Assistant Professor RLJIT
  • 24. • Whenever an open function is called the kernel will resolve the pathname to file inode • Open call fails and returns -1 (file inode not exist /the process lacks appropriate permissions) Kernel support to open system call 24Sunil Kumar R.M Assistant Professor RLJIT
  • 25. rc=1 rc=2 r rc=1 rw rc=1 w rc=1 File descriptor table File table Inode table 25Sunil Kumar R.M Assistant Professor RLJIT
  • 26. • Else a series of steps follow • The kernel will search the file descriptor table and look for first unused entry, which is returned as file descriptor of the opened file • The kernel will scan the file table, which is used to reference the file If an unused entry is found then 26Sunil Kumar R.M Assistant Professor RLJIT
  • 27. 1. The p o ess’s file des ipto ta le e t y will e set to point to file table entry 2. The file table entry will be set to point to inode table entry where the inode record of file is present 3. The file table entry will contain the current file pointer of the open file 4. The file table entry will contain an open mode which specifies the file is opened for read- only ,write-only etc. 5. Reference count of file table is set to 1. 6. The reference count of the in-memory inode of file is increased by 1. 27Sunil Kumar R.M Assistant Professor RLJIT
  • 28. • The kernel will use the file descriptor to index the p o ess’s file des ipto ta le to fi d file table entry to opened file • It checks the file table entry to make sure that the file is opened with appropriate mode • The kernel will use the file pointer used in file table entry to determine where the read operation should occur in file Kernel support : read system call 28Sunil Kumar R.M Assistant Professor RLJIT
  • 29. • The kernel will check the type of file in the inode record and invokes an appropriate driver function to initiate the actual data transfer with a physical file • If the process calls lseek function then the changes are made provided the file is not a character device file, a FIFO file, or a symbolic link file as they follow only sequential read and write operations 29Sunil Kumar R.M Assistant Professor RLJIT
  • 30. 1. The kernel will set the corresponding descriptor table entry to unused 2. It decrements the reference count in file table entry by 1.if reference count !=0 then go to 6 3. File table entry is marked unused 4. The reference count in file inode table entry by 1.if reference count !=0 then go to 6 Kernel support : close system call 30Sunil Kumar R.M Assistant Professor RLJIT
  • 31. 5. If hard link count is non zero, it returns a success status, otherwise marks the inode table entry as unused and and deallocates all the physical disk storage 6. It returns the process with a 0 (success ) status 31Sunil Kumar R.M Assistant Professor RLJIT
  • 32. 32Sunil Kumar R.M Assistant Professor RLJIT
  • 33. 33Sunil Kumar R.M Assistant Professor RLJIT
  • 34. rc=1 rc=2 r rc=1 rw rc=1 w rc=1 File descriptor table File table Inode table 34Sunil Kumar R.M Assistant Professor RLJIT