2011-12-06 02:23:28 +00:00
|
|
|
/*
|
|
|
|
* badblocks.c - Bad blocks checker
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr>
|
|
|
|
* Laboratoire MASI, Institut Blaise Pascal
|
|
|
|
* Universite Pierre et Marie Curie (Paris VI)
|
|
|
|
*
|
|
|
|
* Copyright 1995, 1996, 1997, 1998, 1999 by Theodore Ts'o
|
|
|
|
* Copyright 1999 by David Beattie
|
2018-06-28 15:25:13 +00:00
|
|
|
* Copyright 2011-2018 by Pete Batard
|
2011-12-06 02:23:28 +00:00
|
|
|
*
|
|
|
|
* This file is based on the minix file system programs fsck and mkfs
|
|
|
|
* written and copyrighted by Linus Torvalds <Linus.Torvalds@cs.helsinki.fi>
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
2012-03-03 22:59:58 +00:00
|
|
|
#include <stdint.h>
|
2011-12-06 02:23:28 +00:00
|
|
|
|
2019-04-12 20:32:40 +00:00
|
|
|
#include "ext2fs/ext2fs.h"
|
2011-12-06 02:23:28 +00:00
|
|
|
|
2012-03-03 22:59:58 +00:00
|
|
|
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;
|
2011-12-06 02:23:28 +00:00
|
|
|
|
2012-03-03 22:59:58 +00:00
|
|
|
#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)
|
2011-12-06 02:23:28 +00:00
|
|
|
|
2012-03-03 22:59:58 +00:00
|
|
|
#define BB_CHECK_MAGIC(struct, code) \
|
2011-12-06 18:08:16 +00:00
|
|
|
if ((struct)->magic != (code)) return (code)
|
2012-03-03 22:59:58 +00:00
|
|
|
#define BB_BAD_BLOCKS_THRESHOLD 256
|
|
|
|
#define BB_BLOCKS_AT_ONCE 64
|
|
|
|
#define BB_SYS_PAGE_SIZE 4096
|
2011-12-06 02:23:28 +00:00
|
|
|
|
2011-12-06 18:08:16 +00:00
|
|
|
enum error_types { READ_ERROR, WRITE_ERROR, CORRUPTION_ERROR };
|
2011-12-07 00:28:27 +00:00
|
|
|
enum op_type { OP_READ, OP_WRITE };
|
2011-12-06 18:08:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Badblocks report
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2012-03-03 22:59:58 +00:00
|
|
|
uint32_t bb_count;
|
|
|
|
uint32_t num_read_errors;
|
|
|
|
uint32_t num_write_errors;
|
|
|
|
uint32_t num_corruption_errors;
|
2011-12-06 18:08:16 +00:00
|
|
|
} badblocks_report;
|
2011-12-06 14:05:53 +00:00
|
|
|
|
2011-12-06 02:23:28 +00:00
|
|
|
/*
|
|
|
|
* Shared prototypes
|
|
|
|
*/
|
2018-06-28 15:25:13 +00:00
|
|
|
BOOL BadBlocks(HANDLE hPhysicalDrive, ULONGLONG disk_size, int nb_passes,
|
|
|
|
int flash_type, badblocks_report *report, FILE* fd);
|