| To: | <linux-mips@linux-mips.org> |
|---|---|
| Subject: | file handling in kernel mode |
| From: | "durai" <durai@isofttech.com> |
| Date: | Sun, 16 Nov 2003 14:30:05 +0530 |
| Original-recipient: | rfc822;linux-mips@linux-mips.org |
| References: | <92F2591F460F684C9C309EB0D33256FA01B750B8@trid-mail1.tridentmicro.com> <20031115125329.GA324@linux-mips.org> |
| Sender: | linux-mips-bounce@linux-mips.org |
|
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 |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: question regarding put data in the specified section, Ralf Baechle |
|---|---|
| Next by Date: | Re: SNI RM200, Martin Michlmayr |
| Previous by Thread: | Re: question regarding put data in the specified section, Ralf Baechle |
| Next by Thread: | Re: file handling in kernel mode, Ralf Baechle |
| Indexes: | [Date] [Thread] [Top] [All Lists] |