0

I am reading about device drivers and I have a question related to the UNIX philosophy regarding everything as file.

When a user issues a command say for eg, opening a file then what comes into action - System call or File Operation? sys_open is a system call and open is a file operation. Can you please elaborate on the topic.

Thanks in advance.

alk
  • 69,737
  • 10
  • 105
  • 255
shingaridavesh
  • 921
  • 1
  • 9
  • 19

2 Answers2

1

Quick answer, I hope it'll help:

All system calls work the same way. The system call number is stored somewhere (e.g. in a register) together with the system call parameters. In case of open system calls parameters are: pointer to the filename and permissions string. Then the open function raises a software interruption using the adequate intruction (syscall, int ..., it depends on the HW).

As for any interruption, the kernel is invoked (in kernel mode) to handle the interruption. The system detects that the interruption was caused by a system call, then read the system call number in the register sees it is a open system call, create the file descriptor in the kernel memory and proceed to actually open the file by calling the driver open function. The file descriptor id is then stored back into a register and returns to user mode.

The file descriptor is then retrieved from the register and returned by open().

Ben
  • 7,372
  • 8
  • 38
  • 46
  • Okay thanks a lot. So u mean to say that when user invokes a request system call is called and that in turns uses file operations? – shingaridavesh Oct 16 '12 at 03:46
  • @shingaridavesh If by file operations you mean actually writing on the drive then yes, the system does it for the user (with the help of a driver). The user has no mean to do it. – Ben Oct 16 '12 at 09:32
  • so in case of device driver file operations and system call point to same thing, as in system call open will point to open.c(linux/fs/open.c) or fops defined in driver? – shingaridavesh Nov 15 '12 at 06:56
0

"Each open file (represented internally by a file structure, which we will examine shortly) is associated with its own set of functions (by including a field called f_op that points to a file_operations structure). The operations are mostly in charge of implementing the system calls and are therefore, named open, read, and so on."

This is from LDD chapter Character Driver. can anyone please elaborate that what does the last line mean.

shingaridavesh
  • 921
  • 1
  • 9
  • 19