[Yaffs] How do you find the end of YAFFS data?

David Wuertele dave-gnus@bfnet.com
Wed, 27 Oct 2004 17:26:46 -0700


--=-=-=

I've written a program called "readyaffs" (see attached) --- well,
"written" is a little strong, basically I just copied mkyaffs.c over
to readyaffs.c and changed the reads to writes and the writes to
reads, and voila I have a system for taking a snapshot of a YAFFS
filesystem:

     readyaffs /dev/mtd/2 > yaffs.dump

verified that I can then reload this dump onto a different filesystem
elsewhere:

     mkyaffs /dev/mtd/2 yaffs.dump

My problem is that yaffs.dump is huge --- it is the same size as the
whole partition.  But I know my data doesn't fill that partition.  Is
there an easy way to discover where the end of the data is, and
truncate yaffs.dump to only be that long?

Thanks,
Dave


--=-=-=
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=readyaffs.c
Content-Transfer-Encoding: base64

LyoKICogWUFGRlM6IFlldCBhbm90aGVyIEZGUy4gQSBOQU5ELWZsYXNoIHNwZWNpZmljIGZpbGUg
c3lzdGVtLiAKICogbWt5YWZmcy5jIEZvcm1hdCBhIGNodW5rIG9mIE5BTkQgZm9yIFlBRkZTLgog
KgogKiBDb3B5cmlnaHQgKEMpIDIwMDIgQWxlcGggT25lIEx0ZC4KICogICBmb3IgVG9ieSBDaHVy
Y2hpbGwgTHRkIGFuZCBCcmlnaHRzdGFyIEVuZ2luZWVyaW5nCiAqCiAqIENyZWF0ZWQgYnkgQ2hh
cmxlcyBNYW5uaW5nIDxjaGFybGVzQGFsZXBoMS5jby51az4KICoKICogVGhpcyBwcm9ncmFtIGlz
IGZyZWUgc29mdHdhcmU7IHlvdSBjYW4gcmVkaXN0cmlidXRlIGl0IGFuZC9vciBtb2RpZnkKICog
aXQgdW5kZXIgdGhlIHRlcm1zIG9mIHRoZSBHTlUgR2VuZXJhbCBQdWJsaWMgTGljZW5zZSB2ZXJz
aW9uIDIgYXMKICogcHVibGlzaGVkIGJ5IHRoZSBGcmVlIFNvZnR3YXJlIEZvdW5kYXRpb24uCiAq
CiAqICBBY2tub3dsZWRnZW1lbnQ6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