simple file system

Discussion in 'C Programming' started by Greg, Nov 30, 2004.

  1. Greg

    Greg Guest

    I am continuing writing my simple file system and I have run across
    the following problem.

    I am writing a superblock to a certain frame in the file as follows:
    (&sb is the address of a superblock struct with size < FRAME_SZ * 4)

    #define FRAME_SZ 512

    int frame = 3 ;

    struct superblock *sb = malloc (FRAME_SZ * 4) ;
    struct superblock *sb_echoed = malloc (FRAME_SZ * 4) ;
    long int byte = frame * FRAME_SZ ;
    void *sb_info = malloc (FRAME_SZ * 4) ;

    memcpy (sb_info, &sb, 2048) ; // sb_info contains all superblock info
    fseek (file, byte, SEEK_SET) ;
    fwrite (&sb_info, FRAME_SZ * 4, 1, fp) ;

    void *sb_mem = malloc (FRAME_SZ * 4) ;

    fseek (fp, byte, SEEK_SET) ;
    printf ("Grabbing 4 frames starting at byte: %ld\n", ftell (fp)) ;
    fread (sb_mem, FRAME_SZ * 4, 1, fp) ;
    //memcpy (sb, &sb_mem, FRAME_SZ * 4) ; // attempt to copy data from
    file
    FILE *tempFile = fopen ("temp.dat", "wb") ;
    fwrite (&sb_mem, FRAME_SZ * 4, 1, tempFile) ;


    When I try to retrieve the struct, I grab it from the file and write
    it to a temporary file. I compare the two using something like od -j
    1536 -N 2048 -x file.dat, and the results are not the same.

    Anyone have any ideas what I am doing wrong?
     
    Greg, Nov 30, 2004
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gluke

    File Lock on Shared File System

    Gluke, Aug 7, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,500
    Kit George [MSFT]
    Aug 15, 2003
  2. Chad Crowder
    Replies:
    7
    Views:
    22,485
    hemant.yadav
    Oct 24, 2009
  3. Arsen V.
    Replies:
    9
    Views:
    10,421
    Steve C. Orr [MVP, MCSD]
    Feb 11, 2005
  4. =?Utf-8?B?Y3dicDE1?=

    Writing a text file to the file system

    =?Utf-8?B?Y3dicDE1?=, Mar 21, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    666
    shiva_ananthoju
    Oct 29, 2005
  5. =?Utf-8?B?Y3dicA==?=

    Writing a text file to the file system

    =?Utf-8?B?Y3dicA==?=, Mar 21, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    399
    =?Utf-8?B?Y3dicA==?=
    Mar 21, 2005
  6. =?Utf-8?B?Sm9l?=

    Simple question about File System

    =?Utf-8?B?Sm9l?=, Apr 29, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    945
    Scott Allen
    Apr 29, 2005
  7. Wagner Dias
    Replies:
    3
    Views:
    3,278
    Andre Kostur
    Mar 28, 2005
  8. Greg

    simple file system

    Greg, Nov 25, 2004, in forum: C Programming
    Replies:
    20
    Views:
    1,022
    Chris Croughton
    Nov 30, 2004
Loading...