How to allocate few bytes to a file automatically after creating it? - Help

This is a discussion on How to allocate few bytes to a file automatically after creating it? - Help ; 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. ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: How to allocate few bytes to a file automatically after creating it?

  1. How to allocate few bytes to a file automatically after creating it?

    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

  2. Re: How to allocate few bytes to a file automatically after creatingit?

    Vineet Joglekar wrote:
    > 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?


    It depends on the language. At the shell level, you could do:

    cat filename
    [type a few bytes of valid data here]
    ^D

    If writing in C,

    fd = open(file, ...

    write(fd, bufferwithvaliddata, sizeofvaliddata);

    and so on.

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


    I worked for a company one summer on a little one-man project. It was a
    summer job.

    I then graduated from college and worked for a different company
    _for 5 years!_

    Then I got a job at the first company. Shortly after that, I received a
    telephone call from a guy saying he had read my paper (published 6 years
    before as a technical Memorandum For Record) and had a question about how
    I did something. He said he had been calling me over and over to ask the
    question. Since I had not even worked there _for 5 years_, I would have
    thought he would have found an alternative way to solve his problem.

    --
    .~. Jean-David Beyer Registered Linux User 85642.
    /V\ Registered Machine 241939.
    /( )\ Shrewsbury, New Jersey http://counter.li.org
    ^^-^^ 06:45:00 up 20 days, 7:28, 5 users, load average: 4.14, 3.63, 3.25


  3. Re: How to allocate few bytes to a file automatically after creating it?

    ["Followup-To:" header set to comp.os.linux.misc.]
    On 2004-05-13, Vineet Joglekar wrote:
    > 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.


    What's wrong with:

    char *data = "100 bytes of data ....."
    FILE *file = fopen( filename, "w");
    fprintf( file, "%s", data);
    fclose(file);

    or other standard functions, such as fwrite()?

    --
    Chris F.A. Johnson http://cfaj.freeshell.org/shell
    ================================================== =================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

  4. Re: How to allocate few bytes to a file automatically after creatingit?

    Vineet Joglekar wrote:
    > 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


    Would you mind to explain why?

    It would help us to respond in a sensible way.

    Tauno Voipio
    tauno voipio @ iki fi


  5. Re: How to allocate few bytes to a file automatically after creating it?

    Vineet Joglekar sat down at the computer and pounded the following into
    the keyboard:

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


    Why would you want a program to use file-system specific calls unless
    absolutely neccessary?

    --
    \\\\\ ----> hedgehog@hedgie.com <----
    \\\\\\\__o Bringing hedgehogs to the common folk since 1994.
    __\\\\\\\'/__________________________________________________ ______

    Visit http://www.hedgie.com for information on my latest book,
    "Waiting for War," published by Aventine Press!


  6. Re: How to allocate few bytes to a file automatically after creating it?

    vinzip@indiatimes.com (Vineet Joglekar) writes:
    > 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 you just want to add a few bytes to a file after you create it, you
    have several choices. If this is in the midst of a C-program, then the
    suggestions other posters have made are good.

    If you just want to produce a file with a few bytes in it, then

    echo "abcdefghi jklmno ( or whatever you want)" > file

    will also do the trick.

    Jack
    --
    First, they fear you. Then they match you. Then they laugh at you.
    Then they ignore you. Then you lose.

  7. Re: How to allocate few bytes to a file automatically after creating it?

    I am sorry.. I guess I missed it.

    What I m trying to do is, to make some changes in the ext2 file system
    for experimental purpose. my goal is to store some metadata in a file
    as soon as it is created. I am trying to make some changes in the file
    system, so it has to be at the file system level. User NEED NOT know
    that i am writing this matadata to every file created. so the picture
    is like when an inode is created for the new file, 1st entry in the
    data block pointers should be valid with some info in the allocated
    data block. The user seeing the file size increased by num of
    allocated bytes is acceptable.

    Thanks and regards,

    Vineet

    Tauno Voipio wrote in message news:...
    > Vineet Joglekar wrote:
    > > 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

    >
    > Would you mind to explain why?
    >
    > It would help us to respond in a sensible way.
    >
    > Tauno Voipio
    > tauno voipio @ iki fi


  8. Re: How to allocate few bytes to a file automatically after creating it?

    Jimmy Brokaw wrote in message news:...
    >
    > Why would you want a program to use file-system specific calls unless
    > absolutely neccessary?


    I am working on my thesis which involves playing with ext2 file
    system. Hence I am working at kernel level.

+ Reply to Thread