From 0cfb5be72f4d74539d7b7e8c4ea0d0b5fcc03a38 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 12 Nov 2010 03:15:45 +0000 Subject: Fix problems with sector command line arguments being too small. --- src/drive.h | 18 +++++++++--------- src/main.c | 26 +++++++++++--------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/drive.h b/src/drive.h index cd8078b..e943ef1 100644 --- a/src/drive.h +++ b/src/drive.h @@ -36,15 +36,15 @@ struct _drivelocks; typedef struct _partitioninfo { - uint32 first; /* The first sector (in sectors) */ - uint32 end; /* The end sector (in sectors) */ - uint32 mft; /* Offset into the MFT (in sectors) */ - byte cluster; /* Cluster size (in sectors) */ - int device; /* A handle to an open device */ - - /* Some other context stuff about the drive */ - struct _drivelocks* locks; - struct _ntfsx_mftmap* mftmap; + uint64 first; /* The first sector (in sectors) */ + uint64 end; /* The end sector (in sectors) */ + uint64 mft; /* Offset into the MFT (in sectors) */ + byte cluster; /* Cluster size (in sectors) */ + int device; /* A handle to an open device */ + + /* Some other context stuff about the drive */ + struct _drivelocks* locks; + struct _ntfsx_mftmap* mftmap; } partitioninfo; diff --git a/src/main.c b/src/main.c index f2d5378..8f2bbd0 100644 --- a/src/main.c +++ b/src/main.c @@ -80,8 +80,10 @@ int main(int argc, char* argv[]) int temp = 0; int mode = 0; int raw = 0; + unsigned long long ull; partitioninfo pi; char driveName[MAX_PATH + 1]; + char *end; #ifdef _WIN32 int drive = 0; #endif @@ -104,8 +106,6 @@ int main(int argc, char* argv[]) case 'c': { temp = atoi(optarg); - - /* TODO: Check this range */ if(temp <= 0 || temp > 128) errx(2, "invalid cluster size (must be between 1 and 128)"); @@ -119,8 +119,6 @@ int main(int argc, char* argv[]) case 'd': { temp = atoi(optarg); - - /* TODO: Check this range */ if(temp < 0 || temp > 128) errx(2, "invalid drive number (must be between 0 and 128)"); @@ -142,13 +140,11 @@ int main(int argc, char* argv[]) /* mft offset */ case 'm': { - temp = atoi(optarg); - - /* TODO: Check this range */ - if(temp < 0) + ull = strtoull(optarg, &end, 10); + if(*end != 0) errx(2, "invalid mft offset (must be positive)"); - pi.mft = temp; + pi.mft = ull; mode = MODE_SCROUNGE; } break; @@ -217,17 +213,17 @@ int main(int argc, char* argv[]) if(argc > 2) warnx("ignoring extra arguments"); - temp = atoi(argv[0]); - if(temp < 0) + ull = strtoull(argv[0], &end, 10); + if(*end != 0) errx(2, "invalid start sector (must be positive)"); - pi.first = temp; + pi.first = ull; - temp = atoi(argv[1]); - if(temp < 0 || ((unsigned int)temp) <= pi.first) + ull = strtoull(argv[1], &end, 10); + if(*end != 0 || ull <= pi.first) errx(2, "invalid end sector (must be positive and greater than first)"); - pi.end = temp; + pi.end = ull; /* Open the device */ pi.device = open(driveName, O_BINARY | O_RDONLY | OPEN_LARGE_OPTS); -- cgit v1.2.3