Files & Directories
Total Page:16
File Type:pdf, Size:1020Kb
COP 4604 UNIX System Programming Files & Directories Dr. Sam Hsu Computer Science & Engineering Florida Atlantic University File Types n Regular n Directory n FIFO n Character special n Block special n Symbolic link 2 File Attributes Attribute Value meaning File type Type of file Access permission File access permissions for different users Hard link count Number of hard links of a file UID User ID of file owner GID Group ID of file File size File size in bytes Last access time Time the file was last accessed Last modification time Time the file was last modified Last change time Time the file attribute was last changed Inode number Inode number of the file File system ID File system ID where the file is stored 3 File Access Permissions n 3 different categories read write excute n 3 different types of users user group other n For example: r w x r - x r - - 1 1 1 1 0 1 1 0 0 7 5 4 u g o 4 File IDs (1/2) n User ID n Real n Effective n Group ID n Real n Effective 5 File IDs (2/2) n Some special run-time properties: n Set-user-id bit. n Set-group-id bit. n Sticky bit. 6 Inodes n The administrative information about a file is kept in a structure known as an inode. n Inodes in a filesystem, in general, are structured as an array known as an inode table. n An inode number, which is an index to the inode table, uniquely identifies a file in a filesystem. 7 UNIX Kernel Support for Files n Three important run-time tables: n File descriptor table n File table n Vnode table n Relationship of C stream pointers and file descriptors: int fileno(FILE *fp); FILE *fdopen(int filedes, const char *type); 8 File Size n Regular file. n Directory file. n Symbolic link. n Holes in a file. 9 File Manipulations n Create files. n Open files. n Transfer data to and from files. n Close files. n Remove files. n Query file attributes. n Truncate files. 10 Hard and Symbolic Links Hard link Symbolic link Does not create a new inode Creates a new inode Increases hard link count Not affecting the target file Not for directories (except for root) Can link to any type of files Not allowed to go across file Can link to any file anywhere systems 11 Some File Commands and System Calls Command System call Attributes changed chmod chmod Access permission, last change time chown chown UID, last change time chgrp chown GID, last change time touch utime Last access time, last modification time ln link Hard link count increased rm unlink Hard link count decreased vi, emac File size, last access time, modification time 12.