linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How to allocate few bytes to a file automatically after creating it?
@ 2004-05-13  1:53 Vineet Joglekar
  2004-05-13  7:53 ` Charlie Gordon
  0 siblings, 1 reply; 2+ messages in thread
From: Vineet Joglekar @ 2004-05-13  1:53 UTC (permalink / raw)
  To: linux-c-programming


My aim is to allocate few bytes to a file; with some valid data in it as soon as it is created. Will the following approach work?

Calling the function ext2_direct_IO() with the appropriate parameters after creating a new inode. The appro. parameters are rw flag, inode, iobuf, blocknr, blocksize.
If I want to add just 100 bytes to the file, I guess blocknr should be 1 and blocksize should be 512 or 1024 .. is that right? Also, how to fill in  "iobuf" which is of the type "struct kiobuf *" to add these 100 bytes?

Please help.. I am trying to work on this problem for a long time now.

Thanks and regards,

Vineet

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!

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

* Re: How to allocate few bytes to a file automatically after creating it?
  2004-05-13  1:53 How to allocate few bytes to a file automatically after creating it? Vineet Joglekar
@ 2004-05-13  7:53 ` Charlie Gordon
  0 siblings, 0 replies; 2+ messages in thread
From: Charlie Gordon @ 2004-05-13  7:53 UTC (permalink / raw)
  To: linux-c-programming

> My aim is to allocate few bytes to a file; with some valid data in it as
soon as it is created. Will the following approach work?
>
> Calling the function ext2_direct_IO() with the appropriate parameters
after creating a new inode. The appro. parameters are rw flag, inode, iobuf,
blocknr, blocksize.
> If I want to add just 100 bytes to the file, I guess blocknr should be 1
and blocksize should be 512 or 1024 .. is that right? Also, how to fill in
"iobuf" which is of the type "struct kiobuf *" to add these 100 bytes?
>

Are you doing this from a driver ?
Fiddling with file system specific stuff seems overkill for your purpose.
If your goal is to make sure the file is non empty, with correct contents,
as soon as it appears in the file system, the classical method is to create
a new file with a temporary name with open(), write appropriate contents to
it with write(), close it, and then rename it to the correct name with
rename(), an atomic change to most file systems.  The only constraint is
that the file be created in the same file system.

If this doesn't solve your problem, what did I miss ?

Chqrlie.




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

end of thread, other threads:[~2004-05-13  7:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-13  1:53 How to allocate few bytes to a file automatically after creating it? Vineet Joglekar
2004-05-13  7:53 ` Charlie Gordon

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