File I/O Flashcards

1
Q

6 basic I/O system calls

A
  1. open()
  2. write()
  3. read()
  4. close()
  5. lseek()
  6. fcntl()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Flags in open()

A

Specifies access and creation mode, i.e.
O_WRONLY, O_RDWR, O_CREAT, etc.

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

Mode in open()

A

Specifies file permission if file is created using O_CREAT or O_TMPFILE

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

File descriptor

A

A small, non-negative integer used as a handle for a particular file to read/write to
Can change each time the file is opened

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

File offset

A

The file offset is a pointer to a specific byte in a file we are reading/writing to
read() automatically increments the file offset, write() starts at the end and increments to end each time

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

lseek()

A

Used to manually adjust the file offset, 3 parameters: fd, offset, whence - adjusts file offset by offset bytes, specified by ‘whence’ which can be:
SEEK_SET - beginning of file
SEEK_CUR - current offset
SEEK_END - end of the file

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

Stream vs. File Descriptor

A

A stream is a “wrapper” around a file descriptor that also has a buffer attached to it

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

Buffered I/O vs. system calls

A

Buffered I/O writes to a buffer before making a system call because system calls are costly

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

fflush()

A

immediately sends buffered data to the kernel - setbuf(NULL) does the same thing

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

Blocking vs Nonblocking

A

Blocking call doesn’t return until the operation can be done, a nonblocking call will return anyway (usually w/ an error)

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

Everything is a File model

A

Everything is represented as a file including hardware like keyboard, mouse, and others like the terminal

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

Disk Partitions

A

A disk is divided into partitions - can be found at /proc/partitions - usually used as a file system, also used as swap space

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

File System

A

a system that manages files/directories, each system has a file tree that starts with root directory /

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

i-node

A

An i-node contains metadata for every file, i.e. type, permissions, owner, etc. - identified by a number

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

Hard link

A

Giving another name to an existing file - will have the same metadata and content

Hard links can’t be made on directories or outside the same file system

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

Soft/symbolic link

A

A soft link is an actual file where the content is the path to the original file
Can be used on directories and between file systems

17
Q

Setuid Bit

A

If set, the user that runs the program can act as the owner of the program

18
Q

Setgid Bit

A

If set, the user that runs the program can act as if the user belonged to the group of the program

19
Q

Sticky bit

A

If set on a directory, a user can delete a file under it only

20
Q

VFS (virtual file system)

A

Defines an interface that different file systems can implement such as open, read, write, etc.

21
Q

Mounting/Unmounting

A

Different file systems can be mounted to others to create a single file tree