chapter 39 - interlude: files and directories Flashcards

1
Q

what is a file

A

a linear sequence of bytes identified by an inode number

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

What is a directory?

A

A special file mapping user-readable names to inode numbers

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

What is a directory tree?

A

A hierarchy starting from root /, containing nested directories and files

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

what does int fd = open(“foo”, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); do

A
  • O_CREAT → create if not exist
  • O_WRONLY → open for writing
  • O_TRUNC → empty the file if it exists
  • S_IRUSR | S_IWUSR → user can read/write
  • Returns a file descriptor, placed in the process’s ofile[NOFILE] array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a file descriptor?

A

A per-process integer used to access an open file

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

What does read(fd, buf, size) do?

A

Reads size bytes into buf from file fd, and updates the offset

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

What does write(fd, buf, size) do?

A

Writes size bytes from buf to file fd, also updating the offset

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

What does lseek(fd, offset, whence) do?

A

Moves the file offset (SEEK_SET, SEEK_CUR, or SEEK_END)

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

What is stored in the Open File Table?

A

Read/write flags, inode pointer, offset, and reference count

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

What happens after fork() to file descriptors?

A

Child gets copies of parent’s FDs, sharing the same offset and inode

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

What does dup(fd) do?

A

Duplicates fd, both share offset, inode, and permissions

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

What does fsync(fd) do?

A

Forces all dirty data for that file to disk immediately

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

What does rename(“old”, “new”) do?

A

Atomically renames a file; ensures no corruption even during crashes

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

What does stat() or fstat() return?

A

Metadata like inode, size, permissions, owner, and timestamps

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

What does unlink() do?

A

Removes a file; deletes it once all links and open FDs are gone

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