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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:03:29+00:00 2026-05-29T06:03:29+00:00

I am new to linux and was making a module in which user can

  • 0

I am new to linux and was making a module in which user can read as well as write to a device file.the following is my code where read is working fine but not the write function.

MODULE_LICENSE("DUAL BSD/GPL");

char message[80];
char *msg_ptr;

int dev_major = 0;
int dev_minor = 0;

struct cdev *cdev;

ssize_t dev_read(struct file *filp,char __user *buf,size_t count,loff_t *offset)
{
int i;
i=copy_to_user(buf,msg_ptr,count);
 printk(KERN_ALERT"buff:%s",buf);


return 0;
 }
  ssize_t dev_write(struct file *filp,const char __user *buf,size_t count,loff_t *offset)
{
  int j;
    msg_ptr = kmalloc(sizeof(*buf),GFP_KERNEL);
    copy_from_user(msg_ptr,buf,sizeof(*buf));
 //printk(KERN_ALERT"msg_ptr:%s",msg_ptr);
  return 0;
      }

when i make a char node and then use echo hi >/dev/my_dev then it prints hi but writes infintely as seen in /var/log/messages.

  • 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-29T06:03:30+00:00Added an answer on May 29, 2026 at 6:03 am

    dev_write should return the number of bytes written.
    When you return 0, Linux understand you wrote 0 bytes, and calls you again to write the rest. And again…

    Same for dev_read.

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

Sidebar

Related Questions

I am rather new to Linux device driver programmring, but for debugging purposes, I
For an everyday-user with new hardware Linux seems for me the natural choice if
Till now I had been using following code to ftp file from one location
I'm a relatively new linux and rails dev and I'm attempting the following setup:
I'm making a game which you can see here, if you are on Windows
New to Linux programming in general. I am trying to communicate with a kernel
I'm new to Linux and have inherited keeping our single linux server running. It's
I am new to Linux and I am attempting to install the PHP PEAR
I am trying to build a script (I'm pretty new to linux scripting) and
I'm setting up a new RedHat Enterprise Linux 5 system to host Ruby apps

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.