Skip to contentSkip to conversation

Write file in EXT2

DISCUSSION Sumit Narayan 2 participants 2 messages May 6, 2003

lore
Share & tools
lore
#0 lore raw

Thanks for the details,

But I would like to know when each FS is being accessed, and by which application. Isnt there a single path, say something in the driver code, from where all write/read commands pass? So that we can have a function call from that place, and create a log?

And also, how do I create a logfile on my own. With my own function within the kernel. I dont wish to go to Userland and do the write process.

Thanks in advance.

Sumit

--

Quoted 45 lines · On Tue, 6 May 2003 10:17:08 Matti Aarnio wrote:
Quoted 11 lines · Sumit Narayan

Hi,

I would like to create a log file containing the reads and writes made on a disk, by adding a function in the kernel. And once this log table reaches a limit, say 10,000 records, I would like it to be written on hard disk automatically. I am unable to do this, since I dont know how to write to a file, while in the kernel. I tried System Calls, but they dont seem to work. Could someone tell me what is the list of functions that I need to use to do this job. I think I have to play with super-blocks and inodes. But I dont know how to do that. :) Please help me.

Considering how to do that log writing:

Kernel contains several codes that are writing data to disk for various "logging" tasks. Most promimnent example of them is:

kernel/acct.c

It keeps kernel internal file descriptor ("filp") for its internal use. It has code that opens a file for writing to it, actual writer (one smallish block at the time, but that is merely size parameter issue), and it also closes the file when wanted (e.g. under administrator control).

All that completely independent of target filesystem.

Oh, and of course it has management interface, so that sysadmin can tell to it:
- when to activate / deactivate
- into which file to log

In your application there is a danger of snaring
yourself: disk activity must not stop at logging something, when the log buffer is full and flushing it is under way. Otherwise you are in danger of halting the log-flush, and then you have a dead machine.

Quoted 3 lines

Thanks.
Sumit

Quoted 9 lines
Quoted 1 line

p.s. I am using Kernel 2.4.20 and want this in EXT2 FS

/Matti Aarnio
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005

#1 lore raw
Quoted 7 lines · Sumit Narayan

Thanks for the details,

But I would like to know when each FS is being accessed, and by which application. Isnt there a single path, say something in the driver code, from where all write/read commands pass? So that we can have a function call from that place, and create a log?

The proper place for this is between the 'C' runtime library and the kernel. You can use ld.so.preload to attach your hooks into some code that communicates with a user-mode daemon and writes a log of the file-system activity.

This will not catch statically-linked programs or programs written in assembly that don't use the 'C' shared library, but these are not normal programs.

Quoted 4 lines

And also, how do I create a logfile on my own. With my own function within the kernel. I dont wish to go to Userland and do the write process.

Please fix your mail program, UNIX/Linux text has a control character after, roughly 79 characters, to continue the string on the left-hand side of the screen. This is unlike Windows that assumes you are peering into some RAM in a garbage dump.

Quoted 4 lines

Thanks in advance.

Sumit

You use a kernel thread. The kernel is designed to perform tasks on behalf of a caller. Therefore, it doesn't have a context. Therefore, a particular file-number doesn't mean anything without its association with some process ID. You can either steal the context of some unweary user and screw up its file-system access, or you can make your own process, called a kernel thread. A kernel thread has its own context so file system access works. However, you cannot call the kernel from within the kernel, so you can't use 'C' runtime libraries, etc. Instead, you call things like sys_open() to open a file, sys_close() to close it, etc.

Also, don't assume that /var/log actually exists. The kernel may be alive and well without a mounted file-system, and without anything writable in the file-system.

It is definitely not a good idea to perform file-system access from within your 'driver'. When you do this, you are not making a driver, but a kludge.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips). Why is the government concerned about the lunatic fringe? Think about it.