* EFAULT from file read. @ 2001-09-18 9:16 David Chow 2001-09-18 12:53 ` Richard B. Johnson 0 siblings, 1 reply; 4+ messages in thread From: David Chow @ 2001-09-18 9:16 UTC (permalink / raw) To: linux-kernel Dear all, I am having trouble in reading a file in the kernel space using the file->f_op->read call, everything is ok. I start off file->f_pos = 0 . I also did a mntget to the super block before I call "file=dentry_open(.....)" . I intend to open the file in read only mode. What can be wrong? I have also check the inode->i_size is large enough for me to just read 8 bytes from the file. I keep having EFAULT error from the read call... also before calling mntget, also did a dget to the dentry. Any help is welcomed. Thanks. regards, David Chow ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: EFAULT from file read. 2001-09-18 9:16 EFAULT from file read David Chow @ 2001-09-18 12:53 ` Richard B. Johnson 2001-09-18 13:04 ` Alexander Viro 0 siblings, 1 reply; 4+ messages in thread From: Richard B. Johnson @ 2001-09-18 12:53 UTC (permalink / raw) To: David Chow; +Cc: linux-kernel On Tue, 18 Sep 2001, David Chow wrote: > Dear all, > > I am having trouble in reading a file in the kernel space using the > file->f_op->read call, everything is ok. I start off file->f_pos = 0 . I > also did a mntget to the super block before I call > "file=dentry_open(.....)" . I intend to open the file in read only mode. > What can be wrong? I have also check the inode->i_size is large enough > for me to just read 8 bytes from the file. I keep having EFAULT error > from the read call... also before calling mntget, also did a dget to the > dentry. Any help is welcomed. Thanks. > > regards, > > David Chow > - Are you attempting file access in the kernel from a kernel-thread, or have you just decided to perform file access from some random kernel code? File I/O requires a process context. Your file descriptor means nothing unless associated with the process that opened the file. The kernel, itself, is not a process. It functions in the process context of the caller. Also file I/O sleeps and pages. You need to understand this before you attempt to access files from within the kernel. Normally, you don't access files from within the kernel. If you need file data for a driver for instance, you write an appropriate ioctl() function in your driver so a user-mode task can send the data to the driver. Your startup script inserts the module, then executes a program which initializes the module with the appropriate file data and initialization commands, all sent from user mode. Once the driver is initialized, the user-mode "starter" exits, freeing resources which would otherwise be trapped forever in your driver. Cheers, Dick Johnson Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips). I was going to compile a list of innovations that could be attributed to Microsoft. Once I realized that Ctrl-Alt-Del was handled in the BIOS, I found that there aren't any. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: EFAULT from file read. 2001-09-18 12:53 ` Richard B. Johnson @ 2001-09-18 13:04 ` Alexander Viro 2001-09-19 10:24 ` David Chow 0 siblings, 1 reply; 4+ messages in thread From: Alexander Viro @ 2001-09-18 13:04 UTC (permalink / raw) To: Richard B. Johnson; +Cc: David Chow, linux-kernel On Tue, 18 Sep 2001, Richard B. Johnson wrote: > File I/O requires a process context. Your file descriptor means > nothing unless associated with the process that opened the file. It fscking doesn't. He had clearly said that he calls file->f_op->read(), which has nothing whatsofuckingever to descriptors. Sod off and don't return until you learn to read. As for the original question - grep fro set_fs and you'll see what to do (basically, set_fs(KERNEL_DS) before the call of ->read() and restore afterwards). ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: EFAULT from file read. 2001-09-18 13:04 ` Alexander Viro @ 2001-09-19 10:24 ` David Chow 0 siblings, 0 replies; 4+ messages in thread From: David Chow @ 2001-09-19 10:24 UTC (permalink / raw) Cc: Richard B. Johnson, linux-kernel Alexander Viro ¼g¹D¡G > > On Tue, 18 Sep 2001, Richard B. Johnson wrote: > > > File I/O requires a process context. Your file descriptor means > > nothing unless associated with the process that opened the file. > > It fscking doesn't. He had clearly said that he calls file->f_op->read(), > which has nothing whatsofuckingever to descriptors. Sod off and don't > return until you learn to read. > > As for the original question - grep fro set_fs and you'll see what to > do (basically, set_fs(KERNEL_DS) before the call of ->read() and restore > afterwards). Problem solved by calling dummy=set_fs(KERNEL_DS) . But remember to call set_fs(dummy) to restore after the read. regards, David ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-09-19 10:28 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2001-09-18 9:16 EFAULT from file read David Chow 2001-09-18 12:53 ` Richard B. Johnson 2001-09-18 13:04 ` Alexander Viro 2001-09-19 10:24 ` David Chow
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox