Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv19777/ntfstools
Modified Files:
mkntfs.c
Log Message:
mkntfs - the end to the saga draws closer...
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -U2 -r1.13 -r1.14
--- mkntfs.c 2001/06/06 22:55:49 1.13
+++ mkntfs.c 2001/06/07 23:31:54 1.14
@@ -87,5 +87,4 @@
run_list *rl_boot = NULL, *rl_bad = NULL;
INDEX_ALLOCATION *index = NULL;
-unsigned int index_size;
struct {
@@ -1546,4 +1545,20 @@
}
+/*
+ * 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)
{
@@ -1552,4 +1567,5 @@
}
+/* Return 0 on success or -errno on error. */
int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags)
{
@@ -1894,5 +1910,5 @@
__u32 name_len, const IGNORE_CASE_BOOL ic,
const uchar_t *upcase, const __u32 upcase_len,
- INDEX_ALLOCATION **index, __u32 **index_size)
+ INDEX_ALLOCATION **index)
{
attr_search_context ctx;
@@ -2027,5 +2043,4 @@
}
*index = ia_val;
- *index_size = index_block_size;
return 0;
}
@@ -2083,15 +2098,14 @@
* Insert the fully completed FILE_NAME_ATTR @file_name which is inside
* the file with mft reference @file_ref into the index (allocation) block
- * @index of the parent directory with mft reference @parent_ref and mft
- * record @parent_dir.
+ * @index (which belongs to @file_ref's parent directory).
*
* Return 0 on success or -errno on error.
*/
-int insert_file_link_in_dir_index(INDEX_BLOCK *index, MFT_REF parent_ref,
- MFT_RECORD *parent_dir, MFT_REF file_ref,
+int insert_file_link_in_dir_index(INDEX_BLOCK *index, MFT_REF file_ref,
FILE_NAME_ATTR *file_name, __u32 file_name_size)
{
- int err;
+ int err, ie_key_len, i;
INDEX_ENTRY *ie;
+ char *index_end;
/*
@@ -2099,17 +2113,55 @@
* insertion location.
*/
- while (/**/) {
- //..
+ // FIXME: This is written doing a binary comparison of the
+ // file_name_attr values. This might NOT be what COLLATION_FILE_NAME
+ // means! Check it out!!! It quite probably is a comparison of the
+ // actual names within the file_name_attributes rather than this.
+ index_end = (char*)&index->index +
+ le32_to_cpu(index->index.index_length);
+ ie = (INDEX_ENTRY*)((char*)&index->index +
+ le32_to_cpu(index->index.entries_offset));
+ /*
+ * Loop until we exceed valid memory (corruption case) or until we
+ * reach the last entry.
+ */
+ 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));
+ /* Gone too far, thus found insertion location. */
+ if (i > 0)
+ break;
+ /* Perfect match. But what about the lengths? */
+ if (!i) {
+ /* Gone too far, thus found insertion location. */
+ if (ie_key_len > file_name_size)
+ break;
+ /* Found it. Bugger! Shouldn't be there! */
+ if (ie_key_len == file_name_size)
+ return -EEXIST;
+ /* Name too short, keep looking. */
+ /* if (ie_key_len < file_name_size)
+ goto do_next; */
+ }
+ /* Not found it yet, keep looking. */
+ /* if (i < 0)
+ goto do_next; */
+do_next:
+ /* Next entry. */
+ ie = (INDEX_ENTRY*)((char*)ie + le16_to_cpu(ie->length));
};
err = make_room_for_index_entry_in_index_block(index, ie,
file_name_size);
if (err) {
- //..
+ Eprintf("make_room_for_index_entry_in_index_block failed: "
+ "%s\n", sterror(-err));
+ return err;
}
/* Create entry in place and copy file name attribute value. */
ie->indexed_file = file_ref;
- ie->length = cpu_to_le16();
+ ie->length = cpu_to_le16(sizeof(INDEX_ENTRY_HEADER) + file_name_size +
+ 7 & ~7);
ie->key_length = cpu_to_le16(file_name_size);
- ie->flags = ;
+ ie->flags = 0;
ie->reserved = cpu_to_le16(0);
memcpy((char*)&ie->key.file_name, (char*)file_name, file_name_size);
@@ -2138,5 +2190,7 @@
{
int err;
-
+
+ if (index)
+ free(index);
if (buf)
free(buf);
@@ -2619,6 +2673,5 @@
if (!err) {
err = upgrade_to_large_index(m, "$I30", 4, IGNORE_CASE,
- opt.upcase, opt.upcase_len, &index,
- &index_size);
+ opt.upcase, opt.upcase_len, &index);
}
if (!err) {
@@ -2631,11 +2684,26 @@
a = ctx.attr;
err = insert_file_link_in_dir_index(index, root_ref,
- m, root_ref, (FILE_NAME_ATTR*)((char*)a +
+ (FILE_NAME_ATTR*)((char*)a +
le16_to_cpu(a->value_offset)),
le32_to_cpu(a->value_length));
}
- if (err < 0)
+ if (err)
err_exit("Couldn't create root directory: %s\n",
strerror(-err));
+ // move this to the end after verifying it works ok so far
+ /* Sync the root directory's index block @index to disk. */
+ Dprintf("Syncing root directory index record.\n");
+ i = sizeof(INDEX_BLOCK) - sizeof(INDEX_HEADER) +
+ le32_to_cpu(index->index.allocated_size);
+ err = pre_write_mst_fixup((NTFS_RECORD*)index, 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);
+ // move down up to here
dump_mft_record(m);
/* Add all other attributes, on a per-file basis for clarity. */
|