public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Reading from file in module fails
@ 2004-05-03 10:50 Libor Vanek
  2004-05-03 11:35 ` Erik Mouw
  0 siblings, 1 reply; 7+ messages in thread
From: Libor Vanek @ 2004-05-03 10:50 UTC (permalink / raw)
  To: linux-kernel

Hi,
I'm writing module which needs to read from file. I've got this simple sample code:

char buffer[4096];
ssize_t read;
file *f;
f = filp_open("/some/file",O_RDONLY | O_LARGEFILE,0);
f->f_pos = 0;
read = vfs_read(f,(char __user *) buffer,4096,&f->f_pos);

but here read value is "-14" (-EINVAL?) Does anybody has idea what's wrong? 

It seems that file is opened OK (I've tested:
if (f->f_op->read) {
	read = f->f_op->read(file, buf, count, pos);
}
and result was the same - so I assume that file is opened OK and structure "file f" is filled correctly.


I need to copy files (yes - I know that kernel shouldn't do this but I REALLY need) and there is nothing like "sys_copy" and "sys_sendfile" is not exported (which seems strange to me but there is nothing like EXPORT_SYMBOL(sys_sendfile) in fs/read_write.c


Thanks,
Libor Vanek


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Reading from file in module fails
  2004-05-03 10:50 Libor Vanek
@ 2004-05-03 11:35 ` Erik Mouw
  2004-05-03 11:43   ` Libor Vanek
  0 siblings, 1 reply; 7+ messages in thread
From: Erik Mouw @ 2004-05-03 11:35 UTC (permalink / raw)
  To: Libor Vanek; +Cc: linux-kernel

On Mon, May 03, 2004 at 12:50:41PM +0200, Libor Vanek wrote:
> I need to copy files (yes - I know that kernel shouldn't do this but
> I REALLY need).

This is ugly, but it should do the trick:

int rv;
char *argv[4] = {"/bin/cp", "/tmp/foo", "/tmp/bar", NULL};
char *envp[3] = {"HOME=/", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL};

rv = call_usermodehelper(argv[0], argv, envp, 1);

if(rv < 0) {
	/* error handling */
}

Called from kernel, done in userspace. And if you want to access an SQL
database from kernel tomorrow, it's just a matter of changing the
usermode helper.

(BTW, if you need to copy files from kernel, it's usually a sign of bad
design)


Erik

-- 
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Reading from file in module fails
  2004-05-03 11:35 ` Erik Mouw
@ 2004-05-03 11:43   ` Libor Vanek
  2004-05-03 11:48     ` Erik Mouw
  2004-05-03 12:41     ` Jan-Benedict Glaw
  0 siblings, 2 replies; 7+ messages in thread
From: Libor Vanek @ 2004-05-03 11:43 UTC (permalink / raw)
  To: Erik Mouw; +Cc: linux-kernel

> > I need to copy files (yes - I know that kernel shouldn't do this but
> > I REALLY need).
> 
> This is ugly, but it should do the trick:
> 
> int rv;
> char *argv[4] = {"/bin/cp", "/tmp/foo", "/tmp/bar", NULL};
> char *envp[3] = {"HOME=/", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL};
> 
> rv = call_usermodehelper(argv[0], argv, envp, 1);
> 
> if(rv < 0) {
> 	/* error handling */
> }
> 
> Called from kernel, done in userspace. And if you want to access an SQL
> database from kernel tomorrow, it's just a matter of changing the
> usermode helper.
> 
> (BTW, if you need to copy files from kernel, it's usually a sign of bad
> design)

Geez - that's REALLY ugly :-) But for testing I can use it.

It's not bad design - what I'm doing is writing snapshots for VFS as my diploma thesis. And I need to create copy of file before it's changed (copy-on-write). There is no other way how to do it in kernel-space (and user-space solutions like using LUFS are really slow)

Thx,
Libor



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Reading from file in module fails
  2004-05-03 11:43   ` Libor Vanek
@ 2004-05-03 11:48     ` Erik Mouw
  2004-05-03 12:07       ` root
  2004-05-03 12:41     ` Jan-Benedict Glaw
  1 sibling, 1 reply; 7+ messages in thread
From: Erik Mouw @ 2004-05-03 11:48 UTC (permalink / raw)
  To: Libor Vanek; +Cc: linux-kernel

On Mon, May 03, 2004 at 01:43:16PM +0200, Libor Vanek wrote:
> > (BTW, if you need to copy files from kernel, it's usually a sign of bad
> > design)
> 
> It's not bad design - what I'm doing is writing snapshots for VFS as
> my diploma thesis. And I need to create copy of file before it's
> changed (copy-on-write). There is no other way how to do it in
> kernel-space (and user-space solutions like using LUFS are really
> slow)

Have a look at the cowlinks (copy-on-write links) thread from last
month, it might do the trick.


Erik

-- 
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Reading from file in module fails
  2004-05-03 11:48     ` Erik Mouw
@ 2004-05-03 12:07       ` root
  0 siblings, 0 replies; 7+ messages in thread
From: root @ 2004-05-03 12:07 UTC (permalink / raw)
  To: Erik Mouw; +Cc: linux-kernel

On Mon, May 03, 2004 at 01:48:59PM +0200, Erik Mouw wrote:
> On Mon, May 03, 2004 at 01:43:16PM +0200, Libor Vanek wrote:
> > > (BTW, if you need to copy files from kernel, it's usually a sign of bad
> > > design)
> > It's not bad design - what I'm doing is writing snapshots for VFS as
> > my diploma thesis. And I need to create copy of file before it's
> > changed (copy-on-write). There is no other way how to do it in
> > kernel-space (and user-space solutions like using LUFS are really
> > slow)
> Have a look at the cowlinks (copy-on-write links) thread from last
> month, it might do the trick.

Hmmm, that seems to have several serious disadvantages:
- it's not filesystem/user-space SW independent (requires modifying them - as far as I understand how it's done)
- needs to "touch" all existing files/dirs (maybe I'm wrong but from very first look it seems to me that I need to setup "cow" flag on each file/dir I want to "cow") - my approach should be "atomic" even when I need to setup snapshot on directory containing 100s thousands of files/dirs (and that's an average server I'm thinking of!)

Nevertheless - thanks for a tip.

Libor

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Reading from file in module fails
  2004-05-03 11:43   ` Libor Vanek
  2004-05-03 11:48     ` Erik Mouw
@ 2004-05-03 12:41     ` Jan-Benedict Glaw
  1 sibling, 0 replies; 7+ messages in thread
From: Jan-Benedict Glaw @ 2004-05-03 12:41 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 955 bytes --]

On Mon, 2004-05-03 13:43:16 +0200, Libor Vanek <libor@conet.cz>
wrote in message <20040503114316.GA22732@Loki>:
> It's not bad design - what I'm doing is writing snapshots for VFS as my diploma thesis. And I need to create copy of file before it's changed (copy-on-write). There is no other way how to do it in kernel-space (and user-space solutions like using LUFS are really slow)

That can all be done in userspace.

$ export LD_PRELOAD=libcopyfilesbeforemodify.so

You just need to program a library that provides all functions that
modify files (eg. write, open with O_CREAT, ...) and you're done - 100%
in userspace.

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Reading from file in module fails
       [not found]     ` <1RL3A-23k-23@gated-at.bofh.it>
@ 2004-05-03 16:55       ` Pascal Schmidt
  0 siblings, 0 replies; 7+ messages in thread
From: Pascal Schmidt @ 2004-05-03 16:55 UTC (permalink / raw)
  To: Jan-Benedict Glaw; +Cc: linux-kernel

On Mon, 03 May 2004 14:50:10 +0200, you wrote in linux.kernel:

> That can all be done in userspace.
>
> $ export LD_PRELOAD=3Dlibcopyfilesbeforemodify.so
>
> You just need to program a library that provides all functions that
> modify files (eg. write, open with O_CREAT, ...) and you're done - 100%
> in userspace.

This won't catch asm programs that do syscalls by hand or statically
linked programs. If you really need to catch all write accesses, it
needs to be done in the kernel, probably as an LSM hook or something.

-- 
Ciao,
Pascal

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-05-03 16:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1RJl8-Eo-5@gated-at.bofh.it>
     [not found] ` <1RJXT-19T-37@gated-at.bofh.it>
     [not found]   ` <1RK7v-1gJ-9@gated-at.bofh.it>
     [not found]     ` <1RL3A-23k-23@gated-at.bofh.it>
2004-05-03 16:55       ` Reading from file in module fails Pascal Schmidt
2004-05-03 10:50 Libor Vanek
2004-05-03 11:35 ` Erik Mouw
2004-05-03 11:43   ` Libor Vanek
2004-05-03 11:48     ` Erik Mouw
2004-05-03 12:07       ` root
2004-05-03 12:41     ` Jan-Benedict Glaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox