diff options
Diffstat (limited to 'src')
120 files changed, 379 insertions, 508 deletions
diff --git a/src/btrfs.h b/src/btrfs.h index 26fb20eb..d28c590b 100644 --- a/src/btrfs.h +++ b/src/btrfs.h @@ -94,7 +94,7 @@ struct btrfs_dev_item { /* uuid of FS who owns this device */ uint8_t fsid[BTRFS_UUID_SIZE]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct btrfs_super_block { uint8_t csum[BTRFS_CSUM_SIZE]; @@ -136,7 +136,7 @@ struct btrfs_super_block { /* future expansion */ uint64_t reserved[32]; uint8_t sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); int check_btrfs(disk_t *disk_car,partition_t *partition); int recover_btrfs(disk_t *disk_car, const struct btrfs_super_block *sb,partition_t *partition,const int verbose, const int dump_ind); diff --git a/src/common.h b/src/common.h index 9304b414..2b7b808c 100644 --- a/src/common.h +++ b/src/common.h @@ -34,7 +34,7 @@ struct efi_guid_s uint8_t clock_seq_hi_and_reserved; uint8_t clock_seq_low; uint8_t node[6]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); #define DEFAULT_SECTOR_SIZE 0x200u diff --git a/src/exfat.h b/src/exfat.h index 9152f53e..26f5e3f0 100644 --- a/src/exfat.h +++ b/src/exfat.h @@ -47,7 +47,7 @@ struct exfat_super_block { unsigned char allocated_percent; /* 0x70 percentage of allocated space (?) */ unsigned char xxxx05[397]; /* ??? (0x00...) */ uint16_t signature; /* 0xaa55 */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct exfat_file_entry { @@ -67,7 +67,7 @@ struct exfat_file_entry uint8_t ctz; uint8_t mtz; uint8_t reserved2[7]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct exfat_stream_ext_entry { @@ -81,7 +81,7 @@ struct exfat_stream_ext_entry uint32_t reserved3; uint32_t first_cluster; uint64_t data_length; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct exfat_alloc_bitmap_entry { @@ -90,7 +90,7 @@ struct exfat_alloc_bitmap_entry uint8_t reserved[18]; uint32_t first_cluster; uint64_t data_length; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); uint64_t exfat_cluster_to_offset(const struct exfat_super_block *exfat_header, const unsigned int cluster); int exfat_read_cluster(disk_t *disk, const partition_t *partition, const struct exfat_super_block*exfat_header, void *buffer, const unsigned int cluster); @@ -73,7 +73,7 @@ struct fat_boot_sector { /* */ uint8_t nothing[420]; /* 0x5A */ uint16_t marker; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct fat_fsinfo { uint32_t leadsig; /* 0x41615252 */ @@ -83,7 +83,7 @@ struct fat_fsinfo { uint32_t nextfree; /* next free cluster */ uint8_t reserved3[12]; uint32_t magic3; /* 0xAA550000 */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct msdos_dir_entry { int8_t name[8],ext[3]; /* 00 name and extension */ @@ -98,7 +98,7 @@ struct msdos_dir_entry { uint16_t date; /* 18 */ uint16_t start; /* 1A */ uint32_t size; /* 1C file size (in bytes) */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); /* Up to 13 characters of the name */ struct msdos_dir_slot { @@ -30,7 +30,7 @@ struct disk_fatx uint32_t cluster_size_in_sector; uint16_t fats; uint32_t unknown; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); int check_FATX(disk_t *disk_car, partition_t *partition); int recover_FATX(const struct disk_fatx *fatx_block, partition_t *partition); diff --git a/src/fidentify.c b/src/fidentify.c index 6d0949de..824924e7 100644 --- a/src/fidentify.c +++ b/src/fidentify.c @@ -56,6 +56,11 @@ extern file_enable_t list_file_enable[]; extern file_check_list_t file_check_list; #define READ_SIZE 1024*512 +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif static int file_identify(const char *filename, const unsigned int check) { @@ -115,11 +120,7 @@ static int file_identify(const char *filename, const unsigned int check) if(check > 0 && file_recovery_new.file_check!=NULL) { file_recovery_new.handle=file; -#ifdef HAVE_FSEEKO - fseeko(file_recovery_new.handle, 0, SEEK_END); -#else - fseek(file_recovery_new.handle, 0, SEEK_END); -#endif + my_fseek(file_recovery_new.handle, 0, SEEK_END); #ifdef HAVE_FTELLO file_recovery_new.file_size=ftello(file_recovery_new.handle); #else diff --git a/src/file_1cd.c b/src/file_1cd.c index d9fa2989..23161349 100644 --- a/src/file_1cd.c +++ b/src/file_1cd.c @@ -48,7 +48,7 @@ struct header_1cd char magic[8]; uint32_t version; uint32_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_1cd(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_7z.c b/src/file_7z.c index 35393565..0c671a47 100644 --- a/src/file_7z.c +++ b/src/file_7z.c @@ -51,8 +51,7 @@ struct header_7z { uint64_t nextHeaderOffset; uint64_t nextHeaderSize; uint64_t nextHeaderCRC; -} __attribute__ ((__packed__)); - +} __attribute__ ((gcc_struct, __packed__)); static int header_check_7z(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_a.c b/src/file_a.c index 567ea15d..2af79f95 100644 --- a/src/file_a.c +++ b/src/file_a.c @@ -51,7 +51,7 @@ struct file_header char mode[8]; char size[10]; char magic[2]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_a(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_ab.c b/src/file_ab.c index 02135dfc..17d16b67 100644 --- a/src/file_ab.c +++ b/src/file_ab.c @@ -45,7 +45,7 @@ struct ab_header { char magic[4]; uint32_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_addressbook(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_ace.c b/src/file_ace.c index 96e3701f..276a28f5 100644 --- a/src/file_ace.c +++ b/src/file_ace.c @@ -34,6 +34,11 @@ #include "crc.h" /* #define DEBUG_ACE */ +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif static void register_header_check_ace(file_stat_t *file_stat); @@ -57,7 +62,8 @@ struct header_ace { bit 0 indicates if field add size is preset */ uint32_t addsize; /** an optional field which represents the size of an additional block without specified structure */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); + typedef struct header_ace ace_header_t; static void file_check_ace(file_recovery_t *file_recovery) @@ -65,11 +71,7 @@ static void file_check_ace(file_recovery_t *file_recovery) file_recovery->offset_error = 0; file_recovery->offset_ok = 0; file_recovery->file_size = 0; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, 0, SEEK_SET)<0) -#else - if(fseek(file_recovery->handle, 0, SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle, 0, SEEK_SET)<0) return ; #ifdef DEBUG_ACE log_trace("file_check_ace\n"); @@ -88,11 +90,7 @@ static void file_check_ace(file_recovery_t *file_recovery) file_recovery->file_size=0; return ; } -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, -sizeof(h)+4, SEEK_CUR)<0) -#else - if(fseek(file_recovery->handle, -sizeof(h)+4, SEEK_CUR)<0) -#endif + if(my_fseek(file_recovery->handle, -sizeof(h)+4, SEEK_CUR)<0) { file_recovery->offset_error=file_recovery->file_size; file_recovery->file_size=0; @@ -169,11 +167,7 @@ static void file_check_ace(file_recovery_t *file_recovery) if (le16(h.flags)&1) { file_recovery->file_size += le32(h.addsize); -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, file_recovery->file_size, SEEK_SET)<0) -#else - if(fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET)<0) { file_recovery->offset_error=file_recovery->file_size; file_recovery->file_size=0; diff --git a/src/file_aif.c b/src/file_aif.c index 1b4c6f9d..9faaad7a 100644 --- a/src/file_aif.c +++ b/src/file_aif.c @@ -48,7 +48,7 @@ struct aif_header char ckID[4]; uint32_t ckSize; char formType[4]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_aif(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_ape.c b/src/file_ape.c index 24b8e3e6..d93bcb73 100644 --- a/src/file_ape.c +++ b/src/file_ape.c @@ -83,7 +83,7 @@ struct APE_DESCRIPTOR uint64_t nAPEFrameDataBytes; // the number of bytes of APE frame data uint32_t nTerminatingDataBytes; // the terminating data of the file (not including tag data) uint8_t cFileMD5[16]; // the MD5 hash of the file (see notes for usage... it's a littly tricky) -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); /***************************************************************************************** * APE_HEADER structure (describes the format, duration, etc. of the APE file) diff --git a/src/file_ari.c b/src/file_ari.c index 102c435a..12daf930 100644 --- a/src/file_ari.c +++ b/src/file_ari.c @@ -53,7 +53,7 @@ struct arri_header uint32_t width; uint32_t height; uint32_t cam_hwr_rev; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_ari(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_arj.c b/src/file_arj.c index 4aa76e9c..79c7e0e2 100644 --- a/src/file_arj.c +++ b/src/file_arj.c @@ -115,7 +115,7 @@ struct arj_main_header { uint16_t security_env_size; uint16_t unused; char filename; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_check_arj(file_recovery_t *file_recovery) { diff --git a/src/file_asf.c b/src/file_asf.c index edc53cca..cd95a71e 100644 --- a/src/file_asf.c +++ b/src/file_asf.c @@ -51,7 +51,7 @@ struct asf_header_obj_s { uint32_t nbr_header_obj; char reserved1; /* 1 */ char reserved2; /* 2 */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct asf_file_prop_s { unsigned char object_id[16]; @@ -59,13 +59,13 @@ struct asf_file_prop_s { unsigned char file_id[16]; uint64_t file_size; uint64_t file_date; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct asf_stream_prop_s { unsigned char object_id[16]; uint64_t object_size; unsigned char stream_type[16]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_asf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_au.c b/src/file_au.c index 44edeb56..0269453f 100644 --- a/src/file_au.c +++ b/src/file_au.c @@ -60,7 +60,7 @@ struct header_au_s uint32_t encoding; uint32_t sample_rate; uint32_t channels; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_au(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_axx.c b/src/file_axx.c index 25cf7675..72d19091 100644 --- a/src/file_axx.c +++ b/src/file_axx.c @@ -48,7 +48,12 @@ struct SHeader { uint32_t aoLength; uint8_t oType; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif static void file_check_axx(file_recovery_t *fr) { @@ -57,11 +62,7 @@ static void file_check_axx(file_recovery_t *fr) { struct SHeader header; unsigned int len; -#ifdef HAVE_FSEEKO - if(fseeko(fr->handle, offset, SEEK_SET) < 0) -#else - if(fseek(fr->handle, offset, SEEK_SET) < 0) -#endif + if(my_fseek(fr->handle, offset, SEEK_SET) < 0) return ; if (fread(&header, sizeof(header), 1, fr->handle)!=1) return ; diff --git a/src/file_bac.c b/src/file_bac.c index a1923ee3..73ed3717 100644 --- a/src/file_bac.c +++ b/src/file_bac.c @@ -53,7 +53,7 @@ struct block_header char ID[4]; /* Identification and block level */ uint32_t VolSessionId; /* Session Id for Job */ uint32_t VolSessionTime; /* Session Time for Job */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_bac(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_bkf.c b/src/file_bkf.c index d3398171..5b796b06 100644 --- a/src/file_bkf.c +++ b/src/file_bkf.c @@ -61,7 +61,7 @@ struct mtf_db_hdr uint8_t strType; /* string type */ uint8_t rsv3; /* reserved for future use */ uint16_t check; /* header checksum */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_check_bkf(file_recovery_t *file_recovery) { diff --git a/src/file_bmp.c b/src/file_bmp.c index 9a3ef216..7f4afd6e 100644 --- a/src/file_bmp.c +++ b/src/file_bmp.c @@ -57,7 +57,7 @@ struct bmp_header uint32_t size; uint32_t reserved; uint32_t offset; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_bmp(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_cab.c b/src/file_cab.c index 9d23ea4c..13195220 100644 --- a/src/file_cab.c +++ b/src/file_cab.c @@ -56,7 +56,7 @@ struct cab_header { uint16_t flags; uint16_t setid; uint16_t number; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_cab(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_caf.c b/src/file_caf.c index 13e6e156..8d801961 100644 --- a/src/file_caf.c +++ b/src/file_caf.c @@ -53,7 +53,7 @@ struct chunk_struct { uint32_t type; int64_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_caf(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_cow.c b/src/file_cow.c index d29bbb69..59d10ff8 100644 --- a/src/file_cow.c +++ b/src/file_cow.c @@ -57,7 +57,7 @@ typedef struct { uint8_t l2_bits; uint32_t crypt_method; uint64_t l1_table_offset; -} __attribute__ ((__packed__)) QCowHeader_t; +} __attribute__ ((gcc_struct, __packed__)) QCowHeader_t; typedef struct QCowHeader { uint32_t magic; diff --git a/src/file_cwk.c b/src/file_cwk.c index 01c9653c..4c54f16c 100644 --- a/src/file_cwk.c +++ b/src/file_cwk.c @@ -63,7 +63,7 @@ struct cwk_header uint16_t margins[6]; uint16_t inner_height; uint16_t inner_width; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_check_cwk(file_recovery_t *file_recovery) { diff --git a/src/file_d2s.c b/src/file_d2s.c index e173d0bb..b8096385 100644 --- a/src/file_d2s.c +++ b/src/file_d2s.c @@ -48,7 +48,7 @@ struct d2s_header { uint32_t unk1; uint32_t unk2; char name[0]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_rename_d2s(const char *old_filename) { diff --git a/src/file_dad.c b/src/file_dad.c index 2f4fa0e9..d8afb613 100644 --- a/src/file_dad.c +++ b/src/file_dad.c @@ -50,7 +50,7 @@ struct dad_header uint32_t unk1; uint32_t unk2; uint32_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_dad(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_ddf.c b/src/file_ddf.c index f6db68dc..b059460d 100644 --- a/src/file_ddf.c +++ b/src/file_ddf.c @@ -78,7 +78,7 @@ struct MasterHeader uint32_t m_n3DFlags; // reserved...currently unused /* Fields for v4 are added here*/ char m_cRsvdData[120]; // (120) pad to 512 bytes -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_aux(const unsigned char *buffer, file_recovery_t *file_recovery_new) { diff --git a/src/file_dex.c b/src/file_dex.c index eee1d355..91d2dc99 100644 --- a/src/file_dex.c +++ b/src/file_dex.c @@ -70,7 +70,7 @@ struct dex_header uint32_t class_def_off; uint32_t data_size; uint32_t data_off; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_dex(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_djv.c b/src/file_djv.c index bde84ecd..882780f0 100644 --- a/src/file_djv.c +++ b/src/file_djv.c @@ -48,7 +48,7 @@ struct djv_header uint32_t magic; uint32_t type; uint32_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_djv(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_doc.c b/src/file_doc.c index ad71f106..f5cda30e 100644 --- a/src/file_doc.c +++ b/src/file_doc.c @@ -38,6 +38,12 @@ #include "memmem.h" #include "setdate.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_doc(file_stat_t *file_stat); static void file_check_doc(file_recovery_t *file_recovery); static int header_check_doc(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); @@ -84,12 +90,7 @@ static void file_check_doc(file_recovery_t *file_recovery) const uint64_t doc_file_size_org=file_recovery->file_size; file_recovery->file_size=0; /*reads first sector including OLE header */ - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, 0, SEEK_SET) < 0 || -#else - fseek(file_recovery->handle, 0, SEEK_SET) < 0 || -#endif + if(my_fseek(file_recovery->handle, 0, SEEK_SET) < 0 || fread(&buffer_header, sizeof(buffer_header), 1, file_recovery->handle) != 1) return ; #ifdef DEBUG_OLE @@ -154,11 +155,7 @@ static void file_check_doc(file_recovery_t *file_recovery) free(fat); return ; } -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, (1+block)<<le16(header->uSectorShift), SEEK_SET)<0) -#else - if(fseek(file_recovery->handle, (1+block)<<le16(header->uSectorShift), SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle, (1+block)<<le16(header->uSectorShift), SEEK_SET)<0) { #ifdef DEBUG_OLE log_info("fseek failed\n"); @@ -506,11 +503,7 @@ static uint32_t *OLE_load_FAT(FILE *IN, const struct OLE_HDR *header) i<le32(header->num_extra_FAT_blocks) && block!=0xFFFFFFFF && block!=0xFFFFFFFE; i++, block=le32(dif[109+i*(((1<<le16(header->uSectorShift))/4)-1)])) { -#ifdef HAVE_FSEEKO - if(fseeko(IN, (1+block)<<le16(header->uSectorShift), SEEK_SET) < 0) -#else - if(fseek(IN, (1+block)<<le16(header->uSectorShift), SEEK_SET) < 0) -#endif + if(my_fseek(IN, (1+block)<<le16(header->uSectorShift), SEEK_SET) < 0) { free(dif); return NULL; @@ -531,11 +524,7 @@ static uint32_t *OLE_load_FAT(FILE *IN, const struct OLE_HDR *header) j<le32(header->num_FAT_blocks); j++, data+=(1<<le16(header->uSectorShift))) { -#ifdef HAVE_FSEEKO - if(fseeko(IN, (1+le32(dif[j]))<<le16(header->uSectorShift), SEEK_SET)<0) -#else - if(fseek(IN, (1+le32(dif[j]))<<le16(header->uSectorShift), SEEK_SET)<0) -#endif + if(my_fseek(IN, (1+le32(dif[j]))<<le16(header->uSectorShift), SEEK_SET)<0) { free(dif); free(fat); @@ -570,11 +559,7 @@ static void *OLE_read_stream(FILE *IN, free(dataPt); return NULL; } -#ifdef HAVE_FSEEKO - if(fseeko(IN, (1+block)<<uSectorShift, SEEK_SET)<0) -#else - if(fseek(IN, (1+block)<<uSectorShift, SEEK_SET)<0) -#endif + if(my_fseek(IN, (1+block)<<uSectorShift, SEEK_SET)<0) { free(dataPt); return NULL; @@ -601,11 +586,7 @@ static uint32_t *OLE_load_MiniFAT(FILE *IN, const struct OLE_HDR *header, const block=le32(header->MiniFat_block); for(i=0; i < le32(header->csectMiniFat) && block < fat_entries; i++) { -#ifdef HAVE_FSEEKO - if(fseeko(IN, ((uint64_t)1+block) << le16(header->uSectorShift), SEEK_SET) < 0) -#else - if(fseek(IN, ((uint64_t)1+block) << le16(header->uSectorShift), SEEK_SET) < 0) -#endif + if(my_fseek(IN, ((uint64_t)1+block) << le16(header->uSectorShift), SEEK_SET) < 0) { free(minifat); return NULL; @@ -865,12 +846,7 @@ static void file_rename_doc(const char *old_filename) log_info("file_rename_doc(%s)\n", old_filename); #endif /*reads first sector including OLE header */ - if( -#ifdef HAVE_FSEEKO - fseeko(file, 0, SEEK_SET) < 0 || -#else - fseek(file, 0, SEEK_SET) < 0 || -#endif + if(my_fseek(file, 0, SEEK_SET) < 0 || fread(&buffer_header, sizeof(buffer_header), 1, file) != 1) { fclose(file); @@ -907,11 +883,7 @@ static void file_rename_doc(const char *old_filename) block=le32(fat[block]), i++) { struct OLE_DIR *dir_entries; -#ifdef HAVE_FSEEKO - if(fseeko(file, (1+block)<<le16(header->uSectorShift), SEEK_SET)<0) -#else - if(fseek(file, (1+block)<<le16(header->uSectorShift), SEEK_SET)<0) -#endif + if(my_fseek(file, (1+block)<<le16(header->uSectorShift), SEEK_SET)<0) { free(fat); fclose(file); diff --git a/src/file_dpx.c b/src/file_dpx.c index 900526b4..89c14aaa 100644 --- a/src/file_dpx.c +++ b/src/file_dpx.c @@ -64,7 +64,7 @@ struct header_dpx char copyright[200]; /* right to use or copyright info */ uint32_t key; /* encryption ( FFFFFFFF = unencrypted ) */ char Reserved[104]; /* reserved field TBD (need to pad) */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_dpx(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_dv.c b/src/file_dv.c index d2692a92..5edbd4b7 100644 --- a/src/file_dv.c +++ b/src/file_dv.c @@ -42,6 +42,12 @@ const file_hint_t file_hint_dv= { .register_header_check=®ister_header_check_dv }; +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static data_check_t data_check_NTSC(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size && @@ -62,12 +68,7 @@ static void file_check_dv_NTSC(file_recovery_t *fr) unsigned char buffer_header[512]; unsigned char buffer[120000]; uint64_t fs=fr->file_size/120000*120000; - if( -#ifdef HAVE_FSEEKO - fseeko(fr->handle, 0, SEEK_SET) < 0 || -#else - fseek(fr->handle, 0, SEEK_SET) < 0 || -#endif + if(my_fseek(fr->handle, 0, SEEK_SET) < 0 || fread(&buffer_header, sizeof(buffer_header), 1, fr->handle) != 1) return ; if(fs > 0) @@ -75,11 +76,7 @@ static void file_check_dv_NTSC(file_recovery_t *fr) if(fs > 0) fs-=120000; while(fs < fr->file_size && -#ifdef HAVE_FSEEKO - fseeko(fr->handle, fs, SEEK_SET) >= 0 && -#else - fseek(fr->handle, fs, SEEK_SET) >= 0 && -#endif + my_fseek(fr->handle, fs, SEEK_SET) >= 0 && fread(&buffer, sizeof(buffer), 1, fr->handle) == 1) { unsigned int i; @@ -114,12 +111,7 @@ static void file_check_dv_PAL(file_recovery_t *fr) unsigned char buffer_header[512]; unsigned char buffer[144000]; uint64_t fs=fr->file_size/144000*144000; - if( -#ifdef HAVE_FSEEKO - fseeko(fr->handle, 0, SEEK_SET) < 0 || -#else - fseek(fr->handle, 0, SEEK_SET) < 0 || -#endif + if(my_fseek(fr->handle, 0, SEEK_SET) < 0 || fread(&buffer_header, sizeof(buffer_header), 1, fr->handle) != 1) return ; if(fs > 0) @@ -127,11 +119,7 @@ static void file_check_dv_PAL(file_recovery_t *fr) if(fs > 0) fs-=144000; while(fs < fr->file_size && -#ifdef HAVE_FSEEKO - fseeko(fr->handle, fs, SEEK_SET) >= 0 && -#else - fseek(fr->handle, fs, SEEK_SET) >= 0 && -#endif + my_fseek(fr->handle, fs, SEEK_SET) >= 0 && fread(&buffer, sizeof(buffer), 1, fr->handle) == 1) { unsigned int i; diff --git a/src/file_e01.c b/src/file_e01.c index 261585b7..eca94a14 100644 --- a/src/file_e01.c +++ b/src/file_e01.c @@ -64,7 +64,7 @@ struct ewf_file_header * 0x00 0x00 */ uint16_t fields_end; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_check_e01(file_recovery_t *file_recovery) { diff --git a/src/file_ecryptfs.c b/src/file_ecryptfs.c index 8e19f185..4faf4eb5 100644 --- a/src/file_ecryptfs.c +++ b/src/file_ecryptfs.c @@ -54,7 +54,7 @@ struct ecrypfs_header { unsigned char reserved1; unsigned char reserved2; uint32_t flags; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void register_header_check_ecryptfs(file_stat_t *file_stat) { diff --git a/src/file_emf.c b/src/file_emf.c index d7e36daa..ec9e2eb8 100644 --- a/src/file_emf.c +++ b/src/file_emf.c @@ -78,7 +78,7 @@ struct EMF_HDR uint32_t nPalEntries; U_SIZEL szlDevice; U_SIZEL szlMillimeters; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static const unsigned char emf_header[4]= { 0x01, 0x00, 0x00, 0x00}; diff --git a/src/file_evt.c b/src/file_evt.c index 8f1af93d..080e3be6 100644 --- a/src/file_evt.c +++ b/src/file_evt.c @@ -49,7 +49,7 @@ const file_hint_t file_hint_evt= { struct evt_chunk { uint32_t size; uint32_t id; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_evt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_exe.c b/src/file_exe.c index 9cd38f72..17097dbc 100644 --- a/src/file_exe.c +++ b/src/file_exe.c @@ -209,14 +209,14 @@ struct rsrc_entries_s { uint32_t Type; uint32_t Pos; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct PE_index { uint16_t len; uint16_t val_len; uint16_t type; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static char vs_version_info[32]={ 'V', 0x0, 'S', 0x0, '_', 0x0, 'V', 0x0, 'E', 0x0, 'R', 0x0, 'S', 0x0, 'I', 0x0, diff --git a/src/file_fcs.c b/src/file_fcs.c index 8ca29fc9..fded067b 100644 --- a/src/file_fcs.c +++ b/src/file_fcs.c @@ -61,7 +61,7 @@ struct fcs_header unsigned char data_end[8]; /* 34 */ unsigned char analysis_start[8]; /* 34 */ unsigned char analysis_end[8]; /* 50 */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static uint64_t ascii2int(const unsigned char *string, const unsigned int max_length) { diff --git a/src/file_fds.c b/src/file_fds.c index 289eb9c4..8c04c853 100644 --- a/src/file_fds.c +++ b/src/file_fds.c @@ -48,7 +48,7 @@ struct fds_header { char ident[4]; uint8_t numsides; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_fds(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_fh5.c b/src/file_fh5.c index e91de867..72bd2374 100644 --- a/src/file_fh5.c +++ b/src/file_fh5.c @@ -36,7 +36,7 @@ struct fh5_header_s { unsigned char id[8]; uint32_t datalen; /* Big Endian size w/o headers */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); typedef struct fh5_header_s fh5_header_t; static void register_header_check_fh5(file_stat_t *file_stat); diff --git a/src/file_flp.c b/src/file_flp.c index bfa0a68c..48289257 100644 --- a/src/file_flp.c +++ b/src/file_flp.c @@ -53,7 +53,7 @@ struct flp_header int16_t time_division; char magic2[4]; uint32_t len2; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_flp(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_flv.c b/src/file_flv.c index 3aaeacbd..091b4779 100644 --- a/src/file_flv.c +++ b/src/file_flv.c @@ -50,7 +50,7 @@ struct flv_header uint8_t version; uint8_t type_flags; uint32_t data_offset; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct flv_tag { @@ -60,7 +60,7 @@ struct flv_tag uint8_t timestamp[3]; uint8_t timestamp_ext; uint8_t streamID[3]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_flv(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_fs.c b/src/file_fs.c index e1708a87..1df8f73a 100644 --- a/src/file_fs.c +++ b/src/file_fs.c @@ -55,7 +55,7 @@ struct transaction_header uint16_t len_username; uint16_t len_descr; uint16_t len_ext; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_fs(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_gif.c b/src/file_gif.c index a4ab1d63..eaa0772f 100644 --- a/src/file_gif.c +++ b/src/file_gif.c @@ -31,6 +31,12 @@ #include "filegen.h" #include "log.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_gif(file_stat_t *file_stat); static int header_check_gif(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); static void file_check_gif(file_recovery_t *file_recovery); @@ -74,12 +80,7 @@ static void file_check_gif(file_recovery_t *file_recovery) { const unsigned char gif_footer[2]= {0x00, 0x3b}; unsigned char buffer[2]; - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, file_recovery->calculated_file_size-2, SEEK_SET)<0 || -#else - fseek(file_recovery->handle, file_recovery->calculated_file_size-2, SEEK_SET)<0 || -#endif + if(my_fseek(file_recovery->handle, file_recovery->calculated_file_size-2, SEEK_SET)<0 || fread(buffer, 2, 1, file_recovery->handle)!=1 || memcmp(buffer, gif_footer, sizeof(gif_footer))!=0) { diff --git a/src/file_gpg.c b/src/file_gpg.c index 732efbc7..daf7d456 100644 --- a/src/file_gpg.c +++ b/src/file_gpg.c @@ -34,6 +34,12 @@ #include "log.h" #endif +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_gpg(file_stat_t *file_stat); static int header_check_gpg(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); @@ -252,12 +258,7 @@ static void file_check_gpg(file_recovery_t *file_recovery) unsigned int length_type=0; unsigned int length; const int old_partial_body_length=partial_body_length; - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, offset, SEEK_SET) < 0 || -#else - fseek(file_recovery->handle, offset, SEEK_SET) < 0 || -#endif + if(my_fseek(file_recovery->handle, offset, SEEK_SET) < 0 || fread(&buffer, sizeof(buffer), 1, file_recovery->handle) != 1) return; @@ -318,12 +319,7 @@ static void file_check_gpg(file_recovery_t *file_recovery) { int len2; unsigned char tmp[2]; - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, offset+1+8+1+2+len, SEEK_SET) < 0 || -#else - fseek(file_recovery->handle, offset+1+8+1+2+len, SEEK_SET) < 0 || -#endif + if(my_fseek(file_recovery->handle, offset+1+8+1+2+len, SEEK_SET) < 0 || fread(&tmp, sizeof(tmp), 1, file_recovery->handle) != 1) return; mpi=(const uint16_t *)&tmp[0]; diff --git a/src/file_gsm.c b/src/file_gsm.c index aaeb8786..368fcc83 100644 --- a/src/file_gsm.c +++ b/src/file_gsm.c @@ -49,7 +49,7 @@ struct block_header { unsigned char marker; unsigned char payload[32]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_gsm(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_gz.c b/src/file_gz.c index 0edf8a1f..2dd8ac90 100644 --- a/src/file_gz.c +++ b/src/file_gz.c @@ -56,7 +56,7 @@ struct gzip_header uint32_t mtime; uint8_t extra_flags; uint8_t os; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static const unsigned char gz_header_magic[3]= {0x1F, 0x8B, 0x08}; /* flags: diff --git a/src/file_hdf.c b/src/file_hdf.c index fd02b689..e5746de8 100644 --- a/src/file_hdf.c +++ b/src/file_hdf.c @@ -37,6 +37,12 @@ #include "log.h" #endif +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_hdf(file_stat_t *file_stat); const file_hint_t file_hint_hdf= { @@ -53,7 +59,7 @@ struct ddh_struct { uint16_t size; uint32_t next; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct dd_struct { @@ -61,7 +67,7 @@ struct dd_struct uint16_t ref; uint32_t offset; uint32_t length; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_check_hdf(file_recovery_t *file_recovery) { @@ -75,12 +81,7 @@ static void file_check_hdf(file_recovery_t *file_recovery) const struct dd_struct *p; unsigned int i; unsigned int size; - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, offset, SEEK_SET) < 0 || -#else - fseek(file_recovery->handle, offset, SEEK_SET) < 0 || -#endif + if(my_fseek(file_recovery->handle, offset, SEEK_SET) < 0 || fread(&ddh, sizeof(ddh), 1, file_recovery->handle) !=1 || be16(ddh.size)==0 || fread(dd, sizeof(struct dd_struct)*be16(ddh.size), 1, file_recovery->handle) !=1) diff --git a/src/file_hds.c b/src/file_hds.c index 0bee2b63..ee12762e 100644 --- a/src/file_hds.c +++ b/src/file_hds.c @@ -52,7 +52,7 @@ struct parallels_header { uint32_t catalog_entries; uint32_t nb_sectors; char padding[24]; -} __attribute__((packed)); +} __attribute__((gcc_struct,__packed__)); static int header_check_hds(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_ico.c b/src/file_ico.c index 645b48aa..0b100446 100644 --- a/src/file_ico.c +++ b/src/file_ico.c @@ -60,7 +60,7 @@ struct ico_header uint16_t reserved; uint16_t type; uint16_t count; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct ico_directory { @@ -72,7 +72,7 @@ struct ico_directory uint16_t bits_per_pixel; uint32_t bitmap_size; uint32_t bitmap_offset; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_ico(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_ifo.c b/src/file_ifo.c index 1f13e6ad..f30939f2 100644 --- a/src/file_ifo.c +++ b/src/file_ifo.c @@ -58,7 +58,7 @@ struct ifo_hdr char name[12]; uint32_t ls_BUP[4]; uint32_t ls_IFO; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_ifo(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_indd.c b/src/file_indd.c index 12c88c09..eb2bba9e 100644 --- a/src/file_indd.c +++ b/src/file_indd.c @@ -33,6 +33,12 @@ #include "filegen.h" #include "log.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_indd(file_stat_t *file_stat); static int header_check_indd(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); static void file_check_indd(file_recovery_t *file_recovery); @@ -69,7 +75,7 @@ struct InDesignMasterPage { uint8_t fIrrelevant2 [8]; uint32_t fFilePages; uint8_t fIrrelevant3 [3812]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct InDesignContigObjMarker { uint8_t fGUID [16]; @@ -77,7 +83,7 @@ struct InDesignContigObjMarker { uint32_t fObjectClassID; uint32_t fStreamLength; uint32_t fChecksum; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_check_indd(file_recovery_t *file_recovery) { @@ -95,11 +101,7 @@ static void file_check_indd(file_recovery_t *file_recovery) #ifdef DEBUG_INDD log_info("file_check_indd offset=%llu (0x%llx)\n", (long long unsigned)offset, (long long unsigned)offset); #endif -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, offset, SEEK_SET) < 0) -#else - if(fseek(file_recovery->handle, offset, SEEK_SET) < 0) -#endif + if(my_fseek(file_recovery->handle, offset, SEEK_SET) < 0) { file_recovery->file_size=0; return ; diff --git a/src/file_it.c b/src/file_it.c index 1567893a..1782c7a4 100644 --- a/src/file_it.c +++ b/src/file_it.c @@ -67,7 +67,7 @@ struct impulse_header uint32_t Reserved; char Chnl_Pan[64]; char Chnl_Vol[64]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_it(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_jpg.c b/src/file_jpg.c index cf036d1f..c032d751 100644 --- a/src/file_jpg.c +++ b/src/file_jpg.c @@ -50,6 +50,12 @@ #include "file_tiff.h" #include "setdate.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + extern const file_hint_t file_hint_doc; extern const file_hint_t file_hint_indd; extern const file_hint_t file_hint_mov; @@ -109,7 +115,7 @@ struct MP_IFD_Field uint16_t type; uint32_t count; char value[0]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct MP_Entry { @@ -118,7 +124,7 @@ struct MP_Entry uint32_t offset; uint16_t dep1; uint16_t dep2; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static uint64_t check_mpo_be(const unsigned char *mpo, const uint64_t mpo_offset, const unsigned int size) { @@ -288,11 +294,7 @@ static void file_check_mpo(file_recovery_t *fr) do { offset+=2+size; -#ifdef HAVE_FSEEKO - if(fseeko(fr->handle, offset, SEEK_SET) < 0) -#else - if(fseek(fr->handle, offset, SEEK_SET) < 0) -#endif + if(my_fseek(fr->handle, offset, SEEK_SET) < 0) { fr->file_size=0; return ; @@ -775,11 +777,7 @@ static inline int jpeg_session_resume(struct jpeg_session_struct *jpeg_session) if(resume_memory((j_common_ptr)&jpeg_session->cinfo)) return -1; src = (my_source_mgr *) jpeg_session->cinfo.src; -#ifdef HAVE_FSEEKO - if(fseeko(jpeg_session->handle, jpeg_session->offset + src->file_size, SEEK_SET) < 0) -#else - if(fseek(jpeg_session->handle, jpeg_session->offset + src->file_size, SEEK_SET) < 0) -#endif + if(my_fseek(jpeg_session->handle, jpeg_session->offset + src->file_size, SEEK_SET) < 0) return -1; return 0; } @@ -792,11 +790,7 @@ static inline void jpeg_session_suspend(struct jpeg_session_struct *jpeg_session static void jpeg_session_start(struct jpeg_session_struct *jpeg_session) { -#ifdef HAVE_FSEEKO - if(fseeko(jpeg_session->handle, jpeg_session->offset, SEEK_SET) < 0) -#else - if(fseek(jpeg_session->handle, jpeg_session->offset, SEEK_SET) < 0) -#endif + if(my_fseek(jpeg_session->handle, jpeg_session->offset, SEEK_SET) < 0) { log_critical("jpeg_session_start: fseek failed.\n"); } @@ -1321,7 +1315,7 @@ struct sof_header uint16_t width; /* 1-65535 */ unsigned char nbr; /* 1-255 */ unsigned char data[0]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int jpg_check_sof0(const unsigned char *buffer, const unsigned int buffer_size, const unsigned i, const unsigned int size) { @@ -1352,11 +1346,7 @@ static void jpg_search_marker(file_recovery_t *file_recovery) return ; offset=file_recovery->offset_error / file_recovery->blocksize * file_recovery->blocksize; i=file_recovery->offset_error % file_recovery->blocksize; -#ifdef HAVE_FSEEKO - if(fseeko(infile, offset, SEEK_SET) < 0) -#else - if(fseek(infile, offset, SEEK_SET) < 0) -#endif + if(my_fseek(infile, offset, SEEK_SET) < 0) return ; do { @@ -1398,11 +1388,7 @@ static uint64_t jpg_check_structure(file_recovery_t *file_recovery, const unsign uint64_t thumb_offset=0; size_t nbytes; file_recovery->extra=0; -#ifdef HAVE_FSEEKO - if(fseeko(infile, 0, SEEK_SET) < 0) -#else - if(fseek(infile, 0, SEEK_SET) < 0) -#endif + if(my_fseek(infile, 0, SEEK_SET) < 0) return 0; if((nbytes=fread(&buffer, 1, sizeof(buffer), infile))>0) { diff --git a/src/file_lnk.c b/src/file_lnk.c index 9a523d6a..542be84f 100644 --- a/src/file_lnk.c +++ b/src/file_lnk.c @@ -68,7 +68,7 @@ struct lnk_header_s { uint32_t showWnd_value; /* 3Ch */ uint32_t hot_key; /* 40h */ uint64_t always_zero; /* 44h */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); /* These constants comes from winedump/lnk.c */ #define SCF_PIDL 1 diff --git a/src/file_lxo.c b/src/file_lxo.c index d19493e7..10dc3bcc 100644 --- a/src/file_lxo.c +++ b/src/file_lxo.c @@ -48,7 +48,7 @@ struct lxo_header char magic[4]; uint32_t size; char type[3]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_lxo(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_lzh.c b/src/file_lzh.c index 86b6f564..7052dde2 100644 --- a/src/file_lzh.c +++ b/src/file_lzh.c @@ -56,7 +56,7 @@ struct lzh_level0 uint8_t level; uint8_t filename_len; uint8_t filename[0]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct lzh_level1 { @@ -70,7 +70,7 @@ struct lzh_level1 uint8_t level; uint8_t filename_len; uint8_t filename[0]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct lzh_level2 { @@ -84,7 +84,7 @@ struct lzh_level2 uint16_t file_crc; uint8_t os_id; uint16_t next_header_size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_rename_level0(const char *old_filename) { diff --git a/src/file_m2ts.c b/src/file_m2ts.c index e307e447..a55c51a2 100644 --- a/src/file_m2ts.c +++ b/src/file_m2ts.c @@ -30,6 +30,12 @@ #include "types.h" #include "filegen.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_m2ts(file_stat_t *file_stat); static void register_header_check_ts(file_stat_t *file_stat); @@ -79,12 +85,7 @@ static void file_rename_ts_188(const char *old_filename) unsigned int pid; if((file=fopen(old_filename, "rb"))==NULL) return; - if( -#ifdef HAVE_FSEEKO - fseeko(file, 0, SEEK_SET) < 0 || -#else - fseek(file, 0, SEEK_SET) < 0 || -#endif + if(my_fseek(file, 0, SEEK_SET) < 0 || fread(&buffer, sizeof(buffer), 1, file) != 1) { fclose(file); @@ -104,12 +105,7 @@ static void file_rename_ts_192(const char *old_filename) unsigned int pid; if((file=fopen(old_filename, "rb"))==NULL) return; - if( -#ifdef HAVE_FSEEKO - fseeko(file, 0, SEEK_SET) < 0 || -#else - fseek(file, 0, SEEK_SET) < 0 || -#endif + if(my_fseek(file, 0, SEEK_SET) < 0 || fread(&buffer, sizeof(buffer), 1, file) != 1) { fclose(file); diff --git a/src/file_mb.c b/src/file_mb.c index 760dcfb4..4ae761a6 100644 --- a/src/file_mb.c +++ b/src/file_mb.c @@ -48,7 +48,7 @@ struct maya_header char magic[4]; uint32_t size; char magic2[8]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_mb(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_mid.c b/src/file_mid.c index 2ea72d68..d468720f 100644 --- a/src/file_mid.c +++ b/src/file_mid.c @@ -32,6 +32,12 @@ #include "common.h" #include "log.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_mid(file_stat_t *file_stat); const file_hint_t file_hint_mid= { @@ -53,7 +59,7 @@ struct midi_header uint16_t format; uint16_t tracks; int16_t time_division; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_check_midi(file_recovery_t *file_recovery) { @@ -63,12 +69,7 @@ static void file_check_midi(file_recovery_t *file_recovery) unsigned int tracks; uint64_t fs=4+4+6; file_recovery->file_size=0; - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, 0, SEEK_SET) < 0 || -#else - fseek(file_recovery->handle, 0, SEEK_SET) < 0 || -#endif + if(my_fseek(file_recovery->handle, 0, SEEK_SET) < 0 || fread(&hdr, sizeof(hdr), 1, file_recovery->handle) != 1) return ; tracks=be16(hdr.tracks); @@ -78,11 +79,7 @@ static void file_check_midi(file_recovery_t *file_recovery) #ifdef DEBUG_MIDI log_info("file_check_midi 0x%08llx\n", (unsigned long long)fs); #endif -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, fs, SEEK_SET) < 0 || -#else - if(fseek(file_recovery->handle, fs, SEEK_SET) < 0 || -#endif + if(my_fseek(file_recovery->handle, fs, SEEK_SET) < 0 || fread(&track, 8, 1, file_recovery->handle) != 1 || memcmp(&track.magic[0], "MTrk", 4)!=0) return ; diff --git a/src/file_mig.c b/src/file_mig.c index 5274407a..eb9c29dc 100644 --- a/src/file_mig.c +++ b/src/file_mig.c @@ -34,6 +34,12 @@ #include "log.h" #endif +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_mig(file_stat_t *file_stat); const file_hint_t file_hint_mig= { @@ -55,7 +61,7 @@ struct MIG_HDR uint32_t unk2; uint32_t unk3; unsigned char fn[0]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_check_mig(file_recovery_t *file_recovery) { @@ -65,11 +71,7 @@ static void file_check_mig(file_recovery_t *file_recovery) while(1) { size_t res; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, offset, SEEK_SET) < 0) -#else - if(fseek(file_recovery->handle, offset, SEEK_SET) < 0) -#endif + if(my_fseek(file_recovery->handle, offset, SEEK_SET) < 0) { #ifdef DEBUG_MIG log_info("0x%lx fseek failed\n", (long unsigned)offset); diff --git a/src/file_mlv.c b/src/file_mlv.c index add3fedb..d139eee2 100644 --- a/src/file_mlv.c +++ b/src/file_mlv.c @@ -31,6 +31,12 @@ #include "filegen.h" #include "common.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_mlv(file_stat_t *file_stat); const file_hint_t file_hint_mlv= { @@ -58,13 +64,13 @@ typedef struct { uint32_t audioFrameCount; /* number of audio frames in this file. set to 0 on start, updated when finished. */ uint32_t sourceFpsNom; /* configured fps in 1/s multiplied by sourceFpsDenom */ uint32_t sourceFpsDenom; /* denominator for fps. usually set to 1000, but may be 1001 for NTSC */ -} __attribute__ ((__packed__)) mlv_file_hdr_t; +} __attribute__ ((gcc_struct, __packed__)) mlv_file_hdr_t; typedef struct { uint8_t blockType[4]; uint32_t blockSize; uint64_t timestamp; -} __attribute__ ((__packed__)) mlv_hdr_t; +} __attribute__ ((gcc_struct, __packed__)) mlv_hdr_t; static int is_valid_type(const mlv_hdr_t *hdr) { @@ -98,12 +104,7 @@ static void file_check_mlv(file_recovery_t *file_recovery) uint64_t fs=0; do { - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, fs, SEEK_SET)<0 || -#else - fseek(file_recovery->handle, fs, SEEK_SET)<0 || -#endif + if(my_fseek(file_recovery->handle, fs, SEEK_SET)<0 || fread(&hdr, sizeof(hdr), 1, file_recovery->handle)!=1 || le32(hdr.blockSize)<0x10 || !is_valid_type(&hdr) || diff --git a/src/file_mov.c b/src/file_mov.c index 077f0ae4..4cc4b051 100644 --- a/src/file_mov.c +++ b/src/file_mov.c @@ -70,14 +70,14 @@ struct atom_struct { uint32_t size; uint32_t type; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct atom64_struct { uint32_t size1; uint32_t type; uint64_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_rename_mov(const char *old_filename) { diff --git a/src/file_mrw.c b/src/file_mrw.c index c6398499..2a478d7b 100644 --- a/src/file_mrw.c +++ b/src/file_mrw.c @@ -56,7 +56,7 @@ struct hdr { uint32_t fourcc; uint32_t size; char data[0]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct prd { char ver[8]; @@ -74,7 +74,7 @@ struct prd { uint8_t unknown1; uint16_t unknown2; uint16_t pattern; // 0x0001 RGGB, or 0x0004 GBRG -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); /* Minolta */ static int header_check_mrw(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) diff --git a/src/file_nes.c b/src/file_nes.c index 27c6f36f..91e2d176 100644 --- a/src/file_nes.c +++ b/src/file_nes.c @@ -48,7 +48,7 @@ struct nes_header char ident[4]; uint8_t prgsize; uint8_t chrsize; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_nes(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_nk2.c b/src/file_nk2.c index 87c40fb0..624d7dc1 100644 --- a/src/file_nk2.c +++ b/src/file_nk2.c @@ -32,6 +32,12 @@ #include "common.h" #include "log.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_nk2(file_stat_t *file_stat); static int header_check_nk2(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); static void file_check_nk2(file_recovery_t *file_recovery); @@ -112,12 +118,7 @@ static void file_check_nk2(file_recovery_t *fr) fr->file_size = 0; fr->offset_error=0; fr->offset_ok=0; - if( -#ifdef HAVE_FSEEKO - fseeko(fr->handle, 0, SEEK_SET) < 0 || -#else - fseek(fr->handle, 0, SEEK_SET) < 0 || -#endif + if(my_fseek(fr->handle, 0, SEEK_SET) < 0 || fread(&nk2h, sizeof(nk2h), 1, fr->handle)!=1) return; fr->file_size+=sizeof(nk2h); @@ -192,11 +193,7 @@ static void file_check_nk2(file_recovery_t *fr) } #endif fr->file_size+=sizeof(entryh); -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, fr->file_size+size, SEEK_SET) < 0) -#else - if (fseek(fr->handle, fr->file_size+size, SEEK_SET) < 0) -#endif + if (my_fseek(fr->handle, fr->file_size+size, SEEK_SET) < 0) { fr->offset_error=fr->file_size; fr->file_size=0; diff --git a/src/file_oci.c b/src/file_oci.c index 976cccc4..19a29b99 100644 --- a/src/file_oci.c +++ b/src/file_oci.c @@ -47,7 +47,7 @@ struct oci_header { unsigned char type[4]; uint32_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_oci(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_par2.c b/src/file_par2.c index a82fb39d..ceb1ba45 100644 --- a/src/file_par2.c +++ b/src/file_par2.c @@ -32,6 +32,12 @@ #include "common.h" #include "log.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_par2(file_stat_t *file_stat); const file_hint_t file_hint_par2= { @@ -76,11 +82,7 @@ static void file_rename_par2(const char *old_filename) size_t buffer_size; unsigned char buffer[4096]; const uint64_t *lengthp=(const uint64_t *)&buffer[8]; -#ifdef HAVE_FSEEKO - if(fseeko(file, offset, SEEK_SET)<0) -#else - if(fseek(file, offset, SEEK_SET)<0) -#endif + if(my_fseek(file, offset, SEEK_SET)<0) { fclose(file); return; diff --git a/src/file_pct.c b/src/file_pct.c index b97ec7a9..1a58f647 100644 --- a/src/file_pct.c +++ b/src/file_pct.c @@ -78,7 +78,7 @@ struct pct_file_entry { uint16_t OYMax; #endif uint32_t Reserved2; /* 0x24 */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void register_header_check_pct(file_stat_t *file_stat) { diff --git a/src/file_pcx.c b/src/file_pcx.c index 7eff9e62..6332f6ef 100644 --- a/src/file_pcx.c +++ b/src/file_pcx.c @@ -76,7 +76,7 @@ struct pcx_file_entry { uint16_t HScrSize; /* only supported by */ uint16_t VScrSize; /* PC Paintbrush IV or higher */ uint8_t Filler[56]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void register_header_check_pcx(file_stat_t *file_stat) { diff --git a/src/file_pdf.c b/src/file_pdf.c index c48d455b..818cb43e 100644 --- a/src/file_pdf.c +++ b/src/file_pdf.c @@ -39,6 +39,12 @@ #include "memmem.h" #include "common.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_pdf(file_stat_t *file_stat); static void file_date_pdf(file_recovery_t *file_recovery); @@ -76,11 +82,7 @@ static void file_rename_pdf(const char *old_filename) const unsigned char utf16[3]= { 0xfe, 0xff, 0x00}; if((handle=fopen(old_filename, "rb"))==NULL) return; -#ifdef HAVE_FSEEKO - if(fseeko(handle, 0, SEEK_END)<0) -#else - if(fseek(handle, 0, SEEK_END)<0) -#endif + if(my_fseek(handle, 0, SEEK_END)<0) { fclose(handle); return; @@ -102,11 +104,7 @@ static void file_rename_pdf(const char *old_filename) return; } offset+=sizeof(pattern); -#ifdef HAVE_FSEEKO - if(fseeko(handle, offset, SEEK_SET)<0) -#else - if(fseek(handle, offset, SEEK_SET)<0) -#endif + if(my_fseek(handle, offset, SEEK_SET)<0) { fclose(handle); return ; @@ -202,11 +200,7 @@ static void file_check_pdf_and_size(file_recovery_t *file_recovery) int i; int taille; file_recovery->file_size=file_recovery->calculated_file_size; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle,file_recovery->file_size-read_size,SEEK_SET)<0) -#else - if(fseek(file_recovery->handle,file_recovery->file_size-read_size,SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle,file_recovery->file_size-read_size,SEEK_SET)<0) { file_recovery->file_size=0; return ; @@ -238,11 +232,7 @@ static void file_date_pdf(file_recovery_t *file_recovery) uint64_t offset=0; unsigned int j=0; unsigned char*buffer=(unsigned char*)MALLOC(4096); -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, 0, SEEK_SET)<0) -#else - if(fseek(file_recovery->handle, 0, SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle, 0, SEEK_SET)<0) { free(buffer); return ; @@ -264,11 +254,7 @@ static void file_date_pdf(file_recovery_t *file_recovery) { const unsigned char *date_asc; struct tm tm_time; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, offset+i+1, SEEK_SET)<0) -#else - if(fseek(file_recovery->handle, offset+i+1, SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle, offset+i+1, SEEK_SET)<0) { free(buffer); return ; diff --git a/src/file_png.c b/src/file_png.c index ae625225..014b1b79 100644 --- a/src/file_png.c +++ b/src/file_png.c @@ -38,6 +38,12 @@ #include "common.h" #include "filegen.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + extern const file_hint_t file_hint_doc; static void register_header_check_png(file_stat_t *file_stat); @@ -60,7 +66,7 @@ struct png_chunk uint32_t type; char data[0]; /* data is followed by uint32_t crc; */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_jng(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { @@ -110,12 +116,7 @@ static void file_check_png(file_recovery_t *fr) { char buffer[8]; const struct png_chunk *chunk=(const struct png_chunk *)&buffer; - if( -#ifdef HAVE_FSEEKO - fseeko(fr->handle, fr->file_size, SEEK_SET) < 0 || -#else - fseek(fr->handle, fr->file_size, SEEK_SET) < 0 || -#endif + if(my_fseek(fr->handle, fr->file_size, SEEK_SET) < 0 || fread(&buffer, sizeof(buffer), 1, fr->handle) != 1) { fr->file_size=0; diff --git a/src/file_prc.c b/src/file_prc.c index 3177ce1a..c94d90a5 100644 --- a/src/file_prc.c +++ b/src/file_prc.c @@ -64,7 +64,7 @@ struct DatabaseHdrType_s { uint32_t creator; /* 0x40 */ uint32_t uniqueIDSeed; /* 0x44 */ /* RecordListType recordList; */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_prc(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_psb.c b/src/file_psb.c index 6bd4ea3e..6e91e719 100644 --- a/src/file_psb.c +++ b/src/file_psb.c @@ -50,6 +50,7 @@ const file_hint_t file_hint_psb= { }; static uint64_t psb_image_data_size_max=0; + struct psb_file_header { char signature[4]; @@ -60,7 +61,7 @@ struct psb_file_header uint32_t width; /* max of 300,000 */ uint16_t depth; /* 1, 8, 16 or 32 */ uint16_t color_mode; /* Bitmap = 0; Grayscale = 1; Indexed = 2; RGB = 3; CMYK = 4; Multichannel = 7; Duotone = 8; Lab = 9 */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_psb(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_psd.c b/src/file_psd.c index ed1c347e..0237da34 100644 --- a/src/file_psd.c +++ b/src/file_psd.c @@ -61,7 +61,7 @@ struct psd_file_header uint32_t width; /* max of 30,000 */ uint16_t depth; /* 1, 8, 16 or 32 */ uint16_t color_mode; /* Bitmap = 0; Grayscale = 1; Indexed = 2; RGB = 3; CMYK = 4; Multichannel = 7; Duotone = 8; Lab = 9 */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_psd(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_psp.c b/src/file_psp.c index 1da02d4d..1ace5bbf 100644 --- a/src/file_psp.c +++ b/src/file_psp.c @@ -53,7 +53,7 @@ struct psp_chunk { char header[4]; uint16_t id; uint32_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_psp(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_r3d.c b/src/file_r3d.c index a39c47a5..4b797673 100644 --- a/src/file_r3d.c +++ b/src/file_r3d.c @@ -54,7 +54,7 @@ struct atom_struct { uint32_t size; uint32_t type; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static data_check_t data_check_r3d(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { diff --git a/src/file_ra.c b/src/file_ra.c index d0182e2c..e9ca056c 100644 --- a/src/file_ra.c +++ b/src/file_ra.c @@ -51,7 +51,7 @@ struct ra3_header { uint32_t data_size; uint8_t title_length; char title[0]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct ra4_header { char magic[4]; @@ -79,8 +79,7 @@ struct ra4_header { char unk4[3]; uint8_t title_length; char title[0]; -} __attribute__ ((__packed__)); - +} __attribute__ ((gcc_struct, __packed__)); static int header_check_ra(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_raf.c b/src/file_raf.c index efff4560..5bbd5ca0 100644 --- a/src/file_raf.c +++ b/src/file_raf.c @@ -59,7 +59,7 @@ struct header_raf uint32_t cfa_header_size; uint32_t cfa_offset; uint32_t cfa_size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_raf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_reg.c b/src/file_reg.c index 931891c0..b6f2e501 100644 --- a/src/file_reg.c +++ b/src/file_reg.c @@ -54,7 +54,7 @@ struct creg_file_header uint32_t uk2; uint32_t uk3; uint32_t uk4; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct rgdb_block { @@ -68,7 +68,7 @@ struct rgdb_block uint16_t first_free_id; uint32_t uk1; uint32_t chksum; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_reg_9x(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { @@ -102,7 +102,7 @@ struct regf_file_header uint8_t unknown5[ 64 ]; uint8_t unknown6[ 396 ]; uint32_t xor_checksum; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_reg_nt(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_riff.c b/src/file_riff.c index 5c97df91..397cf878 100644 --- a/src/file_riff.c +++ b/src/file_riff.c @@ -34,6 +34,12 @@ #include "log.h" #endif +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + data_check_t data_check_avi_stream(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery); static void register_header_check_riff(file_stat_t *file_stat); @@ -104,11 +110,7 @@ static void check_riff_list(file_recovery_t *fr, const unsigned int depth, const return; for(file_size=start; file_size < end;) { -#ifdef HAVE_FSEEKO - if(fseeko(fr->handle, file_size, SEEK_SET)<0) -#else - if(fseek(fr->handle, file_size, SEEK_SET)<0) -#endif + if(my_fseek(fr->handle, file_size, SEEK_SET)<0) { fr->offset_error=file_size; return; @@ -147,11 +149,7 @@ static void file_check_avi(file_recovery_t *fr) { const uint64_t file_size=fr->file_size; riff_list_header list_header; -#ifdef HAVE_FSEEKO - if(fseeko(fr->handle, fr->file_size, SEEK_SET)<0) -#else - if(fseek(fr->handle, fr->file_size, SEEK_SET)<0) -#endif + if(my_fseek(fr->handle, fr->file_size, SEEK_SET)<0) { fr->file_size=0; return ; diff --git a/src/file_rm.c b/src/file_rm.c index 22ef77d8..e118df08 100644 --- a/src/file_rm.c +++ b/src/file_rm.c @@ -51,7 +51,7 @@ struct rm_header uint16_t version; uint32_t file_version; uint32_t header_nbr; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_rm(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_rpm.c b/src/file_rpm.c index cbe3d835..56c407a6 100644 --- a/src/file_rpm.c +++ b/src/file_rpm.c @@ -54,7 +54,7 @@ struct rpmlead { uint16_t osnum; uint16_t signature_type; char reserved[16]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static void file_rename_rpm(const char *old_filename) { diff --git a/src/file_rx2.c b/src/file_rx2.c index 0c8a0b55..261f6543 100644 --- a/src/file_rx2.c +++ b/src/file_rx2.c @@ -49,7 +49,7 @@ struct rx2_header { uint32_t magic; uint32_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_rx2(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_sp3.h b/src/file_sp3.h index 61e8c5e8..2692237e 100644 --- a/src/file_sp3.h +++ b/src/file_sp3.h @@ -303,4 +303,4 @@ struct SP3FileInfo uint32_t Prove_UC_CRC32; char zzReserved999[1024*10-1312]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); diff --git a/src/file_spe.c b/src/file_spe.c index eae09ceb..0318d6f5 100644 --- a/src/file_spe.c +++ b/src/file_spe.c @@ -236,7 +236,7 @@ struct header_spe char Istring[40]; /* 3978 special Intensity scaling string */ char empty3[80]; /* 4018 empty block to reach 4100 bytes */ int16_t lastvalue; /* 4098 Always the LAST value in the header */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static const unsigned char spe_header[4]= {0x67, 0x45, 0x23, 0x01}; diff --git a/src/file_spf.c b/src/file_spf.c index 3480df3e..45030006 100644 --- a/src/file_spf.c +++ b/src/file_spf.c @@ -32,6 +32,12 @@ #include "filegen.h" #include "common.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_spf(file_stat_t *file_stat); static int header_check_spf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); static void file_check_spf(file_recovery_t *file_recovery); @@ -74,11 +80,7 @@ static void file_check_spf(file_recovery_t *file_recovery) unsigned char*buffer; buffer=(unsigned char*)MALLOC(READ_SIZE); file_recovery->file_size=0; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, 0, SEEK_SET)<0) -#else - if(fseek(file_recovery->handle, 0, SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle, 0, SEEK_SET)<0) { free(buffer); return; diff --git a/src/file_sql.c b/src/file_sql.c index 39b36c09..21b7f350 100644 --- a/src/file_sql.c +++ b/src/file_sql.c @@ -70,7 +70,7 @@ struct db_header char reserved_for_expansion[20]; uint32_t version_valid_for; uint32_t version; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_sqlite(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_swf.c b/src/file_swf.c index 22961786..543b6840 100644 --- a/src/file_swf.c +++ b/src/file_swf.c @@ -51,7 +51,7 @@ struct swf_header char magic[3]; unsigned char version; uint32_t size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int read_SB(const unsigned char **data, unsigned int *offset_bit, unsigned int nbit) { diff --git a/src/file_tib.c b/src/file_tib.c index 2fb9c307..2b0bc387 100644 --- a/src/file_tib.c +++ b/src/file_tib.c @@ -34,6 +34,12 @@ #include "filegen.h" #include "common.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static void register_header_check_tib(file_stat_t *file_stat); static int header_check_tib(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); @@ -67,12 +73,7 @@ static void file_check_tib2(file_recovery_t *file_recovery) unsigned char*buffer=(unsigned char*)MALLOC(512); int64_t file_size=file_recovery->calculated_file_size-512; file_recovery->file_size = file_recovery->calculated_file_size; - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, file_size, SEEK_SET) < 0 || -#else - fseek(file_recovery->handle, file_size, SEEK_SET) < 0 || -#endif + if(my_fseek(file_recovery->handle, file_size, SEEK_SET) < 0 || fread(buffer, 1, 512, file_recovery->handle) != 512) { free(buffer); @@ -88,12 +89,7 @@ static void file_check_tib2(file_recovery_t *file_recovery) for(; file_size>0; file_size-=512) { unsigned int i; - if( -#ifdef HAVE_FSEEKO - fseeko(file_recovery->handle, file_size, SEEK_SET) < 0 || -#else - fseek(file_recovery->handle, file_size, SEEK_SET) < 0 || -#endif + if(my_fseek(file_recovery->handle, file_size, SEEK_SET) < 0 || fread(buffer, 1, 512, file_recovery->handle) != 512) { free(buffer); diff --git a/src/file_tiff.h b/src/file_tiff.h index db5fe871..21fa5fdf 100644 --- a/src/file_tiff.h +++ b/src/file_tiff.h @@ -60,12 +60,10 @@ typedef struct { } TIFFDirEntry; /* Work around a gcc bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 */ -#pragma pack(1) struct ifd_header { uint16_t nbr_fields; TIFFDirEntry ifd; -} __attribute__ ((__packed__)); -#pragma pack() +} __attribute__ ((gcc_struct, __packed__)); time_t get_date_from_tiff_header(const TIFFHeader *tiff, const unsigned int tiff_size); const char *find_tag_from_tiff_header(const TIFFHeader *tiff, const unsigned int tiff_size, const unsigned int tag, const char **potential_error); diff --git a/src/file_vmdk.c b/src/file_vmdk.c index e2126adc..753a9020 100644 --- a/src/file_vmdk.c +++ b/src/file_vmdk.c @@ -72,7 +72,7 @@ typedef struct { int64_t grain_offset; char filler[1]; char check_bytes[4]; -} __attribute__((packed)) VMDK4Header; +} __attribute__((gcc_struct,__packed__)) VMDK4Header; static int header_check_vmdk3(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_wim.c b/src/file_wim.c index d5f66f4c..cecee244 100644 --- a/src/file_wim.c +++ b/src/file_wim.c @@ -53,7 +53,7 @@ struct reshdr_disk_short }; uint64_t offset; uint64_t original_size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); #define RESHDR_GET_SIZE(R) (le64(R.size) & 0x00FFFFFFFFFFFFFF) @@ -74,7 +74,7 @@ struct _WIMHEADER_V1_PACKED uint32_t dwBootIndex; struct reshdr_disk_short rhIntegrity; unsigned char bUnused[60]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_wim(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_wmf.c b/src/file_wmf.c index 5941c553..2622d024 100644 --- a/src/file_wmf.c +++ b/src/file_wmf.c @@ -54,7 +54,7 @@ struct wmf_header uint16_t num_objects; uint32_t max_record; uint16_t members; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_wmf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_woff.c b/src/file_woff.c index f40e04be..14855fea 100644 --- a/src/file_woff.c +++ b/src/file_woff.c @@ -58,7 +58,7 @@ struct WOFFHeader uint32_t metaOrigLength; uint32_t privOffset; uint32_t privLength; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_woff(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_wpd.c b/src/file_wpd.c index b2e692d3..6efbceed 100644 --- a/src/file_wpd.c +++ b/src/file_wpd.c @@ -56,7 +56,7 @@ struct wpd_hdr uint16_t indexHeaderOffset; /* 14 */ uint32_t unk; uint32_t documentSize; /* 20: WP 6.1 or later ? */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_wpd(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_x3f.c b/src/file_x3f.c index 40015bd9..eed5bfdf 100644 --- a/src/file_x3f.c +++ b/src/file_x3f.c @@ -54,7 +54,7 @@ struct x3f_header uint32_t rows; uint32_t rotation; /* version 2.1 and later have additional fields */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_x3f(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_xcf.c b/src/file_xcf.c index 8e58e189..a535a50d 100644 --- a/src/file_xcf.c +++ b/src/file_xcf.c @@ -53,7 +53,7 @@ struct xcf_header uint32_t width; uint32_t heigth; uint32_t base_type; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_xcf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_xpt.c b/src/file_xpt.c index 57087d15..fa238b56 100644 --- a/src/file_xpt.c +++ b/src/file_xpt.c @@ -52,7 +52,7 @@ struct TypeLibHeader { uint8_t minor_version; uint16_t num_interfaces; uint32_t file_length; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); static int header_check_xpt(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { diff --git a/src/file_zip.c b/src/file_zip.c index 8fef36f5..4ca2c77e 100644 --- a/src/file_zip.c +++ b/src/file_zip.c @@ -41,6 +41,13 @@ #include "log.h" /* #define DEBUG_ZIP */ + +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + extern const file_hint_t file_hint_doc; static void register_header_check_zip(file_stat_t *file_stat); static int header_check_zip(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); @@ -92,8 +99,7 @@ struct zip_file_entry { uint32_t uncompressed_size; /** Uncompressed size */ uint16_t filename_length; /** Filename length */ uint16_t extra_length; /** Extra fields length */ -} __attribute__ ((__packed__)); -typedef struct zip_file_entry zip_file_entry_t; +} __attribute__ ((gcc_struct, __packed__)); struct zip64_extra_entry { @@ -103,7 +109,9 @@ struct zip64_extra_entry uint64_t compressed_size; uint64_t offset; /* Offset of local header record */ uint32_t disk_start_number; /* Number of the disk on which this file starts */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); + +typedef struct zip_file_entry zip_file_entry_t; typedef struct zip64_extra_entry zip64_extra_entry_t; static uint32_t expected_compressed_size=0; @@ -128,11 +136,7 @@ static int64_t file_get_pos(FILE *f, const void* needle, const unsigned int size if (buffer[count]==*(const char *)needle && memcmp(buffer+count, needle, size)==0) { free(buffer); -#ifdef HAVE_FSEEKO - if(fseeko(f, (long)count-read_size, SEEK_CUR)<0) -#else - if(fseek(f, (long)count-read_size, SEEK_CUR)<0) -#endif + if(my_fseek(f, (long)count-read_size, SEEK_CUR)<0) return -1; return total; } @@ -140,11 +144,7 @@ static int64_t file_get_pos(FILE *f, const void* needle, const unsigned int size total++; left--; } -#ifdef HAVE_FSEEKO - if(feof(f) || fseeko(f, (long)1-size, SEEK_CUR)<0) -#else - if(feof(f) || fseek(f, (long)1-size, SEEK_CUR)<0) -#endif + if(feof(f) || my_fseek(f, (long)1-size, SEEK_CUR)<0) { free(buffer); return -1; @@ -226,11 +226,7 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns free(filename); return -1; } -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, -to_read, SEEK_CUR) < 0) -#else - if (fseek(fr->handle, -to_read, SEEK_CUR) < 0) -#endif + if (my_fseek(fr->handle, -to_read, SEEK_CUR) < 0) { log_info("fseek failed\n"); free(filename); @@ -319,13 +315,8 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns log_trace("zip: Unexpected EOF in file_entry header: %lu bytes expected\n", len); #endif } -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, fr->file_size, SEEK_SET) == -1 || - fseeko(fr->handle, len, SEEK_CUR) == -1) -#else - if (fseek(fr->handle, fr->file_size, SEEK_SET) == -1 || - fseek(fr->handle, len, SEEK_CUR) == -1) -#endif + if (my_fseek(fr->handle, fr->file_size, SEEK_SET) == -1 || + my_fseek(fr->handle, len, SEEK_CUR) == -1) { #ifdef DEBUG_ZIP log_trace("zip: Unexpected EOF in file_entry header: %lu bytes expected\n", len); @@ -343,11 +334,7 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns len=krita; if (len>0) { -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, len, SEEK_CUR) == -1) -#else - if (fseek(fr->handle, len, SEEK_CUR) == -1) -#endif + if (my_fseek(fr->handle, len, SEEK_CUR) == -1) { #ifdef DEBUG_ZIP log_trace("zip: Unexpected EOF in file_entry data: %lu bytes expected\n", len); @@ -396,12 +383,8 @@ static int zip_parse_central_dir(file_recovery_t *fr) uint16_t internal_attr; /** Internal file attributes */ uint32_t external_attr; /** External file attributes */ uint32_t offset_header; /** Relative offset of local header */ - } __attribute__ ((__packed__)) dir; -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, 2, SEEK_CUR) == -1) -#else - if (fseek(fr->handle, 2, SEEK_CUR) == -1) -#endif + } __attribute__ ((gcc_struct, __packed__)) dir; + if (my_fseek(fr->handle, 2, SEEK_CUR) == -1) { #ifdef DEBUG_ZIP log_trace("Unexpected EOF skipping version from central_dir\n"); @@ -433,11 +416,7 @@ static int zip_parse_central_dir(file_recovery_t *fr) /* Rest of the block - could attempt CRC check */ len = le16(file.extra_length) + le16(dir.comment_length) + le16(file.filename_length); -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, len, SEEK_CUR) == -1) -#else - if (fseek(fr->handle, len, SEEK_CUR) == -1) -#endif + if (my_fseek(fr->handle, len, SEEK_CUR) == -1) { #ifdef DEBUG_ZIP log_trace("zip: Unexpected EOF in central_dir: %u bytes expected\n", len); @@ -463,7 +442,7 @@ static int zip64_parse_end_central_dir(file_recovery_t *fr) uint64_t number_entries2; /** Total number of entries in the central directory */ uint64_t size; /** Size of the central directory */ uint64_t offset; /** Offset of start of central directory */ - } __attribute__ ((__packed__)) dir; + } __attribute__ ((gcc_struct, __packed__)) dir; if (fread(&dir, sizeof(dir), 1, fr->handle) != 1) { @@ -477,11 +456,7 @@ static int zip64_parse_end_central_dir(file_recovery_t *fr) if (dir.end_size > 0) { const uint64_t len = le64(dir.end_size); -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, len, SEEK_CUR) == -1) -#else - if (fseek(fr->handle, len, SEEK_CUR) == -1) -#endif + if (my_fseek(fr->handle, len, SEEK_CUR) == -1) { #ifdef DEBUG_ZIP log_trace("zip: Unexpected EOF in end_central_dir_64: expected %llu bytes\n", (long long unsigned)len); @@ -507,7 +482,7 @@ static int zip_parse_end_central_dir(file_recovery_t *fr) uint32_t size; /** Size of the central directory */ uint32_t offset; /** Offset of start of central directory */ uint16_t comment_length; /** Comment length */ - } __attribute__ ((__packed__)) dir; + } __attribute__ ((gcc_struct, __packed__)) dir; if (fread(&dir, sizeof(dir), 1, fr->handle) != 1) { @@ -521,11 +496,7 @@ static int zip_parse_end_central_dir(file_recovery_t *fr) if (dir.comment_length) { const uint16_t len = le16(dir.comment_length); -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, len, SEEK_CUR) == -1) -#else - if (fseek(fr->handle, len, SEEK_CUR) == -1) -#endif + if (my_fseek(fr->handle, len, SEEK_CUR) == -1) { #ifdef DEBUG_ZIP log_trace("zip: Unexpected EOF in end_central_dir: expected %u bytes\n", len); @@ -546,7 +517,7 @@ static int zip_parse_data_desc(file_recovery_t *fr) uint32_t crc32; /** Checksum (CRC32) */ uint32_t compressed_size; /** Compressed size (bytes) */ uint32_t uncompressed_size; /** Uncompressed size (bytes) */ - } __attribute__ ((__packed__)) desc; + } __attribute__ ((gcc_struct, __packed__)) desc; if (fread(&desc, sizeof(desc), 1, fr->handle) != 1) { @@ -583,11 +554,7 @@ static int zip_parse_signature(file_recovery_t *fr) if (len) { len = le16(len); -#ifdef HAVE_FSEEKO - if (fseeko(fr->handle, len, SEEK_CUR) == -1) -#else - if (fseek(fr->handle, len, SEEK_CUR) == -1) -#endif + if (my_fseek(fr->handle, len, SEEK_CUR) == -1) { #ifdef DEBUG_ZIP log_trace("zip: Unexpected EOF in zip_parse_signature: expected %u bytes\n", len); @@ -606,7 +573,7 @@ static int zip64_parse_end_central_dir_locator(file_recovery_t *fr) uint32_t disk_number; /** Number of the disk with the start of the zip64 end of central directory */ uint64_t relative_offset; /** Relative offset of the zip64 end of central directory record */ uint32_t disk_total_number; /** Total number of disks */ - } __attribute__ ((__packed__)) loc; + } __attribute__ ((gcc_struct, __packed__)) loc; if (fread(&loc, sizeof(loc), 1, fr->handle) != 1) { @@ -627,11 +594,7 @@ static void file_check_zip(file_recovery_t *fr) fr->offset_error=0; fr->offset_ok=0; first_filename[0]='\0'; -#ifdef HAVE_FSEEKO - if(fseeko(fr->handle, 0, SEEK_SET) < 0) -#else - if(fseek(fr->handle, 0, SEEK_SET) < 0) -#endif + if(my_fseek(fr->handle, 0, SEEK_SET) < 0) return ; while (1) { @@ -717,11 +680,7 @@ static void file_rename_zip(const char *old_filename) fr.file_size = 0; fr.offset_error=0; first_filename[0]='\0'; -#ifdef HAVE_FSEEKO - if(fseeko(fr.handle, 0, SEEK_SET) < 0) -#else - if(fseek(fr.handle, 0, SEEK_SET) < 0) -#endif + if(my_fseek(fr.handle, 0, SEEK_SET) < 0) { fclose(fr.handle); return ; diff --git a/src/filegen.c b/src/filegen.c index 6854363f..fee262d3 100644 --- a/src/filegen.c +++ b/src/filegen.c @@ -36,6 +36,12 @@ #include "filegen.h" #include "log.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + static file_check_t file_check_plist={ .list = TD_LIST_HEAD_INIT(file_check_plist.list) }; @@ -179,11 +185,7 @@ void file_allow_nl(file_recovery_t *file_recovery, const unsigned int nl_mode) { unsigned char buffer[4096]; int taille; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, file_recovery->file_size,SEEK_SET)<0) -#else - if(fseek(file_recovery->handle, file_recovery->file_size,SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle, file_recovery->file_size,SEEK_SET)<0) return; taille=fread(buffer,1, 4096,file_recovery->handle); if(taille > 0 && buffer[0]=='\n' && (nl_mode&NL_BARENL)==NL_BARENL) @@ -205,11 +207,7 @@ uint64_t file_rsearch(FILE *handle, uint64_t offset, const void*footer, const un int taille; const unsigned int read_size=(offset%4096!=0 ? offset%4096 : 4096); offset-=read_size; -#ifdef HAVE_FSEEKO - if(fseeko(handle,offset,SEEK_SET)<0) -#else - if(fseek(handle,offset,SEEK_SET)<0) -#endif + if(my_fseek(handle,offset,SEEK_SET)<0) { free(buffer); return 0; @@ -257,11 +255,7 @@ void file_search_lc_footer(file_recovery_t *file_recovery, const unsigned char*f file_size=file_size-(file_size%read_size); else file_size-=read_size; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle,file_size,SEEK_SET)<0) -#else - if(fseek(file_recovery->handle,file_size,SEEK_SET)<0) -#endif + if(my_fseek(file_recovery->handle,file_size,SEEK_SET)<0) { free(buffer); return; diff --git a/src/hdaccess.c b/src/hdaccess.c index 8e0634aa..f0929954 100644 --- a/src/hdaccess.c +++ b/src/hdaccess.c @@ -135,7 +135,7 @@ struct tdewf_file_header * 0x00 0x00 */ uint16_t fields_end; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct info_file_struct @@ -875,7 +875,7 @@ typedef struct _scsi_inquiry_data uint8_t product_revision[4]; uint8_t vendor_specific[20]; uint8_t _reserved3[40]; -} __attribute__((packed)) scsi_inquiry_data_t; +} __attribute__((gcc_struct,__packed__)) scsi_inquiry_data_t; #define INQ_CMD_LEN 6 #define INQ_REPLY_LEN sizeof(scsi_inquiry_data_t) @@ -31,7 +31,7 @@ extern "C" { struct hfs_extent { uint16_t block; uint16_t count; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); typedef struct hfs_extent hfs_extent_rec[3]; typedef struct hfs_mdb hfs_mdb_t; @@ -74,7 +74,7 @@ struct hfs_mdb { hfs_extent_rec drXTExtRec; /* 0x86 extents B-tree's first 3 extents */ uint32_t drCTFlSize; /* 0x92 bytes in the catalog B-tree */ hfs_extent_rec drCTExtRec; /* 0x96 catalog B-tree's first 3 extents */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); int check_HFS(disk_t *disk_car,partition_t *partition,const int verbose); int test_HFS(disk_t *disk_car, const hfs_mdb_t *hfs_mdb,partition_t *partition,const int verbose, const int dump_ind); int recover_HFS(disk_t *disk_car, const hfs_mdb_t *hfs_mdb,partition_t *partition,const int verbose, const int dump_ind, const int backup); diff --git a/src/iso9660.h b/src/iso9660.h index ba1d6490..5a4f5864 100644 --- a/src/iso9660.h +++ b/src/iso9660.h @@ -59,7 +59,7 @@ struct iso_primary_descriptor char unused4; char application_data[512]; char unused5[653]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); #define ISO_PD_SIZE (sizeof(struct iso_primary_descriptor)) #ifdef __cplusplus @@ -54,7 +54,7 @@ struct ntfs_boot_sector { uint32_t checksum; /* 0x50 Boot sector checksum. */ uint8_t bootstrap[426]; /* 0x54 Irrelevant (boot up code). */ uint16_t marker; /* 0x1FE */ - } __attribute__ ((__packed__)); + } __attribute__ ((gcc_struct, __packed__)); #define NTFS_Magic 0x454c4946 /* FILE */ @@ -73,7 +73,7 @@ struct ntfs_mft_record { uint16_t next_attr_instance; uint16_t reserved; /* NTFS 3.1+ */ uint32_t mft_record_number; /* NTFS 3.1+ */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); typedef struct ntfs_mft_record ntfs_recordheader; @@ -144,7 +144,7 @@ typedef struct { /* 12*/ uint8_t ih_flags; /* Bit field of INDEX_HEADER_FLAGS. */ /* 13*/ uint8_t reserved[3]; /* Reserved/align to 8-byte boundary.*/ /* sizeof() == 16 */ -} __attribute__((__packed__)) TD_INDEX_HEADER; +} __attribute__((gcc_struct, __packed__)) TD_INDEX_HEADER; /** * struct FILE_NAME_ATTR - Attribute: Filename (0x30). @@ -188,17 +188,17 @@ typedef struct { pack the extended attributes (EAs), if such are present.*/ /* 3e*/ uint16_t reserved; /* Reserved for alignment. */ - } __attribute__((__packed__)); + } __attribute__((gcc_struct, __packed__)); /* 3c*/ uint32_t reparse_point_tag; /* Type of reparse point, present only in reparse points and only if there are no EAs. */ - } __attribute__((__packed__)); + } __attribute__((gcc_struct, __packed__)); /* 40*/ uint8_t file_name_length; /* Length of file name in (Unicode) characters. */ /* 41*/ uint8_t file_name_type; /* Namespace of the file name.*/ /* 42*/ char *file_name[0]; /* File name in Unicode. */ -} __attribute__((__packed__)) TD_FILE_NAME_ATTR; +} __attribute__((gcc_struct, __packed__)) TD_FILE_NAME_ATTR; /** @@ -238,7 +238,7 @@ typedef struct { /* 16*/ TD_INDEX_HEADER index; /* Index header describing the following index entries. */ /* sizeof()= 32 bytes */ -} __attribute__((__packed__)) TD_INDEX_ROOT; +} __attribute__((gcc_struct, __packed__)) TD_INDEX_ROOT; int check_NTFS(disk_t *disk_car,partition_t *partition,const int verbose,const int dump_ind); @@ -54,7 +54,7 @@ struct OLE_HDR uint32_t FAT_next_block; /*68*/ uint32_t num_extra_FAT_blocks; /*72*/ /* FAT block list starts here !! first 109 entries */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct OLE_DIR { @@ -75,7 +75,7 @@ struct OLE_DIR uint32_t size; // 120 int16_t reserved; // 124 must be 0 int16_t padding; // 126 must be 0 -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct DIRECTORY { diff --git a/src/partgpt.h b/src/partgpt.h index f3fe8ade..7bbcc614 100644 --- a/src/partgpt.h +++ b/src/partgpt.h @@ -44,7 +44,7 @@ struct gpt_hdr uint32_t hdr_entsz; /* 0x54 */ uint32_t hdr_crc_table; /* 0x58 */ uint8_t padding[420]; /* 0x5c */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct gpt_ent { diff --git a/src/parthumax.c b/src/parthumax.c index 58ea5149..63625ecc 100644 --- a/src/parthumax.c +++ b/src/parthumax.c @@ -64,13 +64,13 @@ struct partition_humax { uint32_t num_sectors; uint32_t unk2; uint32_t start_sector; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct humaxlabel { char unk1[0x1be]; struct partition_humax partitions[4]; uint16_t magic; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); arch_fnct_t arch_humax= { diff --git a/src/partxbox.h b/src/partxbox.h index 59dcde10..0ae65706 100644 --- a/src/partxbox.h +++ b/src/partxbox.h @@ -29,7 +29,7 @@ struct xbox_partition char unk1[0x600]; char magic[4]; uint32_t bootnbr; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); list_part_t *add_partition_xbox_cli(disk_t *disk_car,list_part_t *list_part, char **current_cmd); @@ -47,12 +47,12 @@ struct dos_image_file_hdr uint16_t e_oeminfo; // OEM information; e_oemid specific uint16_t e_res2[10]; // Reserved words uint32_t e_lfanew; // File address of new exe header -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct exe_reloc{ uint16_t offset; uint16_t segment; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct pe_image_file_hdr { uint32_t Magic; @@ -63,12 +63,12 @@ struct pe_image_file_hdr { uint32_t NumberOfSymbols; /* debug */ uint16_t SizeOfOptionalHeader; /* == 224 */ uint16_t Characteristics; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct pe_image_data_dir { uint32_t VirtualAddress; uint32_t Size; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct pe_image_optional_hdr32 { uint16_t Magic; @@ -102,7 +102,7 @@ struct pe_image_optional_hdr32 { uint32_t LoaderFlags; /* ? */ uint32_t NumberOfRvaAndSizes; /* unreliable */ struct pe_image_data_dir DataDirectory[16]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct pe_image_optional_hdr64 { uint16_t Magic; @@ -135,7 +135,7 @@ struct pe_image_optional_hdr64 { uint32_t LoaderFlags; /* ? */ uint32_t NumberOfRvaAndSizes; /* unreliable */ struct pe_image_data_dir DataDirectory[16]; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct pe_image_section_hdr { uint8_t Name[8]; /* may not end with NULL */ @@ -154,7 +154,7 @@ struct pe_image_section_hdr { uint16_t NumberOfRelocations; /* object files only */ uint16_t NumberOfLinenumbers; /* object files only */ uint32_t Characteristics; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); #define IMAGE_SIZEOF_SYMBOL 18 @@ -180,7 +180,7 @@ struct pe_image_symbol_hdr { WORD Type; uin8_t StorageClass; uin8_t NumberOfAuxSymbols; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); #endif #endif @@ -71,6 +71,12 @@ #include "phbf.h" #include "phnc.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + //#define DEBUG_BF //#define DEBUG_BF2 #define READ_SIZE 1024*512 @@ -328,11 +334,7 @@ static bf_status_t photorec_bf_pad(struct ph_param *params, file_recovery_t *fil uint64_t file_size_backup; nbr=0; offset_error_tmp=file_recovery->offset_error; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, file_recovery->file_size, SEEK_SET) < 0) -#else - if(fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET) < 0) -#endif + if(my_fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET) < 0) return BF_ENOENT; #if 1 if(file_recovery->data_check!=NULL) diff --git a/src/photorec.c b/src/photorec.c index 895a2ce3..7d6bc3f1 100644 --- a/src/photorec.c +++ b/src/photorec.c @@ -55,6 +55,12 @@ #include "setdate.h" #include "dfxml.h" +#if defined(HAVE_FSEEKO) && !defined(__MINGW32__) +#define my_fseek fseeko +#else +#define my_fseek fseek +#endif + /* #define DEBUG_FILE_FINISH */ /* #define DEBUG_UPDATE_SEARCH_SPACE */ /* #define DEBUG_FREE */ @@ -1137,11 +1143,7 @@ void file_block_truncate_and_move(file_recovery_t *file_recovery, alloc_data_t * uint64_t i; unsigned char *block_buffer; block_buffer=&buffer[blocksize]; -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, 0, SEEK_SET) < 0) -#else - if(fseek(file_recovery->handle, 0, SEEK_SET) < 0) -#endif + if(my_fseek(file_recovery->handle, 0, SEEK_SET) < 0) return ; for(i=0; i< file_recovery->file_size; i+= blocksize) { @@ -1153,12 +1155,7 @@ void file_block_truncate_and_move(file_recovery_t *file_recovery, alloc_data_t * } else { -#ifdef HAVE_FSEEKO - if(fseeko(file_recovery->handle, file_recovery->file_size, SEEK_SET) < 0) - return ; -#else - if(fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET) < 0) + if(my_fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET) < 0) return ; -#endif } } @@ -70,7 +70,7 @@ struct reiserfs_super_block /*116 */ char s_unused[88] ; /* zero filled by mkreiserfs and reiserfs_convert_objectid_map_v1() * so any additions must be updated there as well. */ /*204*/ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); #define SB_SIZE (sizeof(struct reiserfs_super_block)) @@ -83,7 +83,7 @@ struct reiser4_master_sb { char uuid[16]; /* unique id */ char label[16]; /* filesystem label */ uint64_t diskmap; /* location of the diskmap. 0 if not present */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct format40_super { uint64_t sb_block_count; @@ -72,7 +72,7 @@ struct struct_sun_partition_i386 { unsigned char info[52]; /* Informative text string */ uint16_t magic; /* Magic number */ uint16_t csum; /* Label xor'd checksum */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); typedef struct struct_sun_partition_i386 sun_partition_i386; #define SUN_LABEL_MAGIC 0xDABE #define SUN_LABEL_MAGIC_START 0x600DDEEE @@ -116,7 +116,7 @@ struct sysv4_super_block { int32_t s_magic; /* 0x1f8 version of file system */ int32_t s_type; /* 0x1fc type of file system: 1 for 512 byte blocks 2 for 1024 byte blocks */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); /* SystemV2 super-block data on disk */ struct sysv2_super_block { @@ -283,17 +283,19 @@ extern "C" { #define UFS_DIR_ROUND (UFS_DIR_PAD - 1) #define UFS_DIR_REC_LEN(name_len) (((name_len) + 1 + 8 + UFS_DIR_ROUND) & ~UFS_DIR_ROUND) + struct ufs_timeval { uint32_t tv_sec; uint32_t tv_usec; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct ufs_csum { uint32_t cs_ndir; /* number of directories */ uint32_t cs_nbfree; /* number of free blocks */ uint32_t cs_nifree; /* number of free inodes */ uint32_t cs_nffree; /* number of free frags */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); + struct ufs2_csum_total { uint64_t cs_ndir; /* number of directories */ uint64_t cs_nbfree; /* number of free blocks */ @@ -301,7 +303,7 @@ struct ufs2_csum_total { uint64_t cs_nffree; /* number of free frags */ uint64_t cs_numclusters; /* number of free clusters */ uint64_t cs_spare[3]; /* future expansion */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct fs_u11_u1_st { int8_t fs_fsmnt[UFS_MAXMNTLEN];/* name mounted on */ @@ -310,7 +312,7 @@ struct fs_u11_u1_st { uint32_t fs_maxcluster; uint32_t fs_cpc; /* cyl per cycle in postbl */ uint16_t fs_opostbl[16][8]; /* old rotation block list head */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct fs_u11_u2_st { int8_t fs_fsmnt[UFS2_MAXMNTLEN]; /* name mounted on */ @@ -334,7 +336,7 @@ struct fs_u11_u2_st { uint64_t fs_csaddr; /* blk addr of cyl grp summary area */ uint64_t fs_pendingblocks;/* blocks in process of being freed */ uint32_t fs_pendinginodes;/*inodes in process of being freed */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); /* * This is the actual superblock, as it is laid out on the disk. @@ -453,7 +455,7 @@ struct ufs_super_block { uint32_t fs_rotbloff; /* (uint8_t) blocks for each rotation */ uint32_t fs_magic; /* magic number */ uint8_t fs_space[1]; /* list of blocks for each rotation */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); /* * Preference for optimization. @@ -34,12 +34,12 @@ struct vmfs_volume { uint32_t magic; uint32_t version; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); struct vmfs_lvm { uint64_t size; uint64_t blocks; -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); int check_VMFS(disk_t *disk,partition_t *partition); int recover_VMFS(disk_t *disk, const struct vmfs_volume *sb, partition_t *partition, const int verbose, const int dump_ind); @@ -36,7 +36,7 @@ struct wbfs_head uint8_t wbfs_sec_sz_s; // size of a wbfs sec uint8_t padding3[2]; uint8_t disc_table[0]; // size depends on hd sector size -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); int check_WBFS(disk_t *disk,partition_t *partition); int recover_WBFS(disk_t *disk, const struct wbfs_head *sb, partition_t *partition, const int verbose, const int dump_ind); @@ -104,7 +104,7 @@ struct xfs_sb uint16_t sb_logsectsize; /* sector size for the log, bytes */ uint32_t sb_logsunit; /* stripe unit size for the log */ uint32_t sb_features2; /* additonal feature bits */ -} __attribute__ ((__packed__)); +} __attribute__ ((gcc_struct, __packed__)); int check_xfs(disk_t *disk_car,partition_t *partition,const int verbose); int recover_xfs(disk_t *disk_car, const struct xfs_sb *sb,partition_t *partition,const int verbose, const int dump_ind); |