Lecture 02 Flashcards

1
Q

Give some properties of files and directories

A
  • Owner
  • Group
  • Size
  • Permissions (User, Group, Other)
  • Times (Accessed, Modified, Changed (metadata))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What functions are used to access the meta-data of files and directories.

A

stat, fstat, and lstat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How is the file/directory metadata returned from the ‘stat’ function?

A

In a C structure called ‘stat’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In a ‘stat’ structure, what is the name of the protection variable?

A

st_mode

This is a mode_t variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which macro function checks if a file is a regular file or not from a mode_t variable?

A

S_ISREG(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which macro function checks if a file is a directory or not from a mode_t variable?

A

S_ISDIR(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which macro function checks if a file is a block special file or not from a mode_t variable?

A

S_ISBLK(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which macro function checks if a file is a character special file or not from a mode_t variable?

A

S_ISCHR(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which macro function checks if a file is First In First Out or not from a mode_t variable?

A

S_ISFIFO(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which macro function checks if a file is a socket or not from a mode_t variable?

A

S_ISSOCK(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which macro function checks if a file is a symbolic link or not from a mode_t variable?

A

S_ISLNK(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Do you need read permission on a file to call ‘stat’ on it?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What permissions do you need to open a file?

A

Permissions on the file itself, along with ‘execute’ permission on every directory in the path.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How many bits are used to represent permissions?

A

9.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the three permission groups: User,..,..

A

User, Group, Other

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What do Unix systems use to store file and directory metadata?

A

inodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Do inodes contain filenames and contents?

A

No

18
Q

How are inodes addressed?

A

Via an index in the inode table. inode n is the nth inode in the table.

19
Q

Directories map _s to _s

A

names to inode numbers

20
Q

Where is the root directory ‘/’ stored?

A

In some known inode.

21
Q

Can you explicitly make a hard link to a directory?

A

No

22
Q

Can you explicitly make a hard link to a file?

A

Yes

23
Q

What are directory entries known as?

A

Hard Links

24
Q

What are symbolic links stored as instead of an inode?

A

A text string

25
Q

What is a symbolic link?

A

A special file that points to another file or directory

26
Q

What function is used to open a directory for reading?

What does it return?

A

opendir.

It returns a DIR*

27
Q

What is the function prototype for opendir?

A

DIR* opendir(const char *name);

28
Q

What function is used to read from a directory?

What does it return.

A

readdir.

It returns a struct dirent

29
Q

What is the function prototype for readdir?

A

struct dirent* readdir(DIR *dir);

30
Q

What two fields will every struct dirent have?

A

The inode number and the filename.

31
Q

What function gets the current working directory?

A

getcwd()

32
Q

What function changes the current working directory?

A

chdir()

33
Q

What directory is used as the root for relative file paths?

A

The current working directory

34
Q

Which function is used to change the owner of a file?

A

chown()

35
Q

Which function is used to change the permissions of a file?

A

chmod()

36
Q

Which function is used to change the group of a file?

A

chgrp()

37
Q

Which function is used to change the size of a file?

A

trucate()

38
Q

Which function is used to remove a directory?

A

rmdir()

39
Q

Which function is used to make a directory?

A

mkdir()

40
Q

Which function is used to create a link?

A

link

41
Q

Which function is used to delete a link?

A

unlink