Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv27947/ntfstools
Modified Files:
mkntfs.c
Log Message:
Make mft bitmap non resident and located just after $Boot.
This fixes all the crashes experienced!
This makes mkntfs complete and bug free AFAIK.
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -U2 -r1.37 -r1.38
--- mkntfs.c 2001/06/15 16:47:47 1.37
+++ mkntfs.c 2001/06/16 18:26:34 1.38
@@ -126,6 +126,6 @@
int lcn_bitmap_byte_size;
unsigned char *lcn_bitmap = NULL;
-run_list *rl = NULL, *rl_mft = NULL, *rl_mftmirr = NULL, *rl_logfile = NULL;
-run_list *rl_boot = NULL, *rl_bad = NULL, *rl_index;
+run_list *rl = NULL, *rl_mft = NULL, *rl_mft_bmp = NULL, *rl_mftmirr = NULL;
+run_list *rl_logfile = NULL, *rl_boot = NULL, *rl_bad = NULL, *rl_index;
INDEX_ALLOCATION *index_block = NULL;
uchar_t *ustr = NULL;
@@ -1951,4 +1951,26 @@
/*
+ * Create a non-resident bitmap attribute with a predefined on disk location
+ * specified by the run_list @rl. The clusters specified by @rl are assumed to
+ * be allocated already.
+ *
+ * Return 0 on success or -errno on error.
+ */
+int add_attr_bitmap_positioned(MFT_RECORD *m, const char *name,
+ const __u32 name_len, const IGNORE_CASE_BOOL ic,
+ const uchar_t *upcase, const __u32 upcase_len,
+ const run_list *rl, const char *bitmap, const __u32 bitmap_len)
+{
+ int err;
+
+ err = insert_positioned_attr_in_mft_record(m, $BITMAP, name, name_len,
+ ic, upcase, upcase_len, 0, rl, bitmap, bitmap_len);
+ if (err < 0)
+ Eprintf("add_attr_bitmap_positioned failed: %s\n",
+ strerror(-err));
+ return err;
+}
+
+/*
* Create bitmap and index allocation attributes, modify index root
* attribute accordingly and move all of the index entries from the index root
@@ -2559,4 +2581,6 @@
if (rl_mft)
free(rl_mft);
+ if (rl_mft_bmp)
+ free(rl_mft_bmp);
if (rl_mftmirr)
free(rl_mftmirr);
@@ -2863,4 +2887,22 @@
for (i = 0; i < j; i++)
ntfs_set_bit(lcn_bitmap, opt.mft_lcn + i, 1);
+ /* Create run list for mft bitmap. */
+ rl_mft_bmp = (run_list *)malloc(2 * sizeof(run_list));
+ if (!rl_mft_bmp)
+ err_exit("Failed to allocate internal buffer: %s\n",
+ strerror(errno));
+ rl_mft_bmp[0].vcn = 0LL;
+ /* Mft bitmap is right after $Boot's data. */
+ j = (8192 + opt.cluster_size - 1) / opt.cluster_size;
+ rl_mft_bmp[0].lcn = j;
+ /*
+ * Size is always one cluster, even though valid data size and
+ * initialized data size are only 8 bytes.
+ */
+ rl_mft_bmp[1].vcn = rl_mft_bmp[0].length = 1LL;
+ rl_mft_bmp[1].lcn = -1LL;
+ rl_mft_bmp[1].length = 0LL;
+ /* Allocate cluster for mft bitmap. */
+ ntfs_set_bit(lcn_bitmap, (__s64)j, 1);
/* Determine mftmirr_lcn (middle of volume). */
opt.mftmirr_lcn = (opt.nr_sectors * opt.sector_size >> 1)
@@ -3088,8 +3130,8 @@
err = add_attr_sd(m, sd, i);
}
- /* mft_bitmap is not modified in mkntfs, so no need to sync it later. */
+ /* mft_bitmap is not modified in mkntfs; no need to sync it later. */
if (!err)
- err = add_attr_bitmap(m, NULL, 0, 0, NULL, 0, mft_bitmap,
- mft_bitmap_byte_size);
+ err = add_attr_bitmap_positioned(m, NULL, 0, 0, NULL, 0,
+ rl_mft_bmp, mft_bitmap, mft_bitmap_byte_size);
if (err < 0)
err_exit("Couldn't create $MFT: %s\n", strerror(-err));
|