LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 05-11-2010, 02:13 AM   #1
chxooi
LQ Newbie
 
Registered: May 2010
Posts: 24

Rep: Reputation: 0
Kernel file access example.....


This example code is file access(read) into the kernel level..
There is "/tmp/rambo.txt"...

and open() is ok...

but, this function is not work...
I can see the error message...<data is NULL> return -14...

# pwd
/tmp
# ls -la
drwxrwxrwt 4 root 0 140 Jan 2 05:04 .
drwxrwxrwx 23 500 501 4096 May 11 2010 ..
-rwxrwxrwx 1 root 0 40 Jan 2 05:04 rambo.txt
#
# cat rambo.txt
abcdefgzjdkzdwdadasdoda90d12334afdaafaf
#

Code:
EXAMPLE CODE.....


    struct file * fd;
    char * filename="/tmp/rambo.txt";
    char *buff=NULL;
    printk("read function...\n");
    fd=sfile_open(filename,O_RDONLY,0);
    if (fd != NULL) {
        printk("OK.....\n");
        count=10;
        offset=0;
        sfile_read(fd,offset,buff,count);
        printk(" buff %s\n",buff);
    }else{
        printk("not ok\n");
    }

After example excutition
=============
read function...
OK.....
file_read...=
data is <NULL>,ret is -14

====================
What is the reason of "data is <NULL>".
Return is -14 is also problem...


Code:
#if 1
struct file* sfile_open(const char* path, int flags, int rights) {
    struct file* filp = NULL;
    mm_segment_t oldfs;
    int err = 0;
 
    oldfs = get_fs();
    set_fs(get_ds());
    filp = filp_open(path, flags, rights);
    set_fs(oldfs);
    if(IS_ERR(filp)) {
        err = PTR_ERR(filp);
        return NULL;
    }
    return filp;
}
void file_close(struct file* file) {
    filp_close(file, NULL);
}
 
int sfile_read(struct file* file, unsigned long long offset, unsigned char* data, unsigned int size) {
    mm_segment_t oldfs;
    int ret;
 
    printk("file_read...=\n");
    oldfs = get_fs();
    set_fs(get_ds());
 
    ret = vfs_read(file, data, size, &offset);
    printk("data is %s,ret is %d\n",data,ret);
 
    set_fs(oldfs);
    return ret;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
software to access file system.. how to allow access for non root users? stdcinout Linux - Newbie 8 03-09-2010 12:55 PM
Access control with access.conf file custangro Linux - Enterprise 4 06-02-2009 11:22 AM
PHP file download without direct file access prasepretep Programming 2 02-14-2008 05:34 AM
is any option to access ms-access file hitlar Fedora 2 09-08-2006 11:14 PM
Strange file access restrictions in kernel-headers directory zero79 Debian 3 04-30-2004 10:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 02:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration