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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:55:07+00:00 2026-06-18T03:55:07+00:00

I wrote h into driver by doing echo: echo -n h /dev/mydriver When I

  • 0

I wrote h into driver by doing echo:
echo -n h /dev/mydriver

When I do cat /dev/mydriver, myread function is printing h continuously. I wanted to print once. How to do that.

static char m;

static ssize_t myread(struct file *f, char __user *buf, size_t len, loff_t *off)
{
    printk(KERN_INFO "Read()\n");
    if (copy_to_user(buf, &m, 1) != 0)
        return -EFAULT;
    else
        return 1;
}

static ssize_t my_write(struct file *f, const char __user *buf, size_t len, loff_t *off)
{
    printk(KERN_INFO "Write()\n");
    if (copy_from_user(&c, buf + len – 1, 1) != 0)
        return -EFAULT;
    else
        return len;
}
  • 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-18T03:55:08+00:00Added an answer on June 18, 2026 at 3:55 am

    If you want to use standard tools (such as cat) with your custom drivers, do not forget to set offset (*loff_t off) correctly. Your read function should look something like this:

    static ssize_t myread(struct file *f, char __user *buf, size_t len, loff_t *off)
    {
        printk(KERN_INFO "Read()\n");
    
        /* You have just a single char in your buffer, so only 0 offset is valid */
        if(*off > 0)
            return 0; /* End of file */
    
        if (copy_to_user(buf, &m, 1))
            return -EFAULT;
    
        *off++;
        return 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert an old Delphi program I wrote into Java to compile
I just wrote this into my WebForms .aspx: <span id=GenerateChartButton runat=server></span> I went to
In serialization mechanism,we are wrote the object into stream using objectinputstream and object outputstream.These
I wrote this query: INSERT INTO KeysTable (KeyText, Id) SELECT KeyText as BKT, KeysTable.ID
I wrote a perl script a while ago which logged into my online banking
before this I wrote all jquery-code into main fail. Now I want to move
I am looking into making a text based game that I wrote in Haskell
I wrote a query in this format.. Select * INTO #xyz FROM () which
I have wrote a method to convert any layout Liner,Relative,Frame etc into Bitmap but
I just wrote a RTC driver for an NXP RTC chip on my board,

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.