C question - headers in mmaped files

Jepri jepri at webone.com.au
Tue Apr 1 20:53:17 EST 2003


Hey all, I've got a C question for them who do that sort of thing.  Not 
quite linux, but the list is a tad slow thesedays.

I'm writing some code that writes and reads data out of files using 
mmap, and I get to make up my own file format.  It seemed natural to 
have a header describing the file, but I can't figure out how to access 
the header in the mmaped chunk of memory.  I thought I could just take 
pointers to anywhere inside the mmaped memory and cast them to whatever 
I wanted, but it doesn't seem to work for me.

i.e. I tried something really naive like:

map = (char *) mmap(etc etc)
head = (header *) map;
dat = (data *) map+64;

but data ended up pointing over 1kb heigher than it should have.  
What's the right way to do this?  Is there an easy way for me to make 
multiple 'segments' in the file that have different data formats?





More information about the linux mailing list