Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv18316/ntfstools
Modified Files:
mkntfs.c
Log Message:
mkntfs compiles. But untested. Also there are still things to do...
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -U2 -r1.14 -r1.15
--- mkntfs.c 2001/06/07 23:31:54 1.14
+++ mkntfs.c 2001/06/08 14:09:52 1.15
@@ -85,6 +85,7 @@
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;
-INDEX_ALLOCATION *index = NULL;
+run_list *rl_boot = NULL, *rl_bad = NULL, *rl_index;
+INDEX_ALLOCATION *index_block = NULL;
+uchar_t *ustr = NULL;
struct {
@@ -1545,24 +1546,8 @@
}
-/*
- * Write @val_len bytes from @val into the non-resident value of the attribute
- * @a in the mft record @m at offset @ofs into the attribute value.
- *
- * Note, the attribute value must be of sufficient size (>= @ofs + @val_len) for
- * this function to succeed; i.e. this function does not resize the attribute
- * value.
- *
- * Return 0 on success or -errno on error.
- */
-int write_non_resident_attr_value(MFT_RECORD *m, ATTR_RECORD *a, char *val,
- char *val_len)
-{
- retun -ENOTSUP;
-}
-
__s64 time2ntfs(__s64 time)
{
return cpu_to_le64((time + (__s64)(369 * 365 + 89) * 24 * 3600)
- * 10000000);
+ * 10000000);
}
@@ -2127,6 +2112,6 @@
while ((char*)ie < index_end && !(ie->flags & INDEX_ENTRY_END)) {
ie_key_len = le16_to_cpu(ie->key_length);
- i = memcmp(ie->key.file_name, file_name, min(ie_key_len,
- file_name_size));
+ i = memcmp((char*)&ie->key.file_name, (char*)file_name,
+ min(ie_key_len, file_name_size));
/* Gone too far, thus found insertion location. */
if (i > 0)
@@ -2155,5 +2140,5 @@
if (err) {
Eprintf("make_room_for_index_entry_in_index_block failed: "
- "%s\n", sterror(-err));
+ "%s\n", strerror(-err));
return err;
}
@@ -2191,6 +2176,6 @@
int err;
- if (index)
- free(index);
+ if (index_block)
+ free(index_block);
if (buf)
free(buf);
@@ -2213,4 +2198,8 @@
if (rl_bad)
free(rl_bad);
+ if (rl_index)
+ free(rl_index);
+ if (ustr)
+ free(ustr);
if (opt.bad_blocks)
free(opt.bad_blocks);
@@ -2406,5 +2395,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 + opt.cluster_size - 1 &
+ ~(opt.cluster_size - 1);
Dprintf("lcn_bitmap_byte_size = %i, allocated = %i\n",
lcn_bitmap_byte_size, i);
@@ -2673,5 +2663,5 @@
if (!err) {
err = upgrade_to_large_index(m, "$I30", 4, IGNORE_CASE,
- opt.upcase, opt.upcase_len, &index);
+ opt.upcase, opt.upcase_len, &index_block);
}
if (!err) {
@@ -2683,5 +2673,5 @@
err_exit("BUG: $FILE_NAME attribute not found.\n");
a = ctx.attr;
- err = insert_file_link_in_dir_index(index, root_ref,
+ err = insert_file_link_in_dir_index(index_block, root_ref,
(FILE_NAME_ATTR*)((char*)a +
le16_to_cpu(a->value_offset)),
@@ -2694,15 +2684,31 @@
/* Sync the root directory's index block @index to disk. */
Dprintf("Syncing root directory index record.\n");
+ i = 5 * sizeof(uchar_t);
+ ustr = (uchar_t*)calloc(1, i);
+ if (!ustr)
+ err_exit("Not enough memory to allocate internal buffer.\n");;
+ j = stoucs(ustr, "$I30", i);
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.mrec = m;
+ if (!find_first_attr($INDEX_ALLOCATION, ustr, j, IGNORE_CASE,
+ opt.upcase, opt.upcase_len, NULL, 0, &ctx))
+ err_exit("BUG: $INDEX_ALLOCATION attribute not found.\n");
+ a = ctx.attr;
i = sizeof(INDEX_BLOCK) - sizeof(INDEX_HEADER) +
- le32_to_cpu(index->index.allocated_size);
- err = pre_write_mst_fixup((NTFS_RECORD*)index, i);
+ le32_to_cpu(index_block->index.allocated_size);
+ if (sle64_to_cpu(a->initialized_size) < i)
+ err_exit("BUG: $INDEX_ALLOCATION attribute too short.\n");
+ rl_index = decompress_run_list(a);
+ if (!rl_index)
+ err_exit("Failed to decompress run list of $INDEX_ALLOCATION "
+ "attribute.\n");
+ err = pre_write_mst_fixup((NTFS_RECORD*)index_block, i);
if (err)
err_exit("pre_write_mst_fixup() failed while syncing root "
"directory index block.\n");
- err = write_non_resident_attr_value();
- if (err)
- err_exit("write_non_resident_attr_value() failed while syncing "
- "root directory index block.\n");
- __post_read_mst_fixup((NTFS_RECORD*)index, i);
+ lw = ntfs_rlwrite(f, rl_index, (char*)index_block, i, NULL);
+ if (lw != i)
+ err_exit("Error writing $INDEX_ALLOCATION.\n");
+ __post_read_mst_fixup((NTFS_RECORD*)index_block, i);
// move down up to here
dump_mft_record(m);
|