Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv15593/ntfstools
Modified Files:
mkntfs.c
Log Message:
Attribute list support (merging done, part 2, some stuff still incomplete). mkntfs ntfs volume creation. See the changelog...
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -U2 -r1.70 -r1.71
--- mkntfs.c 21 Apr 2002 01:26:39 -0000 1.70
+++ mkntfs.c 22 Apr 2002 10:34:32 -0000 1.71
@@ -136,14 +136,10 @@
INDEX_ALLOCATION *index_block = NULL;
uchar_t *ustr = NULL;
+ntfs_volume *vol;
struct {
- char *dev_name;
int sector_size; /* -s, in bytes, power of 2, default is
512 bytes. */
long long nr_sectors; /* size of device in sectors */
- int cluster_size; /* -c, in bytes, 512*1024 max,
- power of 2, if not specified
- determined by volume size. Minimum
- is 512bytes, maximum is 64kB. */
long long nr_clusters; /* Note: Win2k treats clusters as
32-bit entities! */
@@ -151,5 +147,4 @@
with k for kB, m or M for MB, or
g or G for GB, or t or T for TB */
- int mft_record_size; /* in bytes. */
int index_block_size; /* in bytes. */
int mft_size; /* The smaller of 16kB & one cluster. */
@@ -180,12 +175,4 @@
* mode). */
char force; /* -F, force fs creation. */
- char *volume_label; /* -L, set the volume label. */
- union { /* revision of ntfs, 1.2 or 3.0 */
- unsigned short ntfs_version;
- struct {
- unsigned char ntfs_major_ver;
- unsigned char ntfs_minor_ver;
- };
- };
char quick_format; /* -f or -Q, fast format, don't zero
the volume first. */
@@ -290,5 +277,5 @@
if (bytes_written == -1LL) {
retry = errno;
- Eprintf("Error writing to %s: %s\n", opt.dev_name,
+ Eprintf("Error writing to %s: %s\n", vol->dev_name,
strerror(errno));
errno = retry;
@@ -303,5 +290,5 @@
if (count)
Eprintf("Failed to complete writing to %s after three retries."
- "\n", opt.dev_name);
+ "\n", vol->dev_name);
return total;
}
@@ -332,5 +319,5 @@
total = delta = 0LL;
for (i = 0; rl[i].length; i++) {
- length = rl[i].length * opt.cluster_size;
+ length = rl[i].length * vol->cluster_size;
/* Don't write sparse runs. */
if (rl[i].lcn == -1) {
@@ -341,5 +328,5 @@
continue;
}
- if (lseek(fd, rl[i].lcn * opt.cluster_size, SEEK_SET) ==
+ if (lseek(fd, rl[i].lcn * vol->cluster_size, SEEK_SET) ==
(off_t)-1)
return -1LL;
@@ -355,5 +342,5 @@
retry = errno;
Eprintf("Error writing to %s: %s\n",
- opt.dev_name, strerror(errno));
+ vol->dev_name, strerror(errno));
errno = retry;
return bytes_written;
@@ -369,5 +356,5 @@
if (length) {
Eprintf("Failed to complete writing to %s after three "
- "retries.\n", opt.dev_name);
+ "retries.\n", vol->dev_name);
return total;
}
@@ -804,10 +791,10 @@
ATTR_RECORD *a;
- memset(m, 0, opt.mft_record_size);
+ memset(m, 0, vol->mft_record_size);
m->magic = magic_FILE;
/* Aligned to 2-byte boundary. */
m->usa_ofs = cpu_to_le16((sizeof(MFT_RECORD) + 1) & ~1);
- if (opt.mft_record_size >= NTFS_SECTOR_SIZE)
- m->usa_count = cpu_to_le16(opt.mft_record_size /
+ if (vol->mft_record_size >= NTFS_SECTOR_SIZE)
+ m->usa_count = cpu_to_le16(vol->mft_record_size /
NTFS_SECTOR_SIZE + 1);
else {
@@ -834,5 +821,5 @@
m->bytes_in_use = cpu_to_le32((le16_to_cpu(m->attrs_offset) + 8 + 7) &
~7);
- m->bytes_allocated = cpu_to_le32(opt.mft_record_size);
+ m->bytes_allocated = cpu_to_le32(vol->mft_record_size);
m->base_mft_record = cpu_to_le64((MFT_REF)0);
m->next_attr_instance = cpu_to_le16(0);
@@ -891,5 +878,5 @@
* If on NTFS 1.2-, OTOH, store it as usual.
*/
- if (rl[i].lcn == -1LL && opt.ntfs_major_ver >= 3)
+ if (rl[i].lcn == -1LL && vol->major_ver >= 3)
continue;
rls += get_min_bytes_width(rl[i].lcn - prev_lcn);
@@ -969,5 +956,5 @@
* If on NTFS 1.2-, OTOH, store it as usual.
*/
- if (rl[i].lcn == -1LL && opt.ntfs_major_ver >= 3)
+ if (rl[i].lcn == -1LL && vol->major_ver >= 3)
lcn_len = 0;
else
@@ -1263,5 +1250,5 @@
highest_vcn += rl[i].length;
/* Does the value fit inside the allocated size? */
- if (highest_vcn * opt.cluster_size < val_len) {
+ if (highest_vcn * vol->cluster_size < val_len) {
Eprintf("BUG: Allocated size is smaller than data size!\n");
err = -EINVAL;
@@ -1309,5 +1296,5 @@
memset(a->reserved1, 0, sizeof(a->reserved1));
// FIXME: Allocated size depends on compression.
- a->allocated_size = cpu_to_le64(highest_vcn * opt.cluster_size);
+ a->allocated_size = cpu_to_le64(highest_vcn * vol->cluster_size);
a->data_size = cpu_to_le64(val_len);
if (name_len)
@@ -1419,5 +1406,5 @@
if (val_len) {
rl = allocate_scattered_clusters((val_len +
- opt.cluster_size - 1) / opt.cluster_size);
+ vol->cluster_size - 1) / vol->cluster_size);
if (!rl) {
err = -errno;
@@ -1488,6 +1475,6 @@
memset(a->reserved1, 0, sizeof(a->reserved1));
// FIXME: Allocated size depends on compression.
- a->allocated_size = cpu_to_le64((val_len + (opt.cluster_size - 1)) &
- ~(opt.cluster_size - 1));
+ a->allocated_size = cpu_to_le64((val_len + (vol->cluster_size - 1)) &
+ ~(vol->cluster_size - 1));
a->data_size = cpu_to_le64(val_len);
a->initialized_size = cpu_to_le64(val_len);
@@ -1652,5 +1639,5 @@
si.last_access_time = si.creation_time;
si.file_attributes = flags; /* already LE */
- if (opt.ntfs_major_ver < 3)
+ if (vol->major_ver < 3)
memset(&si.reserved12, 0, sizeof(si.reserved12));
else {
@@ -1669,5 +1656,5 @@
err = insert_resident_attr_in_mft_record(m, AT_STANDARD_INFORMATION,
NULL, 0, 0, 0, 0, (char*)&si,
- opt.ntfs_major_ver < 3 ? 48 : 72);
+ vol->major_ver < 3 ? 48 : 72);
if (err < 0)
Eprintf("add_attr_std_info failed: %s\n", strerror(-err));
@@ -1915,6 +1902,6 @@
r->collation_rule = collation_rule;
r->index_block_size = cpu_to_le32(index_block_size);
- if (index_block_size >= opt.cluster_size) {
- if (index_block_size % opt.cluster_size) {
+ if (index_block_size >= vol->cluster_size) {
+ if (index_block_size % vol->cluster_size) {
Eprintf("add_attr_index_root: index block size is not "
"a multiple of the cluster size.\n");
@@ -1923,6 +1910,6 @@
}
r->clusters_per_index_block = index_block_size /
- opt.cluster_size;
- } else /* if (opt.cluster_size > index_block_size) */ {
+ vol->cluster_size;
+ } else /* if (vol->cluster_size > index_block_size) */ {
if (index_block_size & (index_block_size - 1)) {
Eprintf("add_attr_index_root: index block size is not "
@@ -2303,5 +2290,5 @@
i = ntfs_file_compare_values(file_name,
(FILE_NAME_ATTR*)&ie->key.file_name, 1,
- IGNORE_CASE, opt.upcase, opt.upcase_len);
+ IGNORE_CASE, vol->upcase, vol->upcase_len);
/*
* If @file_name collates before ie->key.file_name, there is no
@@ -2327,5 +2314,5 @@
i = ntfs_file_compare_values(file_name,
(FILE_NAME_ATTR*)&ie->key.file_name, 1,
- CASE_SENSITIVE, opt.upcase, opt.upcase_len);
+ CASE_SENSITIVE, vol->upcase, vol->upcase_len);
if (i == -1)
break;
@@ -2507,13 +2494,13 @@
int r, mnt_flags;
- r = ntfs_check_if_mounted(opt.dev_name, &mnt_flags);
+ r = ntfs_check_if_mounted(vol->dev_name, &mnt_flags);
if (r) {
Eprintf("Failed to determine whether %s is mounted: %s\n",
- opt.dev_name, strerror(-r));
+ vol->dev_name, strerror(-r));
return;
}
if (!(mnt_flags & NTFS_MF_MOUNTED))
return;
- Eprintf("%s is mounted.\n", opt.dev_name);
+ Eprintf("%s is mounted.\n", vol->dev_name);
if (!opt.force)
err_exit("Refusing to make a filesystem here!\n");
@@ -2524,17 +2511,8 @@
{
memset(&opt, 0, sizeof(opt));
- opt.ntfs_major_ver = 1;
- opt.ntfs_minor_ver = 2;
- opt.mft_record_size = 1024;
opt.index_block_size = 4096;
opt.attr_defs = (ATTR_DEF*)&attrdef_ntfs12_array;
opt.attr_defs_len = sizeof(attrdef_ntfs12_array);
//Dprintf("Attr_defs table length = %u\n", opt.attr_defs_len);
- /* Length is in unicode characters. */
- opt.upcase_len = 65536;
- opt.upcase = (uchar_t*)malloc(opt.upcase_len * sizeof(uchar_t));
- if (!opt.upcase)
- err_exit("Could not allocate memory for internal buffer.\n");
- init_upcase_table(opt.upcase, opt.upcase_len * sizeof(uchar_t));
}
@@ -2578,5 +2556,5 @@
if (!l || l > INT_MAX || *s)
err_exit("Invalid cluster size.\n");
- opt.cluster_size = l;
+ vol->cluster_size = l;
break;
case 'f':
@@ -2612,5 +2590,5 @@
break;
case 'L':
- opt.volume_label = optarg;
+ vol->vol_name = optarg;
break;
case 'V':
@@ -2622,5 +2600,5 @@
if (optind == argc)
usage();
- opt.dev_name = argv[optind++];
+ vol->dev_name = argv[optind++];
if (optind < argc) {
u = strtoul(argv[optind++], &s, 0);
@@ -2670,14 +2648,16 @@
if (opt.attr_defs != (ATTR_DEF*)attrdef_ntfs12_array)
free(opt.attr_defs);
- if (opt.upcase)
- free(opt.upcase);
+ if (vol->upcase)
+ free(vol->upcase);
+ if (vol)
+ free(vol);
flk.l_type = F_UNLCK;
err = fcntl(f, F_SETLK, &flk);
if (err == -1)
- Eprintf("Warning: Could not unlock %s: %s\n", opt.dev_name,
+ Eprintf("Warning: Could not unlock %s: %s\n", vol->dev_name,
strerror(errno));
err = close(f);
if (err == -1)
- Eprintf("Warning: Could not close %s: %s\n", opt.dev_name,
+ Eprintf("Warning: Could not close %s: %s\n", vol->dev_name,
strerror(errno));
}
@@ -2755,4 +2735,18 @@
/* Initialize the random number generator with the current time. */
srandom(time(NULL));
+ /* Initialize ntfs_volume structure vol. */
+ vol = (ntfs_volume*)calloc(1, sizeof(*vol));
+ if (!vol)
+ err_exit("Could not allocate memory for internal buffer.\n");
+ vol->major_ver = 1;
+ vol->minor_ver = 2;
+ vol->mft_record_size = 1024;
+ vol->mft_record_size_bits = 10;
+ /* Length is in unicode characters. */
+ vol->upcase_len = 65536;
+ vol->upcase = (uchar_t*)malloc(vol->upcase_len * sizeof(uchar_t));
+ if (!vol->upcase)
+ err_exit("Could not allocate memory for internal buffer.\n");
+ init_upcase_table(vol->upcase, vol->upcase_len * sizeof(uchar_t));
/* Initialize opt to zero / required values. */
init_options();
@@ -2760,13 +2754,13 @@
parse_options(argc, argv);
/* Verify we are dealing with a block device. */
- if (stat(opt.dev_name, &sbuf) == -1) {
+ if (stat(vol->dev_name, &sbuf) == -1) {
if (errno == ENOENT)
err_exit("The device doesn't exist; did you specify "
"it correctly?\n");
err_exit("Error getting information about %s: %s\n",
- opt.dev_name, strerror(errno));
+ vol->dev_name, strerror(errno));
}
if (!S_ISBLK(sbuf.st_mode)) {
- Eprintf("%s is not a block device.\n", opt.dev_name);
+ Eprintf("%s is not a block device.\n", vol->dev_name);
if (!opt.force)
err_exit("Refusing to make a filesystem here!\n");
@@ -2791,5 +2785,5 @@
MINOR(sbuf.st_rdev) % 16 == 0)) {
err_exit("%s is entire device, not just one partition!\n",
- opt.dev_name);
+ vol->dev_name);
}
#endif
@@ -2802,7 +2796,7 @@
} else
i = O_RDWR;
- f = open(opt.dev_name, i);
+ f = open(vol->dev_name, i);
if (f == -1)
- err_exit("Could not open %s: %s\n", opt.dev_name,
+ err_exit("Could not open %s: %s\n", vol->dev_name,
strerror(errno));
/* Acquire exlusive (mandatory) write lock on the whole device. */
@@ -2816,5 +2810,5 @@
err = fcntl(f, F_SETLK, &flk);
if (err == -1) {
- Eprintf("Could not lock %s for %s: %s\n", opt.dev_name,
+ Eprintf("Could not lock %s for %s: %s\n", vol->dev_name,
opt.no_action ? "reading" : "writing",
strerror(errno));
@@ -2822,5 +2816,5 @@
if (err == -1)
Eprintf("Warning: Could not close %s: %s\n",
- opt.dev_name, strerror(errno));
+ vol->dev_name, strerror(errno));
exit(1);
}
@@ -2846,5 +2840,5 @@
"not be obtained automatically.\n"
"Assuming sector size is 512 bytes.\n",
- opt.dev_name);
+ vol->dev_name);
opt.sector_size = 512;
}
@@ -2862,5 +2856,5 @@
if (opt.nr_sectors <= 0)
err_exit("get_device_size(%s) failed. Please specify "
- "it manually.\n", opt.dev_name);
+ "it manually.\n", vol->dev_name);
}
Dprintf("number of sectors = %Ld (0x%Lx)\n", opt.nr_sectors,
@@ -2880,22 +2874,22 @@
Dprintf("volume size = %LikiB\n", opt.volume_size / 1024);
/* If user didn't specify the cluster size, determine it now. */
- if (!opt.cluster_size) {
+ if (!vol->cluster_size) {
if (opt.volume_size <= 512LL << 20) /* <= 512MB */
- opt.cluster_size = 512;
+ vol->cluster_size = 512;
else if (opt.volume_size <= 1LL << 30) /* ]512MB-1GB] */
- opt.cluster_size = 1024;
+ vol->cluster_size = 1024;
else if (opt.volume_size <= 2LL << 30) /* ]1GB-2GB] */
- opt.cluster_size = 2048;
+ vol->cluster_size = 2048;
else
- opt.cluster_size = 4096;
+ vol->cluster_size = 4096;
/* For small volumes on devices with large sector sizes. */
- if (opt.cluster_size < opt.sector_size)
- opt.cluster_size = opt.sector_size;
+ if (vol->cluster_size < opt.sector_size)
+ vol->cluster_size = opt.sector_size;
}
/* Validate cluster size. */
- if (opt.cluster_size & (opt.cluster_size - 1) ||
- opt.cluster_size < opt.sector_size ||
- opt.cluster_size > 128 * opt.sector_size ||
- opt.cluster_size > 65536)
+ if (vol->cluster_size & (vol->cluster_size - 1) ||
+ vol->cluster_size < opt.sector_size ||
+ vol->cluster_size > 128 * opt.sector_size ||
+ vol->cluster_size > 65536)
err_exit("Error: cluster_size is invalid. It must be a power "
"of two, be at least\nthe same as sector_size, be "
@@ -2903,6 +2897,7 @@
"has\nto fit inside eight bits. (We do not support "
"larger cluster sizes yet.)\n");
- Dprintf("cluster size = %i bytes\n", opt.cluster_size);
- if (opt.cluster_size > 4096) {
+ vol->cluster_size_bits = ffs(vol->cluster_size) - 1;
+ Dprintf("cluster size = %i bytes\n", vol->cluster_size);
+ if (vol->cluster_size > 4096) {
if (opt.enable_compression) {
if (!opt.force)
@@ -2923,5 +2918,5 @@
/* If user didn't specify the number of clusters, determine it now. */
if (!opt.nr_clusters)
- opt.nr_clusters = opt.volume_size / opt.cluster_size;
+ opt.nr_clusters = opt.volume_size / vol->cluster_size;
/*
* Check the cluster_size and nr_sectors for consistency with
@@ -2930,7 +2925,7 @@
*/
if (opt.nr_clusters != (opt.nr_sectors * opt.sector_size) /
- opt.cluster_size ||
+ vol->cluster_size ||
opt.volume_size / opt.sector_size != opt.nr_sectors ||
- opt.volume_size / opt.cluster_size != opt.nr_clusters)
+ opt.volume_size / vol->cluster_size != opt.nr_clusters)
err_exit("Illegal combination of volume/cluster/sector size "
"and/or cluster/sector number.\n");
@@ -2941,6 +2936,6 @@
/* Needs to be multiple of 8 bytes. */
lcn_bitmap_byte_size = (lcn_bitmap_byte_size + 7) & ~7;
- i = (lcn_bitmap_byte_size + opt.cluster_size - 1) &
- ~(opt.cluster_size - 1);
+ i = (lcn_bitmap_byte_size + vol->cluster_size - 1) &
+ ~(vol->cluster_size - 1);
Dprintf("lcn_bitmap_byte_size = %i, allocated = %i\n",
lcn_bitmap_byte_size, i);
@@ -2959,9 +2954,9 @@
* bigger, rounded to multiples of cluster size.
*/
- opt.mft_size = (16 * opt.mft_record_size + opt.cluster_size - 1)
- & ~(opt.cluster_size - 1);
+ opt.mft_size = (16 * vol->mft_record_size + vol->cluster_size - 1)
+ & ~(vol->cluster_size - 1);
Dprintf("MFT size = %i (0x%x) bytes\n", opt.mft_size, opt.mft_size);
/* Determine mft bitmap size and allocate it. */
- mft_bitmap_size = opt.mft_size / opt.mft_record_size;
+ mft_bitmap_size = opt.mft_size / vol->mft_record_size;
/* Convert to bytes, at least one. */
mft_bitmap_byte_size = (mft_bitmap_size + 7) >> 3;
@@ -2981,5 +2976,5 @@
rl_mft_bmp[0].vcn = 0LL;
/* Mft bitmap is right after $Boot's data. */
- j = (8192 + opt.cluster_size - 1) / opt.cluster_size;
+ j = (8192 + vol->cluster_size - 1) / vol->cluster_size;
rl_mft_bmp[0].lcn = j;
/*
@@ -2999,7 +2994,7 @@
*/
opt.mft_lcn = rl_mft_bmp[0].lcn + rl_mft_bmp[0].length;
- if (opt.mft_lcn * opt.cluster_size < 16 * 1024)
- opt.mft_lcn = (16 * 1024 + opt.cluster_size - 1) /
- opt.cluster_size;
+ if (opt.mft_lcn * vol->cluster_size < 16 * 1024)
+ opt.mft_lcn = (16 * 1024 + vol->cluster_size - 1) /
+ vol->cluster_size;
}
Dprintf("$MFT logical cluster number = 0x%x\n", opt.mft_lcn);
@@ -3035,5 +3030,5 @@
rl_mft[0].lcn = opt.mft_lcn;
/* We already rounded mft size up to a cluster. */
- j = opt.mft_size / opt.cluster_size;
+ j = opt.mft_size / vol->cluster_size;
rl_mft[1].vcn = rl_mft[0].length = j;
rl_mft[1].lcn = -1LL;
@@ -3044,5 +3039,5 @@
/* Determine mftmirr_lcn (middle of volume). */
opt.mftmirr_lcn = (opt.nr_sectors * opt.sector_size >> 1)
- / opt.cluster_size;
+ / vol->cluster_size;
Dprintf("$MFTMirr logical cluster number = 0x%x\n", opt.mftmirr_lcn);
/* Create run list for mft mirror. */
@@ -3060,5 +3055,5 @@
* whichever is bigger).
*/
- j = (4 * opt.mft_record_size + opt.cluster_size - 1) / opt.cluster_size;
+ j = (4 * vol->mft_record_size + vol->cluster_size - 1) / vol->cluster_size;
rl_mftmirr[1].vcn = rl_mftmirr[0].length = j;
rl_mftmirr[1].lcn = -1LL;
@@ -3090,6 +3085,6 @@
else
opt.logfile_size = (opt.volume_size / 100) &
- ~(opt.cluster_size - 1);
- j = opt.logfile_size / opt.cluster_size;
+ ~(vol->cluster_size - 1);
+ j = opt.logfile_size / vol->cluster_size;
while (rl_logfile[0].lcn + j >= opt.nr_clusters) {
/*
@@ -3099,8 +3094,8 @@
*/
opt.logfile_size >>= 1;
- j = opt.logfile_size / opt.cluster_size;
+ j = opt.logfile_size / vol->cluster_size;
}
- opt.logfile_size = (opt.logfile_size + opt.cluster_size - 1) &
- ~(opt.cluster_size - 1);
+ opt.logfile_size = (opt.logfile_size + vol->cluster_size - 1) &
+ ~(vol->cluster_size - 1);
Dprintf("$LogFile (journal) size = %ikiB\n", opt.logfile_size / 1024);
/*
@@ -3129,5 +3124,5 @@
* bigger.
*/
- j = (8192 + opt.cluster_size - 1) / opt.cluster_size;
+ j = (8192 + vol->cluster_size - 1) / vol->cluster_size;
rl_boot[1].vcn = rl_boot[0].length = j;
rl_boot[1].lcn = -1LL;
@@ -3169,5 +3164,5 @@
Qprintf("Initialising device with zeroes: 0%%");
fflush(stdout);
- mid_clust = (opt.volume_size >> 1) / opt.cluster_size;
+ mid_clust = (opt.volume_size >> 1) / vol->cluster_size;
for (position = 0; position < opt.nr_clusters; position++) {
if (!(position % (int)(progress_inc+1))) {
@@ -3176,6 +3171,6 @@
fflush(stdout);
}
- bw = mkntfs_write(f, buf, opt.cluster_size);
- if (bw != opt.cluster_size) {
+ bw = mkntfs_write(f, buf, vol->cluster_size);
+ if (bw != vol->cluster_size) {
if (bw != -1 || errno != EIO)
err_exit("This should not happen.\n");
@@ -3185,7 +3180,7 @@
"system.\n");
if (position == mid_clust &&
- (opt.ntfs_major_ver < 1 ||
- (opt.ntfs_major_ver == 1 &&
- opt.ntfs_minor_ver < 2)))
+ (vol->major_ver < 1 ||
+ (vol->major_ver == 1 &&
+ vol->minor_ver < 2)))
err_exit("Error: Bad cluster found in "
"location reserved for system "
@@ -3199,9 +3194,9 @@
/* Seek to next cluster. */
lseek(f, ((off_t)position + 1) *
- opt.cluster_size, SEEK_SET);
+ vol->cluster_size, SEEK_SET);
}
}
Qprintf("\b\b\b\b100%%");
- position = (opt.volume_size & (opt.cluster_size - 1)) /
+ position = (opt.volume_size & (vol->cluster_size - 1)) /
opt.sector_size;
for (i = 0; i < position; i++) {
@@ -3211,7 +3206,7 @@
err_exit("This should not happen.\n");
else if (i + 1 == position &&
- (opt.ntfs_major_ver >= 2 ||
- (opt.ntfs_major_ver == 1 &&
- opt.ntfs_minor_ver >= 2)))
+ (vol->major_ver >= 2 ||
+ (vol->major_ver == 1 &&
+ vol->minor_ver >= 2)))
err_exit("Error: Bad cluster found in "
"location reserved for system "
@@ -3232,6 +3227,6 @@
*/
for (i = 1; i < 16; i++) {
- m = (MFT_RECORD*)(buf + i * opt.mft_record_size);
- memcpy(m, buf, opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + i * vol->mft_record_size);
+ memcpy(m, buf, vol->mft_record_size);
m->sequence_number = cpu_to_le16(i);
}
@@ -3240,8 +3235,8 @@
* with empty, formatted records.
*/
- if (opt.cluster_size > 16 * opt.mft_record_size) {
- for (i = 16; i * opt.mft_record_size < opt.cluster_size; i++)
- memcpy(buf + i * opt.mft_record_size, buf,
- opt.mft_record_size);
+ if (vol->cluster_size > 16 * vol->mft_record_size) {
+ for (i = 16; i * vol->mft_record_size < vol->cluster_size; i++)
+ memcpy(buf + i * vol->mft_record_size, buf,
+ vol->mft_record_size);
}
/*
@@ -3252,5 +3247,5 @@
__u32 file_attrs;
- m = (MFT_RECORD*)(buf + i * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + i * vol->mft_record_size);
m->flags |= MFT_RECORD_IN_USE;
ntfs_set_bit(mft_bitmap, 0LL + i, 1);
@@ -3268,5 +3263,5 @@
root_ref = MAKE_MFT_REF(FILE_root, FILE_root);
Vprintf("Creating root directory (mft record 5)\n");
- m = (MFT_RECORD*)(buf + 5 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 5 * vol->mft_record_size);
m->flags |= MFT_RECORD_IS_DIRECTORY;
m->link_count = cpu_to_le16(le16_to_cpu(m->link_count) + 1);
@@ -3331,12 +3326,12 @@
//dump_mft_record(m);
Vprintf("Creating $MFTMirr (mft record 1)\n");
- m = (MFT_RECORD*)(buf + 1 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 1 * vol->mft_record_size);
err = add_attr_data_positioned(m, NULL, 0, 0, 0, rl_mftmirr, buf,
- rl_mftmirr[0].length * opt.cluster_size);
+ rl_mftmirr[0].length * vol->cluster_size);
if (!err)
err = create_hardlink(index_block, root_ref, m,
MAKE_MFT_REF(FILE_MFTMirr, FILE_MFTMirr),
- rl_mftmirr[0].length * opt.cluster_size,
- rl_mftmirr[0].length * opt.cluster_size,
+ rl_mftmirr[0].length * vol->cluster_size,
+ rl_mftmirr[0].length * vol->cluster_size,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$MFTMirr", FILE_NAME_WIN32_AND_DOS);
@@ -3349,5 +3344,5 @@
//dump_mft_record(m);
Vprintf("Creating $LogFile (mft record 2)\n");
- m = (MFT_RECORD*)(buf + 2 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 2 * vol->mft_record_size);
buf2 = malloc(opt.logfile_size);
if (!buf2)
@@ -3373,5 +3368,5 @@
//dump_mft_record(m);
Vprintf("Creating $Volume (mft record 3)\n");
- m = (MFT_RECORD*)(buf + 3 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 3 * vol->mft_record_size);
err = create_hardlink(index_block, root_ref, m,
MAKE_MFT_REF(FILE_Volume, FILE_Volume), 0LL, 0LL,
@@ -3385,11 +3380,11 @@
err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0);
if (!err)
- err = add_attr_vol_name(m, opt.volume_label, opt.volume_label ?
- strlen(opt.volume_label) : 0);
+ err = add_attr_vol_name(m, vol->vol_name, vol->vol_name ?
+ strlen(vol->vol_name) : 0);
if (!err) {
Qprintf("Setting the volume dirty so check disk runs on next "
"reboot into Windows.\n");
- err = add_attr_vol_info(m, VOLUME_IS_DIRTY, opt.ntfs_major_ver,
- opt.ntfs_minor_ver);
+ err = add_attr_vol_info(m, VOLUME_IS_DIRTY, vol->major_ver,
+ vol->minor_ver);
}
if (err < 0)
@@ -3397,6 +3392,6 @@
//dump_mft_record(m);
Vprintf("Creating $AttrDef (mft record 4)\n");
- m = (MFT_RECORD*)(buf + 4 * opt.mft_record_size);
- if (opt.ntfs_major_ver < 3)
+ m = (MFT_RECORD*)(buf + 4 * vol->mft_record_size);
+ if (vol->major_ver < 3)
buf2_size = 36000;
else
@@ -3413,6 +3408,6 @@
err = create_hardlink(index_block, root_ref, m,
MAKE_MFT_REF(FILE_AttrDef, FILE_AttrDef),
- (buf2_size + opt.cluster_size - 1) &
- ~(opt.cluster_size - 1), buf2_size,
+ (buf2_size + vol->cluster_size - 1) &
+ ~(vol->cluster_size - 1), buf2_size,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$AttrDef", FILE_NAME_WIN32_AND_DOS);
@@ -3426,11 +3421,11 @@
//dump_mft_record(m);
Vprintf("Creating $Bitmap (mft record 6)\n");
- m = (MFT_RECORD*)(buf + 6 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 6 * vol->mft_record_size);
err = add_attr_data(m, NULL, 0, 0, 0, lcn_bitmap, lcn_bitmap_byte_size);
if (!err)
err = create_hardlink(index_block, root_ref, m,
MAKE_MFT_REF(FILE_Bitmap, FILE_Bitmap),
- (lcn_bitmap_byte_size + opt.cluster_size - 1) &
- ~(opt.cluster_size - 1), lcn_bitmap_byte_size,
+ (lcn_bitmap_byte_size + vol->cluster_size - 1) &
+ ~(vol->cluster_size - 1), lcn_bitmap_byte_size,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$Bitmap", FILE_NAME_WIN32_AND_DOS);
@@ -3443,5 +3438,5 @@
//dump_mft_record(m);
Vprintf("Creating $Boot (mft record 7)\n");
- m = (MFT_RECORD*)(buf + 7 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 7 * vol->mft_record_size);
buf2 = calloc(1, 8192);
if (!buf2)
@@ -3456,5 +3451,5 @@
bs = (NTFS_BOOT_SECTOR*)buf2;
bs->bpb.bytes_per_sector = cpu_to_le16(opt.sector_size);
- bs->bpb.sectors_per_cluster = (__u8)(opt.cluster_size /
+ bs->bpb.sectors_per_cluster = (__u8)(vol->cluster_size /
opt.sector_size);
bs->bpb.media_type = 0xf8; /* hard disk */
@@ -3467,10 +3462,10 @@
bs->mft_lcn = scpu_to_le64(opt.mft_lcn);
bs->mftmirr_lcn = scpu_to_le64(opt.mftmirr_lcn);
- if (opt.mft_record_size >= opt.cluster_size)
- bs->clusters_per_mft_record = opt.mft_record_size /
- opt.cluster_size;
+ if (vol->mft_record_size >= vol->cluster_size)
+ bs->clusters_per_mft_record = vol->mft_record_size /
+ vol->cluster_size;
else {
- bs->clusters_per_mft_record = -(ffs(opt.mft_record_size) - 1);
- if ((1 << -bs->clusters_per_mft_record) != opt.mft_record_size)
+ bs->clusters_per_mft_record = -(ffs(vol->mft_record_size) - 1);
+ if ((1 << -bs->clusters_per_mft_record) != vol->mft_record_size)
err_exit("BUG: calculated clusters_per_mft_record "
"is wrong (= 0x%x)\n",
@@ -3480,7 +3475,7 @@
bs->clusters_per_mft_record,
bs->clusters_per_mft_record);
- if (opt.index_block_size >= opt.cluster_size)
+ if (opt.index_block_size >= vol->cluster_size)
bs->clusters_per_index_record = opt.index_block_size /
- opt.cluster_size;
+ vol->cluster_size;
else {
bs->clusters_per_index_record = -(ffs(opt.index_block_size) - 1);
@@ -3509,6 +3504,6 @@
err = create_hardlink(index_block, root_ref, m,
MAKE_MFT_REF(FILE_Boot, FILE_Boot),
- (8192 + opt.cluster_size - 1) &
- ~(opt.cluster_size - 1), 8192,
+ (8192 + vol->cluster_size - 1) &
+ ~(vol->cluster_size - 1), 8192,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$Boot", FILE_NAME_WIN32_AND_DOS);
@@ -3551,9 +3546,9 @@
//dump_mft_record(m);
Vprintf("Creating $BadClus (mft record 8)\n");
- m = (MFT_RECORD*)(buf + 8 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 8 * vol->mft_record_size);
// FIXME: This should be IGNORE_CASE
/* Create a sparse named stream of size equal to the volume size. */
err = add_attr_data_positioned(m, "$Bad", 4, 0, 0, rl_bad, NULL,
- opt.nr_clusters * opt.cluster_size);
+ opt.nr_clusters * vol->cluster_size);
if (!err) {
err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0);
@@ -3573,5 +3568,5 @@
//dump_mft_record(m);
Vprintf("Creating $Quota (mft record 9)\n");
- m = (MFT_RECORD*)(buf + 9 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 9 * vol->mft_record_size);
err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0);
if (!err)
@@ -3588,12 +3583,12 @@
//dump_mft_record(m);
Vprintf("Creating $UpCase (mft record 0xa)\n");
- m = (MFT_RECORD*)(buf + 0xa * opt.mft_record_size);
- err = add_attr_data(m, NULL, 0, 0, 0, (char*)opt.upcase,
- opt.upcase_len << 1);
+ m = (MFT_RECORD*)(buf + 0xa * vol->mft_record_size);
+ err = add_attr_data(m, NULL, 0, 0, 0, (char*)vol->upcase,
+ vol->upcase_len << 1);
if (!err)
err = create_hardlink(index_block, root_ref, m,
MAKE_MFT_REF(FILE_UpCase, FILE_UpCase),
- ((opt.upcase_len << 1) + opt.cluster_size - 1) &
- ~(opt.cluster_size - 1), opt.upcase_len << 1,
+ ((vol->upcase_len << 1) + vol->cluster_size - 1) &
+ ~(vol->cluster_size - 1), vol->upcase_len << 1,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$UpCase", FILE_NAME_WIN32_AND_DOS);
@@ -3608,5 +3603,5 @@
for (i = 0xb; i < 0x10; i++) {
Vprintf("Creating system file (mft record 0x%x)\n", i, i);
- m = (MFT_RECORD*)(buf + i * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + i * vol->mft_record_size);
err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0);
if (!err) {
@@ -3631,5 +3626,5 @@
// update during each subsequent c&w of each system file.
Vprintf("Syncing root directory index record.\n");
- m = (MFT_RECORD*)(buf + 5 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 5 * vol->mft_record_size);
i = 5 * sizeof(uchar_t);
ustr = (uchar_t*)calloc(1, i);
@@ -3648,5 +3643,5 @@
}
a = ctx->attr;
- rl_index = decompress_run_list(a);
+ rl_index = ntfs_decompress_mapping_pairs(vol, a, NULL);
if (!rl_index) {
ntfs_put_attr_search_ctx(ctx);
@@ -3671,5 +3666,5 @@
// ntfs_post_write_mst_fixup((NTFS_RECORD*)index_block);
Vprintf("Syncing $Bitmap.\n");
- m = (MFT_RECORD*)(buf + 6 * opt.mft_record_size);
+ m = (MFT_RECORD*)(buf + 6 * vol->mft_record_size);
ctx = ntfs_get_attr_search_ctx(NULL, m);
if (!ctx)
@@ -3682,8 +3677,8 @@
a = ctx->attr;
if (a->non_resident) {
- rl = decompress_run_list(a);
+ rl = ntfs_decompress_mapping_pairs(vol, a, NULL);
ntfs_put_attr_search_ctx(ctx);
if (!rl)
- err_exit("decompress_run_list() failed\n");
+ err_exit("ntfs_decompress_mapping_pairs() failed\n");
lw = ntfs_rlwrite(f, rl, lcn_bitmap, lcn_bitmap_byte_size,
NULL);
@@ -3701,22 +3696,22 @@
*/
Vprintf("Syncing $MFT.\n");
- pos = opt.mft_lcn * opt.cluster_size;
- lw = opt.mft_record_size;
- for (i = 0; i < opt.mft_size / opt.mft_record_size; i++) {
+ pos = opt.mft_lcn * vol->cluster_size;
+ lw = vol->mft_record_size;
+ for (i = 0; i < opt.mft_size / vol->mft_record_size; i++) {
if (!opt.no_action)
- lw = ntfs_mst_pwrite(f, pos, 1, opt.mft_record_size,
- buf + i * opt.mft_record_size);
+ lw = ntfs_mst_pwrite(f, pos, 1, vol->mft_record_size,
+ buf + i * vol->mft_record_size);
if (lw != 1)
err_exit("%s\n", lw == -1 ? strerror(errno) :
"unknown error");
- pos += opt.mft_record_size;
+ pos += vol->mft_record_size;
}
Vprintf("Updating $MFTMirr.\n");
- pos = opt.mftmirr_lcn * opt.cluster_size;
- lw = opt.mft_record_size;
- for (i = 0; i < rl_mftmirr...
[truncated message content] |