diff options
author | Stef Walter <stef@thewalter.net> | 2010-11-12 03:15:45 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2010-11-12 03:15:45 +0000 |
commit | 0cfb5be72f4d74539d7b7e8c4ea0d0b5fcc03a38 (patch) | |
tree | 6e0127c1bededb5c46b7c1543bcfc0956953c302 | |
parent | 28173f3e2037a37cdd6d6afe7f1b084e216df1ca (diff) |
Fix problems with sector command line arguments being too small.
-rw-r--r-- | src/drive.h | 18 | ||||
-rw-r--r-- | 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; @@ -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); |