simple file system
From: Greg (djbitchpimp_at_snowboard.com)
Date: 11/30/04
- Next message: MarcSmith: "sizeof error"
- Previous message: Alwyn: "Re: Learning C with Older books ?."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Nov 2004 23:29:58 -0800
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?
- Next message: MarcSmith: "sizeof error"
- Previous message: Alwyn: "Re: Learning C with Older books ?."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|