COP 4604 System Programming

Files & Directories

Dr. Sam Hsu Computer Science & Engineering Florida Atlantic University Types n Regular n n FIFO n Character special n Block special n Symbolic

2 File Attributes

Attribute Value meaning File type Type of file Access permission File access permissions for different users count Number of hard links of a file UID User ID of file owner GID Group ID of file 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 was last changed number Inode number of the file ID File system ID where the file is stored

3 File Access Permissions

n 3 different categories 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 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 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 . n Holes in a file.

9 File Manipulations n Create files. n files. n Transfer to and from files. n 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 Attributes changed 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 link Hard link count increased Hard link count decreased , emac File size, last access time, modification time

12