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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:19:45+00:00 2026-06-13T18:19:45+00:00

I am writing a device driver for Linux. It creates a device with 4

  • 0

I am writing a device driver for Linux. It creates a device with 4 minor numbers. Whenever we attempt to write to the device at minor number 3, we are suppose to kill the device and currently it isn’t suppose to do anything else except print it is writing to the booga device. Here is some of my current code and I can post more code if necessary:

Write method:

static ssize_t booga_write (struct file *filp, const char *buf, size_t count, loff_t *f_pose) {
    printk("Attempting to write to booga device\n");
    /* need to protect this with a semaphore if multiple processes
       will invoke this driver to prevent a race condition */

    if (down_interruptible (&booga_device_stats->sem))
        return (-ERESTARTSYS);
    booga_device_stats->num_bytes_written += count; 
    up(&booga_device_stats->sem);
    return count; // pretend that count bytes were written

}

How it is tested:

static void run_write_test(char *device, int bufsize)
{
    char *buf;
    int src;
    int out;

    src = open(device, O_WRONLY);
    if (src < 0) {
        perror("Open for write failed:");
        exit(1);
    }
    buf = (char *) malloc(sizeof(char)*(bufsize+1));
    fprintf(stderr, "Attempting to write to booga device\n");
    out = write(src, buf, bufsize);
    fprintf(stderr, "Wrote %d bytes.\n", out);
    free(buf);
    close(src);

}

I am wondering if there is a way to get the minor number. I looked in linux/fs.h and saw that the file struct has a member called private_data but whenever I attempt to call this, it will crash my system as it is currently set to null.

Or should I not be trying to get the minor number from the struct file at all and should attempt to keep track of it when I first open the device?

  • 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-13T18:19:47+00:00Added an answer on June 13, 2026 at 6:19 pm

    You can get the minor number like so:

    iminor(filp->f_path.dentry->d_inode)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a device driver for a DMA device in Linux. In Linux
I'm writing a kernel object (.ko file, which is usually device driver) of Linux.
I'm learning about the blocking I/O functions for writing linux device driver and I'm
I am writing a Linux device driver which supports multiple devices. I have a
I'm new in writing Linux device driver, and I'm wondering how the kernel Makefile
I'm writing my first Linux kernel module, which actually is a RAM disk driver
I'm writing a device driver that is loaded by a 3rd-party driver. I need
I'm writing a driver and I want to get network counters of some device
I have a PCI device, its Linux driver, and a user-space application. The application
I'm currently writing a GNU/linux IRC bot to help me evaluate the kind of

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.