linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Write file in EXT2
@ 2003-05-06 14:52 Sumit Narayan
  2003-05-07 16:55 ` Amol P Dharmadhikari
  0 siblings, 1 reply; 7+ messages in thread
From: Sumit Narayan @ 2003-05-06 14:52 UTC (permalink / raw)
  To: fdavis; +Cc: linux-kernel

Hi,

Thanks for the details.

I wish to know which application access which file, when.. etc etc. I would like to create a log of that. I am unable to write this log to the file from within the kernel. I would not like to go to the user level programs. I am doing this from within the kernel, as I would like to know exactly when things are being done.

Regards,
Sumit
--

On Tue, 06 May 2003 01:06:45  
 Frank Davis wrote:
>Sumit,
>
>In fact, if you're looking at journalizing ext2, ext3 has already done it.
>
>Regards,
>Frank
>
>Frank Davis wrote:
>> Sumit,
>> 
>> Why do you have to do this in the kernel? I can envision doing printks 
>> after each read and write call, and having a userland program receive 
>> the kernel output, storing it into a buffer, and then writing that 
>> buffer, either using fprintf, or fflush, etc.
>> 
>> Regards,
>> Frank
>> 
>> Sumit Narayan wrote:
>> 
>>> 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.
>>> Thanks.
>>> Sumit
>>>
>>> p.s. I am using Kernel 2.4.20 and want this in EXT2 FS
>>>
>>>
>>> ____________________________________________________________
>>> Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
>>> http://login.mail.lycos.com/r/referral?aid=27005
>>> -
>>> To unsubscribe from this list: send the line "unsubscribe 
>>> linux-kernel" in
>>> the body of a message to majordomo@vger.kernel.org
>>> 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

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

* Re: Write file in EXT2
  2003-05-06 14:52 Write file in EXT2 Sumit Narayan
@ 2003-05-07 16:55 ` Amol P Dharmadhikari
  0 siblings, 0 replies; 7+ messages in thread
From: Amol P Dharmadhikari @ 2003-05-07 16:55 UTC (permalink / raw)
  To: Sumit Narayan; +Cc: fdavis, linux-kernel

Hello,

> Hi,
> 
> Thanks for the details.
> 
> I wish to know which application access which file, when.. etc etc. I would like to create a log of that. I am unable to write this log to the file from within the kernel. I would not like to go to the user level programs. I am doing this from within the kernel, as I would like to know exactly when things are being done.

As Richard said in reply to your earlier email, when you are doing file
I/O, you need to store the file descriptor of the open file in some
process's fd table. If you "simply open" a file in the kernel, it is
meaningless. The kernel just executes on behalf of the currently running
process and does not have an execution context itself.

So the idea is to create a kernel thread, and open the log file in its
context. Also, you want to be sure that the filesystem on which the file
you are accessing is mounted when you call the sys_open function. Else
the first write to it might cause a panic. 

-- 
Amol P Dharmadhikari <apdharmadhikari@usfca.edu>

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

* Re: Write file in EXT2
  2003-05-06 14:45 Sumit Narayan
@ 2003-05-06 15:34 ` Richard B. Johnson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard B. Johnson @ 2003-05-06 15:34 UTC (permalink / raw)
  To: Sumit Narayan; +Cc: Matti Aarnio, linux-kernel

On Tue, 6 May 2003, Sumit Narayan wrote:

> 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.

> 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.

> 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.


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

* Re: Write file in EXT2
@ 2003-05-06 14:45 Sumit Narayan
  2003-05-06 15:34 ` Richard B. Johnson
  0 siblings, 1 reply; 7+ messages in thread
From: Sumit Narayan @ 2003-05-06 14:45 UTC (permalink / raw)
  To: Matti Aarnio; +Cc: linux-kernel

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

--

On Tue, 6 May 2003 10:17:08   
 Matti Aarnio wrote:
>On Mon, May 05, 2003 at 11:14:46PM -0400, Sumit Narayan wrote:
>> 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.
>
>> Thanks.
>> Sumit
>> 
>> 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 majordomo@vger.kernel.org
>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

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

* Re: Write file in EXT2
  2003-05-06  3:14 Sumit Narayan
  2003-05-06  4:10 ` Valdis.Kletnieks
@ 2003-05-06  7:17 ` Matti Aarnio
  1 sibling, 0 replies; 7+ messages in thread
From: Matti Aarnio @ 2003-05-06  7:17 UTC (permalink / raw)
  To: Sumit Narayan; +Cc: linux-kernel

On Mon, May 05, 2003 at 11:14:46PM -0400, Sumit Narayan wrote:
> 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.

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

/Matti Aarnio

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

* Re: Write file in EXT2
  2003-05-06  3:14 Sumit Narayan
@ 2003-05-06  4:10 ` Valdis.Kletnieks
  2003-05-06  7:17 ` Matti Aarnio
  1 sibling, 0 replies; 7+ messages in thread
From: Valdis.Kletnieks @ 2003-05-06  4:10 UTC (permalink / raw)
  To: sumit_uconn; +Cc: linux-kernel

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

On Mon, 05 May 2003 23:14:46 EDT, Sumit Narayan <sumit_uconn@lycos.com>  said:
> 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

Have you considered looking at the ext3 file system, which is basically ext2
with a journal?

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

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

* Write file in EXT2
@ 2003-05-06  3:14 Sumit Narayan
  2003-05-06  4:10 ` Valdis.Kletnieks
  2003-05-06  7:17 ` Matti Aarnio
  0 siblings, 2 replies; 7+ messages in thread
From: Sumit Narayan @ 2003-05-06  3:14 UTC (permalink / raw)
  To: linux-kernel

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.
Thanks.
Sumit

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


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

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

end of thread, other threads:[~2003-05-07 16:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-06 14:52 Write file in EXT2 Sumit Narayan
2003-05-07 16:55 ` Amol P Dharmadhikari
  -- strict thread matches above, loose matches on Subject: below --
2003-05-06 14:45 Sumit Narayan
2003-05-06 15:34 ` Richard B. Johnson
2003-05-06  3:14 Sumit Narayan
2003-05-06  4:10 ` Valdis.Kletnieks
2003-05-06  7:17 ` Matti Aarnio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).