SlideShare a Scribd company logo
1 of 34
Download to read offline
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

What's hot

The linux file system structure
The linux file system structureThe linux file system structure
The linux file system structure
Teja Bheemanapally
 

What's hot (20)

Disk and File System Management in Linux
Disk and File System Management in LinuxDisk and File System Management in Linux
Disk and File System Management in Linux
 
Linux security
Linux securityLinux security
Linux security
 
File System Implementation - Part1
File System Implementation - Part1File System Implementation - Part1
File System Implementation - Part1
 
The linux file system structure
The linux file system structureThe linux file system structure
The linux file system structure
 
Unit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - ThreadsUnit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - Threads
 
Unit 1 introduction to web programming
Unit 1 introduction to web programmingUnit 1 introduction to web programming
Unit 1 introduction to web programming
 
Lecture 2 more about parallel computing
Lecture 2   more about parallel computingLecture 2   more about parallel computing
Lecture 2 more about parallel computing
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
Operating Systems - File Management
Operating Systems -  File ManagementOperating Systems -  File Management
Operating Systems - File Management
 
Process threads operating system.
Process threads operating system.Process threads operating system.
Process threads operating system.
 
Types of files
Types of filesTypes of files
Types of files
 
GFS & HDFS Introduction
GFS & HDFS IntroductionGFS & HDFS Introduction
GFS & HDFS Introduction
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
6.distributed shared memory
6.distributed shared memory6.distributed shared memory
6.distributed shared memory
 
File management
File managementFile management
File management
 
Lecture 1 introduction to parallel and distributed computing
Lecture 1   introduction to parallel and distributed computingLecture 1   introduction to parallel and distributed computing
Lecture 1 introduction to parallel and distributed computing
 

Similar to Unix files

Unit 7
Unit 7Unit 7
Unit 7
siddr
 

Similar to Unix files (20)

Unit 7
Unit 7Unit 7
Unit 7
 
2nd unit part 1
2nd unit  part 12nd unit  part 1
2nd unit part 1
 
Linux: Basics OF Linux
Linux: Basics OF LinuxLinux: Basics OF Linux
Linux: Basics OF Linux
 
UNIX.pptx
UNIX.pptxUNIX.pptx
UNIX.pptx
 
linux-file-system01.ppt
linux-file-system01.pptlinux-file-system01.ppt
linux-file-system01.ppt
 
Systems Programming - File IO
Systems Programming - File IOSystems Programming - File IO
Systems Programming - File IO
 
Unix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptxUnix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptx
 
MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptx
 
Introduction to UNIX
Introduction to UNIXIntroduction to UNIX
Introduction to UNIX
 
Unix/Linux
Unix/Linux Unix/Linux
Unix/Linux
 
Linuxnishustud
LinuxnishustudLinuxnishustud
Linuxnishustud
 
unit 3 ppt file represented system......
unit 3 ppt file represented system......unit 3 ppt file represented system......
unit 3 ppt file represented system......
 
10 File System
10 File System10 File System
10 File System
 
Operating systems unix
Operating systems   unixOperating systems   unix
Operating systems unix
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
Linux 4 you
Linux 4 youLinux 4 you
Linux 4 you
 
linux-lecture1.ppt
linux-lecture1.pptlinux-lecture1.ppt
linux-lecture1.ppt
 
KMSUnix and Linux.pptx
KMSUnix and Linux.pptxKMSUnix and Linux.pptx
KMSUnix and Linux.pptx
 
How to Audit Linux - Gene Kartavtsev, ISACA MN
How to Audit Linux - Gene Kartavtsev, ISACA MNHow to Audit Linux - Gene Kartavtsev, ISACA MN
How to Audit Linux - Gene Kartavtsev, ISACA MN
 
9781111306366 ppt ch11
9781111306366 ppt ch119781111306366 ppt ch11
9781111306366 ppt ch11
 

Recently uploaded

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 

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