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

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. sfunds sfunds
    Replies:
    9
    Views:
    8,664
  2. Charles A. Lackman

    Streaming with System.IO and System.Net

    Charles A. Lackman, Dec 8, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    531
    Richard Grimes [MVP]
    Jan 15, 2005
  3. =?Utf-8?B?Sm9l?=

    Simple question about File System

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

    simple file system

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

Share This Page