files in unix
DESCRIPTION
Files in Unix. From the System's View. File Handling Data Structures. Process Table File Table V-Node Table inodes. Process Table. Process A. File Descriptor Flags. File Table Entry. Process B. Pointer to File Table Entry. Process C. Process D. File Table. File 1. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/1.jpg)
1
Files in Unix
From the System's View
![Page 2: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/2.jpg)
2
File Handling Data Structures
Process Table File Table V-Node Table inodes
![Page 3: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/3.jpg)
3
Process Table
Process A
Process B
Process C
Process D
File DescriptorFlags
Pointer toFile Table Entry
FileTableEntry
![Page 4: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/4.jpg)
4
File Table
File Status FlagsRead, Write, Etc.
Current File Offset
Pointer to V-node Table Entry
File 1
File 2
File 3
File 4
File Table forOpen Files
V-node Table
![Page 5: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/5.jpg)
5
V-Node Table Entry
FileTableEntry
File Type
Pointers to Functionsfor this File
Inode Information
V-node TableEntry
Disk Drive
![Page 6: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/6.jpg)
6
File Types
Regular files Directory files Character special files Block special files FIFOs Sockets Symbolic Links
![Page 7: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/7.jpg)
7
Special File Protection Bits
Group Locking
Set group/User ID on execution
Sticky Bit (saved-text-bit)
![Page 8: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/8.jpg)
8
Disk Drives and File Systems
Partition Partition Partition
File System
inode inode inode inode inode
i-list directory blocks and data blocks
BootBlock
SuperBlock
![Page 9: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/9.jpg)
9
Layout: Boot area: Bootstrap code Superblock: Attributes and metadata of file system Inode list: one inode/file 64 bytes, fix the size of file
system Data area: files, directories and indirect blocks which
hold pointers to other file data blocks Directories:
File containing list of files and subdirectories Fixed record of 16 bytes
![Page 10: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/10.jpg)
10
inodes
inodes contain a lot of information about a file mode and type of file number of links to the file owner's UID owners GID number of bytes in file times (last accessed, modified, inode changed) physical disk addresses (direct and indirect blocks) number of blocks access information
![Page 11: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/11.jpg)
11
File Systems Expanded
B S i-list data data data directorydirectory datadata data
inode inode inode
inode # File Name
inode # File Name
inode # File Name
![Page 12: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/12.jpg)
12
2 bytes ( 216= 65535 files) inode number, 14 bytes file name
0 inode number means file no longer exist Root directory and parent have inode number equal to 2
73 .
38 ..
9 File1
0 Deleted file
110 Subdirectory1
65 File2
![Page 13: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/13.jpg)
13
Inodes ( Index nodes): Each file has one unique inode Inode contains metadata of the file on-disk inode and in-core inode
Field Size Description
di_mode 2 File type, permissions
di_uid 2 Owner UID
di_gid 2 Owner GID
di_size 4 Size in bytes
di_addr 39 Array of block addresses
: : :
![Page 14: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/14.jpg)
14
di_addr: File is not stored in contiguous blocks, prevents
fragmentation An array of block address is required, Stored in inode,
prevent extra read Size of array depends on the size of file
012345
76
89
101112
indirectDouble indirect
triple indirect
![Page 15: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/15.jpg)
15
Direction and Indirection
Direct 0
Direct 1
Direct 2
Direct 3
Direct 4
Direct 5
Direct 6
Direct 7
Direct 8
Direct 9
Sgl Ind
Dbl Ind
Triple Ind
DiskBlocks
inode
![Page 16: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/16.jpg)
16
In-core inodes
When a file is being used, it's inode is copied to memory (core) and additional fields are added access status
node is locked process is waiting for node to unlock in-core inode has been modified file has changed so inode has also changed
Number of processes using inode and file Device ID and disk address where inode is located Current file position
![Page 17: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/17.jpg)
17
RFS (Remote File System)
An AT&T invention Independent of any particular network hardware
or software Designed for transparent sharing of disk storage
and peripherals RFS mounts a remote directory structure under
an existing structure in the user's filesystem Remote files are then accessed as though they are part
of the local file system
RFS also supports special files and named pipes
![Page 18: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/18.jpg)
18
System V File System (s5fs)
Single logical disk or partition, one FS per partition Each FS has own root, sub directories, Files, data and
metadata Disk Block = 512 * n, granularity of disk allocation for a file Translated by disk drivers in to track sectors and cylinders
B S Inode list Data blocks
Boot area superblock
![Page 19: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/19.jpg)
19
Superblock Metadata about File system One Superblock per File system Kernel reads Superblock when mounting the File
system Superblock contains following information
Size in blocks of the file system Size in blocks of the inode list Number of free blocks and inodes Free block list (Partial) Free inode list (Full)
![Page 20: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/20.jpg)
20
Kernel Organization
In-Core Inodes Represented by struct inode All fields of on-disk inode and following extra fields
vnode: contains the vnode of the file Device ID of the partition containing the file Inode number of the file Flags for synchronization and cache management Pointers to keep the inode on a free list Pointers to keep the inode on a hash queue Block number of last block read
![Page 21: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/21.jpg)
21
Inode Lookup Lookuppn(), a file system independent function performs
pathname parsing When searching s5fs directory it translates to a call to
s5lookup() s5lookup first checks directory name lookup cache On miss it reads the directory one block at a time If directory contains a valid filename entry, s5lookup()
obtains inode number of file iget() is called to locate inode iget() searches the appropriate hash table to get the
inode
![Page 22: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/22.jpg)
22
The server keeps track of how many remote users have the file open at a given time
Server also maintain security by distinguishing between local and remote opens
Remote access can be restricted to the privileges of selected local accounts
![Page 23: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/23.jpg)
23
NFS (Network File System)
Developed by Sun Microsystems Design goal was portability to other OS's and
architectures Uses RPCs (Remote Procedure Calls) for protocol
definition and remote system access Uses the External Data Representation (XDR) to
define data in a machine independent manner Furthers machine independence by defining a
Virtual File System (VFS) that defines operations that can be performed on a file
![Page 24: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/24.jpg)
24
NFS fileservers are stateless and do not track the state of files or provide any standard Unix file locking capabilities Conflicts among users of the same file can arise
Sun has provided a locking scheme by maintaining client requested locks in memory only Both client and server keep locks in memory for
consistency However, because of the tight coupling between client
and server, loss of a server can cause data consistency problems
![Page 25: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/25.jpg)
25
NFS does not allow shared root filesystems In concept, shared directories like /dev, /bin, and /etc
should reside on a common file server This simplifies the design but the failure of the
fileserver then impacts all attached nodes The user or sysadmin must know what directories
should be mounted at each network node The number of required mounts can take quite a while
to perform on system reboot
Since files are shared in place (on the server) there are no revision conflicts
![Page 26: Files in Unix](https://reader035.vdocuments.net/reader035/viewer/2022081514/56814d40550346895dba65de/html5/thumbnails/26.jpg)
26
The stateless nature of NFS (except for the locking kludge) ensures consistency of the system after recovery from a crash