Find the answer to your Linux question:
Results 1 to 1 of 1
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Bassano, Italy

    ldd3: user-space program writing data to scull device

    Hello everybody!
    I'm reading the book Linux Device Drivers third edition.

    I want a user space program that read a buffer from an input file and writes it down to /dev/scull.

    this code works only for small files (less than 1024 bytes):
    while ((nread = read(fromfd, buf, sizeof(buf))) > 0) {
      	int part;
      	part = write(devfd, buf, nread);
      	if ((part) != nread){
    where fromfd is the input-file file-descriptor
    buf is a 512 buffer // I may change the size of this buffer
    devfd = open("/dev/scull", O_RDWR); // the scull device file descriptor

    but with larger files I got this output (lager the file, longer the output):

    /dev/scull: Illegal seek
    /dev/scull: Illegal seek
    /dev/scull: Illegal seek

    I can't figure out why !
    I apreciate any kind of suggestion!

    Thanks in advance

    I figured out 416 being the bytes actually written

    Also I found at page 68 of Linux Device Driver the explaination of my problem:
    Unfortunately, there may still be misbehaving programs that issue an error message and abort when a partial transfer is performed.
    This happens because some programmers are accustomed to seeing write calls that either fail or succeed completely, which is actually what happens most of the time and should be supported by devices as well.
    This limitation in the scull implementation could be fixed, but we didnít
    want to complicate the code more than necessary.
    So, if I am right I have two options:
    1- reiterate the write() call in the user-space program
    2- fix this limitation in scull implementation

    I can manage to implement 1 but I'd like solution 2 better because I want to keep user-programs as simple as possible (thus making my device better). any ideas?
    Last edited by luca; 05-27-2009 at 02:57 PM. Reason: 416 is not an error code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts