file handling in kernel mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
I need to read a file from a device driver and i wrote a sample driver like this
 
This kernel mode code which try to read the file until end of file is reached. This code had been is working without any problems in RedHat linux and uClinux.
But the same code causes a General Protection Fault in my mips linux. I tested the same code in mips running on uClinux which runs well.
what is wrong with mips linux?
 
#define __KERNEL_SYSCALLS__
 
#include <linux/version.h>
#ifdef MODULE
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/module.h>
#else
#define MOD_INC_USE_COUNT
#define MOD_DEC_USE_COUNT
#endif
 
#include <linux/types.h>
#include <linux/unistd.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <asm/io.h>
int test_open(void );
int init_module(void)
{
        printk("\n init_module ");
        test_open();
        return 0;
}
void cleanup_module(void)
{
        printk("\n cleanup module");
}
int test_open(void )
{
    int ifp,bcount;
    mm_segment_t fs;
    char buffer[0x1000];
 
    // for file opening temporarily tell the kernel I am not a user for
    // memory management segment access
    fs = get_fs();
    set_fs(KERNEL_DS);
    // open the file with the firmware for uploading
    if (ifp = open( "/etc/hotplug/isl3890.arm", O_RDONLY, 0 ), ifp < 0)
    {
        // error opening the file
        printk( "ERROR: File opening did not success \n");
        set_fs(fs);
        return -1;
    }
    // enter a loop which reads data blocks from the file and writes them
    // to the Direct Memory Windows
    do
    {
            bcount = read(ifp, &buffer, sizeof(buffer));
            printk("\n bcount %x ",bcount);
    }
    while (bcount != 0);
    close(ifp);
    // switch back the segment setting
    set_fs(fs);
 
    return 0;
}
 
 
thanks & regards
durai

[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux