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

  • Home
  • SEARCH
  • 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 6877001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:32:51+00:00 2026-05-27T04:32:51+00:00

I’m working on a project where I must open a directory and read the

  • 0

I’m working on a project where I must open a directory and read the files/directories inside at kernel level. I’m basically trying to find out how ls is implemented at kernel level.

Right now I’ve figured out how to get a file descriptor for a directory using sys_open() and the O_DIRECTORY flag, but I don’t know how to read the fd that I receive. If anyone has any tips or other suggestions I’d appreciate it. (Keep in mind this has to be done at kernel level).

Edit:For a long story short, For a school project I am implementing file/directory attributes. Where I’m storring the attributes is a hidden folder at the same level of the file with a given attribute. (So a file in Desktop/MyFolder has an attributes folder called Desktop/MyFolder/.filename_attr). Trust me I don’t care to mess around in kernel for funsies. But the reason I need to read a dir at kernel level is because it’s apart of project specs.

  • 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-05-27T04:32:52+00:00Added an answer on May 27, 2026 at 4:32 am

    To add to caf’s answer mentioning vfs_readdir(), reading and writing to files from within the kernel is is considered unsafe (except for /proc, which acts as an interface to internal data structures in the kernel.)

    The reasons are well described in this linuxjournal article, although they also provide a hack to access files. I don’t think their method could be easily modified to work for directories. A more correct approach is accessing the kernel’s filesystem inode entries, which is what vfs_readdir does.

    Inodes are filesystem objects such as regular files, directories, FIFOs and other
    beasts. They live either on the disc (for block device filesystems)
    or in the memory (for pseudo filesystems).

    Notice that vfs_readdir() expects a file * parameter. To obtain a file structure pointer from a user space file descriptor, you should utilize the kernel’s file descriptor table.

    The kernel.org files documentation says the following on doing so safely:

    To look up the file structure given an fd, a reader
    must use either fcheck() or fcheck_files() APIs. These
    take care of barrier requirements due to lock-free lookup.
    An example :

        rcu_read_lock();
        file = fcheck_files(files, fd);
        if (file) {
            // Handling of the file structures is special. 
            // Since the look-up of the fd (fget() / fget_light()) 
            // are lock-free, it is possible that look-up may race with 
            // the last put() operation on the file structure. 
            // This is avoided using atomic_long_inc_not_zero() on ->f_count
            if (atomic_long_inc_not_zero(&file->f_count))
                *fput_needed = 1;
            else
            /* Didn't get the reference, someone's freed */
                file = NULL;
        }
        rcu_read_unlock();
        ....
        return file;
    

    atomic_long_inc_not_zero() detects if refcounts is already zero or
    goes to zero during increment. If it does, we fail fget() / fget_light().

    Finally, take a look at filldir_t, the second parameter type.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need to

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.