diff options
author | David Cantrell <dcantrell@redhat.com> | 2007-03-15 13:03:24 -0400 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2007-03-15 13:06:47 -0400 |
commit | f21edf3b5e9a0ba30f0f7e60b29b89f079592c2f (patch) | |
tree | 2bb105bbc116b221086a0ae0e2032de3aa8429fa /libparted/fs/hfs/journal.c | |
parent | f18204fc905d6f90a6533f6ce20505d915c04280 (diff) | |
download | parted-f21edf3b5e9a0ba30f0f7e60b29b89f079592c2f.tar.gz |
Move static variable flagging little endian or not to journal.c. We don't want static variables in general, but if they must exist, put them in a C file, not a header.
Parameterize the little_endian flag for the macros in journal.h.
Diffstat (limited to 'libparted/fs/hfs/journal.c')
-rw-r--r-- | libparted/fs/hfs/journal.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/libparted/fs/hfs/journal.c b/libparted/fs/hfs/journal.c index edc5550..5d26216 100644 --- a/libparted/fs/hfs/journal.c +++ b/libparted/fs/hfs/journal.c @@ -39,6 +39,7 @@ #include "journal.h" static int hfsj_vh_replayed = 0; +static int is_le = 0; static uint32_t hfsj_calc_checksum(uint8_t *ptr, int len) @@ -79,14 +80,14 @@ hfsj_update_jl(PedFileSystem* fs, uint32_t block) HfsJJournalInfoBlock* jib; int binsect; - binsect = HFS_32_TO_CPU(priv_data->vh->block_size) / PED_SECTOR_SIZE_DEFAULT; + binsect = HFS_32_TO_CPU(priv_data->vh->block_size, is_le) / PED_SECTOR_SIZE_DEFAULT; sector = (PedSector) priv_data->jib_start_block * binsect; if (!ped_geometry_read(priv_data->plus_geom, buf, sector, 1)) return 0; jib = (HfsJJournalInfoBlock*) buf; offset = (uint64_t)block * PED_SECTOR_SIZE_DEFAULT * binsect; - jib->offset = HFS_CPU_TO_64(offset); + jib->offset = HFS_CPU_TO_64(offset, is_le); if (!ped_geometry_write(priv_data->plus_geom, buf, sector, 1) || !ped_geometry_sync(priv_data->plus_geom)) @@ -134,18 +135,18 @@ hfsj_replay_transaction(PedFileSystem* fs, HfsJJournalHeader* jh, int i, r; uint32_t cksum, size; - blhdr_nbsect = HFS_32_TO_CPU(jh->blhdr_size) / PED_SECTOR_SIZE_DEFAULT; + blhdr_nbsect = HFS_32_TO_CPU(jh->blhdr_size, is_le) / PED_SECTOR_SIZE_DEFAULT; blhdr = (HfsJBlockListHeader*) ped_malloc (blhdr_nbsect * PED_SECTOR_SIZE_DEFAULT); if (!blhdr) return 0; - start = HFS_64_TO_CPU(jh->start) / PED_SECTOR_SIZE_DEFAULT; + start = HFS_64_TO_CPU(jh->start, is_le) / PED_SECTOR_SIZE_DEFAULT; do { start = hfsj_journal_read(priv_data->plus_geom, jh, jsector, jlength, start, blhdr_nbsect, blhdr); if (!start) goto err_replay; - cksum = HFS_32_TO_CPU(blhdr->checksum); + cksum = HFS_32_TO_CPU(blhdr->checksum, is_le); blhdr->checksum = 0; if (cksum!=hfsj_calc_checksum((uint8_t*)blhdr, sizeof(*blhdr))){ ped_exception_throw ( @@ -154,11 +155,11 @@ hfsj_replay_transaction(PedFileSystem* fs, HfsJJournalHeader* jh, _("Bad block list header checksum.")); goto err_replay; } - blhdr->checksum = HFS_CPU_TO_32(cksum); + blhdr->checksum = HFS_CPU_TO_32(cksum, is_le); - for (i=1; i < HFS_16_TO_CPU(blhdr->num_blocks); ++i) { - size = HFS_32_TO_CPU(blhdr->binfo[i].bsize); - sector = HFS_64_TO_CPU(blhdr->binfo[i].bnum); + for (i=1; i < HFS_16_TO_CPU(blhdr->num_blocks, is_le); ++i) { + size = HFS_32_TO_CPU(blhdr->binfo[i].bsize, is_le); + sector = HFS_64_TO_CPU(blhdr->binfo[i].bnum, is_le); if (!size) continue; if (size % PED_SECTOR_SIZE_DEFAULT) { ped_exception_throw( @@ -210,7 +211,7 @@ hfsj_replay_transaction(PedFileSystem* fs, HfsJJournalHeader* jh, } } while (blhdr->binfo[0].next); - jh->start = HFS_CPU_TO_64(start * PED_SECTOR_SIZE_DEFAULT); + jh->start = HFS_CPU_TO_64(start * PED_SECTOR_SIZE_DEFAULT, is_le); ped_free (blhdr); return (ped_geometry_sync (fs->geom)); @@ -244,7 +245,7 @@ hfsj_replay_journal(PedFileSystem* fs) if ( (jib->flags & PED_CPU_TO_BE32(1 << HFSJ_JOURN_IN_FS)) && !(jib->flags & PED_CPU_TO_BE32(1 << HFSJ_JOURN_OTHER_DEV)) ) { - priv_data->jl_start_block = HFS_64_TO_CPU(jib->offset) + priv_data->jl_start_block = HFS_64_TO_CPU(jib->offset, is_le) / ( PED_SECTOR_SIZE_DEFAULT * binsect ); } @@ -281,10 +282,10 @@ hfsj_replay_journal(PedFileSystem* fs) jh = (HfsJJournalHeader*) buf; if (jh->endian == PED_LE32_TO_CPU(HFSJ_ENDIAN_MAGIC)) - little_endian = 1; + is_le = 1; - if ( (jh->magic != HFS_32_TO_CPU(HFSJ_HEADER_MAGIC)) - || (jh->endian != HFS_32_TO_CPU(HFSJ_ENDIAN_MAGIC)) ) { + if ( (jh->magic != HFS_32_TO_CPU(HFSJ_HEADER_MAGIC, is_le)) + || (jh->endian != HFS_32_TO_CPU(HFSJ_ENDIAN_MAGIC, is_le)) ) { ped_exception_throw ( PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, @@ -292,8 +293,8 @@ hfsj_replay_journal(PedFileSystem* fs) return 0; } - if ( (HFS_64_TO_CPU(jh->size)%PED_SECTOR_SIZE_DEFAULT) - || (HFS_64_TO_CPU(jh->size)/PED_SECTOR_SIZE_DEFAULT + if ( (HFS_64_TO_CPU(jh->size, is_le)%PED_SECTOR_SIZE_DEFAULT) + || (HFS_64_TO_CPU(jh->size, is_le)/PED_SECTOR_SIZE_DEFAULT != (uint64_t)length) ) { ped_exception_throw ( PED_EXCEPTION_ERROR, @@ -303,10 +304,10 @@ hfsj_replay_journal(PedFileSystem* fs) return 0; } - if ( (HFS_64_TO_CPU(jh->start) % PED_SECTOR_SIZE_DEFAULT) - || (HFS_64_TO_CPU(jh->end) % PED_SECTOR_SIZE_DEFAULT) - || (HFS_32_TO_CPU(jh->blhdr_size) % PED_SECTOR_SIZE_DEFAULT) - || (HFS_32_TO_CPU(jh->jhdr_size) % PED_SECTOR_SIZE_DEFAULT) ) { + if ( (HFS_64_TO_CPU(jh->start, is_le) % PED_SECTOR_SIZE_DEFAULT) + || (HFS_64_TO_CPU(jh->end, is_le) % PED_SECTOR_SIZE_DEFAULT) + || (HFS_32_TO_CPU(jh->blhdr_size, is_le) % PED_SECTOR_SIZE_DEFAULT) + || (HFS_32_TO_CPU(jh->jhdr_size, is_le) % PED_SECTOR_SIZE_DEFAULT) ) { ped_exception_throw ( PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, @@ -315,7 +316,7 @@ hfsj_replay_journal(PedFileSystem* fs) return 0; } - if (HFS_32_TO_CPU(jh->jhdr_size) != PED_SECTOR_SIZE_DEFAULT) { + if (HFS_32_TO_CPU(jh->jhdr_size, is_le) != PED_SECTOR_SIZE_DEFAULT) { ped_exception_throw ( PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, @@ -325,7 +326,7 @@ hfsj_replay_journal(PedFileSystem* fs) return 0; } - cksum = HFS_32_TO_CPU(jh->checksum); + cksum = HFS_32_TO_CPU(jh->checksum, is_le); jh->checksum = 0; if (cksum != hfsj_calc_checksum((uint8_t*)jh, sizeof(*jh))) { ped_exception_throw ( @@ -334,14 +335,14 @@ hfsj_replay_journal(PedFileSystem* fs) _("Bad journal checksum.")); return 0; } - jh->checksum = HFS_CPU_TO_32(cksum); + jh->checksum = HFS_CPU_TO_32(cksum, is_le); /* The 2 following test are in the XNU Darwin source code */ /* so I assume they're needed */ if (jh->start == jh->size) - jh->start = HFS_CPU_TO_64(PED_SECTOR_SIZE_DEFAULT); + jh->start = HFS_CPU_TO_64(PED_SECTOR_SIZE_DEFAULT, is_le); if (jh->end == jh->size) - jh->start = HFS_CPU_TO_64(PED_SECTOR_SIZE_DEFAULT); + jh->start = HFS_CPU_TO_64(PED_SECTOR_SIZE_DEFAULT, is_le); if (jh->start == jh->end) return 1; @@ -363,7 +364,7 @@ hfsj_replay_journal(PedFileSystem* fs) /* Recalculate cksum of the journal header */ jh->checksum = 0; /* need to be 0 while calculating the cksum */ cksum = hfsj_calc_checksum((uint8_t*)jh, sizeof(*jh)); - jh->checksum = HFS_CPU_TO_32(cksum); + jh->checksum = HFS_CPU_TO_32(cksum, is_le); /* Update the Journal Header */ if (!ped_geometry_write(priv_data->plus_geom, buf, sector, 1) |