- Published on
COMP2700 - Week 4 - Objects and Permissions
Table of Contents
Objects
- All files in unix can be represented as a file
- Tree file system
- Each file entry in a directory is a pointer to a data structure called an inode
| Mode | Type of file and access rights |
|---|---|
| uid | Username of the owner |
| gid | Owner group |
| atime | Last access time |
| mtime | Last modification time |
| itime | Last inode alteration time |
| block count | Size of file; Physical location |
Information about Objects
-rwxr-x--- 1 alice alice 4648643 Aug 17 10:34 test.pdfdrwxr-xr-x 2 alice tutor 3452 Aug 17 10:33 lectures-
File type -> First character
--> filed-> directoryb-> block device file (SSD/HDD, etc)c-> character device file (terminal devices; byte-by-byte query rather than block-by-block)s-> socket Not coveredl-> symbolic linkp-> FIFO (queue)
-
File permissions -> Next nine characters
-
Link counter -> Number of links (i.e. directories pointing) to the file
-
Username -> Usually user who created the file
-
Group -> New file belongs to creator's group or directory's group
-
File size, modification datetime and filename
-
Owner and root can change permissions (chmod)
-
root can change file owner and group (chown)
-
Filename stored in the directory, not in inode
File and Directory Permissions
-
4 groups of 3-bits
-
First group: special modes
-
Next three groups define read, write, and execute access for: owner, group, and other
Special Modes
- First bit -> SUID bit
- Allows program to change effective UID to be different from actual UID
- Second bit -> GUID bit
- Allows program to change effective GID to be different from actual GID
- Third bit -> Sticky bit
- Different implementations
Note: Rarely used, most files will have these set to 0
r-> readw-> writex-> execute
rw-r--r-- -> 000 110 100 100rwxrwxrwx -> 000 111 111 111Special Modes Textual Representation
When special modes are present, bits in the special modes change the display of executable bits of the remaining groups.
- If SUID bit is set: Display
sif the 'owner' exec bit is set; otherwise displayS - If SGID bit is set: Display
sif the 'group' exec bit is set; otherwise displayS - If sticky bit is set: Display
tif the 'other' exec bit is set; otherwise displayT
110 111 110 100 -> rwsrwSr--011 111 101 101 -> rwxrwsr-T101 110 110 100 -> rwSrw-r-TOctal Representation
Each group of three bits can be represented as an octal
000 110 100 100 -> 0644011 111 101 101 -> 3755Default Permissions
- Unix typically use default permissions
0666when creating a new file, and0777when created a new program - Permissions can be adjusted using the umask
- What rights should be withheld
- Actual permissions is derived by masking the given default permissions with the umask
- Computing the logical AND of the bits in the default permission and of the inverse of the bits in the umask
Permissions for Directories
- Read -> Required to see files in a directory (i.e.
ls) - Write -> Required to add or remove files to or from a directory
- Execute -> Required the make the directory current (i.e.
cd) and opening files inside the directory