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 7796471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:22:57+00:00 2026-06-01T23:22:57+00:00

I need to implement a Linux Kernel Driver, that (in the first step) only

  • 0

I need to implement a Linux Kernel Driver, that (in the first step) only forwards all file operations to another file (in later steps, this should be managed and manipulated, but I don’t want to discuss this here).

My idea is the following, but when reading, the kernel crashes:

static struct {
    struct file *file;
    char *file_name;
    int open;
} file_out_data = {
.file_name  = "/any_file",
.open       = 0, 
};


int memory_open(struct inode *inode, struct file *filp) {
  PRINTK("<1>open memory module\n");
    /* 
     * We don't want to talk to two processes at the same time 
     */
    if (file_out_data.open)
        return -EBUSY;
    /*
     * Initialize the message 
     */
    Message_Ptr = Message;
    try_module_get(THIS_MODULE);

        file_out_data.file = filp_open(file_out_data.file_name, filp->f_flags, filp->f_mode); //here should be another return handling in case of fail
    file_out_data.open++;

  /* Success */
  return 0;
}

int memory_release(struct inode *inode, struct file *filp) {
      PRINTK("<1>release memory module\n");
    /* 
     * We're now ready for our next caller 
     */
    file_out_data.open--;
    filp_close(file_out_data.file,NULL);

    module_put(THIS_MODULE);
  /* Success */
  return 0;
}

ssize_t memory_read(struct file *filp, char *buf, 
                    size_t count, loff_t *f_pos) { 
   PRINTK("<1>read memory module \n");
ret=file_out_data.file->f_op->read(file_out_data.file,buf,count,f_pos); //corrected one, false one is to find in the history
    return ret;

}

So, can anyone please tell me why?

  • 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-01T23:22:58+00:00Added an answer on June 1, 2026 at 11:22 pm
    1. Don’t use set_fs() as there is no reason to do it.
    2. Use file->f_fop->read() instead of the vfs_read. Take a look at the file and file_operations structures.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement a custom handler for MVC that gives me the first
I need to implement handling of redelivery of JMS messages in the application that
I need to implement something. Something that could do some certain task in my
I'm trying to implement user threads on a 2.4 Linux kernel (homework) and the
My requirement is to implement(insert ) an ip address validation step in kernel.. Once
I need to implement the following feature for my device running embedde linux on
I need to implement a handshake type protocol in to a small Linux program
I need to read a single file using multiple threads under Linux. There are
I need to implement a few commands of Linux shell for my homework -
I need to implement a daemon that needs to extract data from a database,

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.