This may sound like a weird question, but when I go and open the file:
int fd; fd = open("/dev/somedevice", O_RDWR);
What exactly am I coming back from? I see the manual page saying:
The open() function shall return a file descriptor for the named file that is the lowest file descriptor not currently open for that process
But is it? Is it just an int or is there any data attached to it backstage? The reason I'm asking is to find the code (Linux / C) where we open the file from user space:
//User space code: int fdC; if ((fdC = open(DEVICE, O_RDWR)) < 0) { printf("Error opening device %s (%s)\n", DEVICE, strerror(errno)); goto error_exit; } while (!fQuit) { if ((nRet = read(fdC, &rx_message, 1)) > 0) {
then at the end of the kernel the file operation for this module (which supplies the fd card) is read in the n_read() function:
struct file_operations can_fops = { owner: THIS_MODULE, lseek: NULL, read: n_read,
Then the file descriptor is used in n_read() , but it is accessed to get the data:
int n_read(struct file *file, char *buffer, size_t count, loff_t *loff) { data_t * dev; dev = (data_t*)file->private_data;
So ... I suppose what happens here:
A) the file descriptor returned from open() contains more data than just a descriptive integer value
Or
B) The mapping between the βreadβ call in user space is not as simple as I do, and there is no code in this equation.
Any input that can help me?