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

17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria myrajendra
 
Software configuration management
Software configuration managementSoftware configuration management
Software configuration managementfizamustanser
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examplesabclearnn
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
 
Software Engineering unit 2
Software Engineering unit 2Software Engineering unit 2
Software Engineering unit 2Abhimanyu Mishra
 
Spm unit2 select appropriate approach
Spm unit2 select appropriate approachSpm unit2 select appropriate approach
Spm unit2 select appropriate approachDevyani Vasistha
 
Linux fundamentals
Linux fundamentalsLinux fundamentals
Linux fundamentalsRaghu nath
 
Requirements Engineering Processes
Requirements Engineering ProcessesRequirements Engineering Processes
Requirements Engineering ProcessesRa'Fat Al-Msie'deen
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESVENNILAV6
 
formal verification
formal verificationformal verification
formal verificationToseef Aslam
 
Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell scriptBhavesh Padharia
 
Linux security introduction
Linux security introduction Linux security introduction
Linux security introduction Mohamed Gad
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Wave Digitech
 
Introduction to distributed file systems
Introduction to distributed file systemsIntroduction to distributed file systems
Introduction to distributed file systemsViet-Trung TRAN
 
Linux Basic Commands
Linux Basic CommandsLinux Basic Commands
Linux Basic CommandsHanan Nmr
 

What's hot (20)

17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
 
Linux file system
Linux file systemLinux file system
Linux file system
 
Software configuration management
Software configuration managementSoftware configuration management
Software configuration management
 
Metrics
MetricsMetrics
Metrics
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Software Engineering unit 2
Software Engineering unit 2Software Engineering unit 2
Software Engineering unit 2
 
Spm unit2 select appropriate approach
Spm unit2 select appropriate approachSpm unit2 select appropriate approach
Spm unit2 select appropriate approach
 
Linux fundamentals
Linux fundamentalsLinux fundamentals
Linux fundamentals
 
Requirements Engineering Processes
Requirements Engineering ProcessesRequirements Engineering Processes
Requirements Engineering Processes
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
CMMI staged and continuous
CMMI staged and continuousCMMI staged and continuous
CMMI staged and continuous
 
formal verification
formal verificationformal verification
formal verification
 
Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell script
 
Linux security introduction
Linux security introduction Linux security introduction
Linux security introduction
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Introduction to distributed file systems
Introduction to distributed file systemsIntroduction to distributed file systems
Introduction to distributed file systems
 
Linux Basic Commands
Linux Basic CommandsLinux Basic Commands
Linux Basic Commands
 

Similar to Unix files

Similar to Unix files (20)

Unit 7
Unit 7Unit 7
Unit 7
 
Types of files
Types of filesTypes of files
Types of files
 
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
 

Recently uploaded

Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 

Recently uploaded (20)

Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 

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