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
ModeType of file and access rights
uidUsername of the owner
gidOwner group
atimeLast access time
mtimeLast modification time
itimeLast inode alteration time
block countSize of file; Physical location

Information about Objects

-rwxr-x--- 1 alice alice 4648643 Aug 17 10:34 test.pdf
drwxr-xr-x 2 alice tutor 3452 Aug 17 10:33 lectures
  • File type -> First character

    • - -> file
    • d -> directory
    • b -> block device file (SSD/HDD, etc)
    • c -> character device file (terminal devices; byte-by-byte query rather than block-by-block)
    • s -> socket Not covered
    • l -> symbolic link
    • p -> 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

File permission bits
  • r -> read
  • w -> write
  • x -> execute
Examples
rw-r--r-- -> 000 110 100 100
rwxrwxrwx -> 000 111 111 111

Special 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 s if the 'owner' exec bit is set; otherwise display S
  • If SGID bit is set: Display s if the 'group' exec bit is set; otherwise display S
  • If sticky bit is set: Display t if the 'other' exec bit is set; otherwise display T
Examples
110 111 110 100 -> rwsrwSr--
011 111 101 101 -> rwxrwsr-T
101 110 110 100 -> rwSrw-r-T

Octal Representation

Each group of three bits can be represented as an octal

Example
000 110 100 100 -> 0644
011 111 101 101 -> 3755

Default Permissions

  • Unix typically use default permissions 0666 when creating a new file, and 0777 when 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