Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:18:33+00:00 2026-06-12T09:18:33+00:00

This may sound like an odd question, but when I go and open a

  • 0

This may sound like an odd question, but when I go and open a file:

int fd;
fd = open("/dev/somedevice", O_RDWR);

What exactly am I getting back? I can see the man page says:
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 that it? Is it just an int or is there data attached to it behind the scenes? The reason I’m asking is I found some code (Linux/C) where we’re opening 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 on the kernel end, the file operations for this module (which supplies the fd) map reads to the n_read() function:

struct file_operations can_fops = { 
    owner:      THIS_MODULE,
    lseek:  NULL, 
    read:   n_read,

Then the file descriptor is used in the n_read(), but it’s being accessed to get 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 figure what’s happening here is either:

A) a file descriptor returned from open() contains more data than just a descriptive integer value
Or
B)The mapping between a call to “read” in the user space isn’t as simple as I’m making it out to be and there’s some code missing in this equation.

Any input that might help direct me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:18:34+00:00Added an answer on June 12, 2026 at 9:18 am

    File descriptor is just an int. The kernel uses it as an index to a table containing all the related information, including file position, file ops (kernel functions that provide the read(), write(), mmap() etc. syscalls), and so on.

    When you open() a file or device, the kernel creates a new file descriptor entry for your process, and populates the internal data, including the file ops.

    When you use read(), write(), mmap(), etc. with a valid file descriptor, the kernel simply looks up the correct in-kernel function to call based on the file ops in the file descriptor table it has (and which the file descriptor indexes). It really is that simple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may sound like a very generic question but here it goes. I have
This may sound like a stupid question but I can't seem to find an
This may sound like a stupid question, perhaps it is. But I'm only trying
This may sound like a bit of a rhetorical question, but I ask it
This may sound like an unusual question, but I am curious as to how
This may sound like a stupid question but I'm a beginner not just to
This may sound like a silly question but in D (using std.regex ) how
This may sound like a stupid question, but can DI be used everywhere where
This may sound like a simple question, but I just cannot seem to find
I understand this may sound like an odd question.. I have a repo on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.