Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I am writing a simple kernel module which is to open() a file, read() some information from it, and close() it. As far as I know, all three of ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    3

    kernel module development problem

    Hi,

    I am writing a simple kernel module which is to open() a file, read() some information from it, and close() it. As far as I know, all three of these functions are system calls and are provided by the kernel. Compiler warns me:
    "sdlm.c:10: warning: implicit declaration of function `open'
    sdlm.c:14: warning: implicit declaration of function `read'
    sdlm.c:16: warning: implicit declaration of function `close'",
    but builds the .ko module.

    When sdlm.ko is inserted, an error occurs:
    sdlm: Unknown symbol read
    sdlm: Unknown symbol open
    sdlm: Unknown symbol close

    Please help me, what's the problem?


    here is my code:
    Code:
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/unistd.h>
    #include <linux/fcntl.h>
    
    int     init_module()
    {
        int fd;
        printk(KERN_INFO "SDL start");
    
        fd = open("/var/license.dat", O_RDWR, S_IRWXU);
        if (fd != -1)
        {
            char banner[200] = "";
            read(fd, banner, 199);
            printk(KERN_NOTICE "License data: `%s`", banner);
            close(fd);
        }
        else
            printk(KERN_NOTICE "License file not found");
    
        return 0;
    }
    
    void    cleanup_module()
    {
        printk(KERN_INFO "SDL exit");
    }

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    You can't use C library functions in the kernel.
    Also this should be posted int the kernel section of this forum.

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    3
    but those functions are not library functions, they are system calls and they are defined in <linux/unistd.h> file in kernel sources

    OK then, one more question, how can I manage with files from kernel space?

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    I posted a very similar question in this forum under the kernel section. The posting is called "Writing to a file from a kernel module???". You should check it out...Hope this helps...Gerard4143

  5. #5
    Just Joined!
    Join Date
    Oct 2008
    Posts
    3
    thank you Gerard, but I still believe this is possible...

  6. #6
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Of course its possible...but is it worth the effort to hack this functionality into the kernel. With that said, if you do find a solution post it I'd like to see it...Geard4143

Posting Permissions

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