[bb] fix bad blocks check for 64 bit

* 32 bit bad blocks check is too limited for large drives
  and result in erroneous computations
* 32 bit also means that 2TB would be absolute limit, which
  may be too low in case for USB HDD checks
* This fix makes bad blocks check and related calls 64 bit compliant
* also improve on bad block reports
This commit is contained in:
Pete Batard 2012-03-03 22:59:58 +00:00
parent 3721b0a570
commit a9c47a4922
6 changed files with 194 additions and 161 deletions

View file

@ -19,27 +19,25 @@
*/
#include <windows.h>
#include <stdint.h>
#ifndef __u32
#define __u32 UINT32
#endif
typedef UINT32 blk_t;
typedef DWORD errcode_t;
typedef uint64_t blk_t;
typedef DWORD errcode_t;
typedef struct ext2_struct_u32_list *ext2_badblocks_list;
typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
typedef struct ext2_struct_u32_list *ext2_u32_list;
typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
typedef struct bb_struct_u64_list *bb_badblocks_list;
typedef struct bb_struct_u64_iterate *bb_badblocks_iterate;
typedef struct bb_struct_u64_list *bb_u64_list;
typedef struct bb_struct_u64_iterate *bb_u64_iterate;
#define EXT2_ET_NO_MEMORY (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY)
#define EXT2_ET_MAGIC_BADBLOCKS_LIST (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OBJECT_IN_LIST)
#define EXT2_ET_MAGIC_BADBLOCKS_ITERATE (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INVALID_BLOCK)
#define BB_ET_NO_MEMORY (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY)
#define BB_ET_MAGIC_BADBLOCKS_LIST (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OBJECT_IN_LIST)
#define BB_ET_MAGIC_BADBLOCKS_ITERATE (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INVALID_BLOCK)
#define EXT2_CHECK_MAGIC(struct, code) \
#define BB_CHECK_MAGIC(struct, code) \
if ((struct)->magic != (code)) return (code)
#define EXT2_BAD_BLOCKS_THRESHOLD 256
#define EXT2_BLOCKS_AT_ONCE 64
#define EXT2_SYS_PAGE_SIZE 4096
#define BB_BAD_BLOCKS_THRESHOLD 256
#define BB_BLOCKS_AT_ONCE 64
#define BB_SYS_PAGE_SIZE 4096
enum error_types { READ_ERROR, WRITE_ERROR, CORRUPTION_ERROR };
enum op_type { OP_READ, OP_WRITE };
@ -48,14 +46,14 @@ enum op_type { OP_READ, OP_WRITE };
* Badblocks report
*/
typedef struct {
blk_t bb_count;
blk_t num_read_errors;
blk_t num_write_errors;
blk_t num_corruption_errors;
uint32_t bb_count;
uint32_t num_read_errors;
uint32_t num_write_errors;
uint32_t num_corruption_errors;
} badblocks_report;
/*
* Shared prototypes
*/
BOOL BadBlocks(HANDLE hPhysicalDrive, ULONGLONG disk_size, int block_size,
BOOL BadBlocks(HANDLE hPhysicalDrive, ULONGLONG disk_size, size_t block_size,
int test_type, badblocks_report *report, FILE* fd);