Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv6768
Modified Files:
mkntfs.c
Log Message:
Bugfixing of mkntfs.c. Loads of it. (-8
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -U2 -r1.23 -r1.24
--- mkntfs.c 2001/06/11 04:02:09 1.23
+++ mkntfs.c 2001/06/11 20:31:29 1.24
@@ -1779,20 +1779,26 @@
{
uchar_t *uname;
- int i;
+ int i, len;
if (vol_name_len) {
- if (vol_name_len > 0xff)
- return -ENAMETOOLONG;
- i = (vol_name_len + 1) * sizeof(uchar_t);
- uname = calloc(1, i);
+ len = (vol_name_len + 1) * sizeof(uchar_t);
+ uname = calloc(1, len);
if (!uname)
return -errno;
- i = (stoucs(uname, vol_name, i) + 1) * sizeof(uchar_t);
+ i = (stoucs(uname, vol_name, len) + 1) * sizeof(uchar_t);
+ if (!i) {
+ free(uname);
+ return -EINVAL;
+ }
+ if (i > 0xff) {
+ free(uname);
+ return -ENAMETOOLONG;
+ }
} else {
uname = NULL;
- i = 0;
+ len = 0;
}
i = insert_resident_attr_in_mft_record(m, $VOLUME_NAME, NULL, 0, 0,
- NULL, 0, 0, 0, (char*)uname, i);
+ NULL, 0, 0, 0, (char*)uname, len);
if (uname)
free(uname);
@@ -2467,5 +2473,5 @@
EXEC_NAME = *argv;
fprintf(stderr, "%s v%s\n", EXEC_NAME, EXEC_VERSION);
- while ((c = getopt(argc, argv, "c:nqs:vz:L:V")) != EOF)
+ while ((c = getopt(argc, argv, "c:fnqs:vz:FL:QV")) != EOF)
switch (c) {
case 'n':
@@ -2564,6 +2570,4 @@
if (opt.upcase)
free(opt.upcase);
- if (opt.volume_label)
- free(opt.volume_label);
free(EXEC_REVISION);
flk.l_type = F_UNLCK;
@@ -2636,5 +2640,5 @@
/* Open the device for reading or reading and writing. */
if (opt.no_action) {
- Qprintf("Running in READ-ONLY mode!");
+ Qprintf("Running in READ-ONLY mode!\n");
i = O_RDONLY;
} else
@@ -2646,11 +2650,15 @@
/* Acquire exlusive (mandatory) write lock on the whole device. */
memset(&flk, 0, sizeof(flk));
- flk.l_type = F_WRLCK;
+ if (opt.no_action)
+ flk.l_type = F_RDLCK;
+ else
+ flk.l_type = F_WRLCK;
flk.l_whence = SEEK_SET;
flk.l_start = flk.l_len = 0LL;
err = fcntl(f, F_SETLK, &flk);
if (err == -1) {
- Eprintf("Could not lock %s for writing: %s\n", opt.dev_name,
- strerror(errno));
+ Eprintf("Could not lock %s for %s: %s\n", opt.dev_name,
+ opt.no_action ? "reading" : "writing",
+ strerror(errno));
err = close(f);
if (err == -1)
@@ -2706,15 +2714,7 @@
"sector_size.\n");
/* Validate volume size. */
- if (opt.volume_size < 4LL << 20 /* 4MB */) {
- opt.volume_size >>= 10;
- if (opt.volume_size >>= 10) {
- opt.volume_size >>= 10;
- i = 1;
- } else
- i = 0;
- err_exit("Error: device is too small (%Li%s). Minimum NTFS "
- "volume size is 4MB.\n", opt.volume_size, i ? "MB":
- "kB");
- }
+ if (opt.volume_size < (4LL << 20) /* 4MB */)
+ err_exit("Error: device is too small (%ikB). Minimum NTFS "
+ "volume size is 4MB.\n", opt.volume_size / 1024);
Dprintf("volume size = %Li bytes\n", opt.volume_size);
/* If user didn't specify the cluster size, determine it now. */
@@ -3261,8 +3261,8 @@
* last sector.
*/
- /* Seek to last cluster. */
- if (lseek(f, opt.nr_sectors * opt.sector_size, SEEK_SET) == (off_t)-1)
- err_exit("Couldn't seek to last sector: %s\n", strerror(errno));
i = max(512, opt.sector_size);
+ if (lseek(f, (opt.nr_sectors + 1) * opt.sector_size - i, SEEK_SET) ==
+ (off_t)-1)
+ err_exit("Seek failed: %s\n", strerror(errno));
bw = mkntfs_write(f, buf2, i);
free(buf2);
|