Upload
oksana
View
55
Download
0
Tags:
Embed Size (px)
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 Presentation
Citation preview
1
Files in Unix
From the System's View
2
File Handling Data Structures
Process Table File Table V-Node Table inodes
3
Process Table
Process A
Process B
Process C
Process D
File DescriptorFlags
Pointer toFile Table Entry
FileTableEntry
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
5
V-Node Table Entry
FileTableEntry
File Type
Pointers to Functionsfor this File
Inode Information
V-node TableEntry
Disk Drive
6
File Types
Regular files Directory files Character special files Block special files FIFOs Sockets Symbolic Links
7
Special File Protection Bits
Group Locking
Set group/User ID on execution
Sticky Bit (saved-text-bit)
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
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
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
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
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
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
: : :
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
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
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
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
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
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)
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
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
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
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
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
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
26
The stateless nature of NFS (except for the locking kludge) ensures consistency of the system after recovery from a crash