Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv1569/ntfstools
Modified Files:
mkntfs.c
Log Message:
Fix/expand dircetory info in layout.h and add creation of index root attribute
to mkntfs.c.
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -U2 -r1.4 -r1.5
--- mkntfs.c 2001/06/01 19:04:08 1.4
+++ mkntfs.c 2001/06/03 02:09:08 1.5
@@ -1737,4 +1737,81 @@
/* Return 0 on success or -errno on error. */
+int add_attr_index_root(MFT_RECORD *m, const char *name, const __u32 name_len,
+ const IGNORE_CASE_BOOL ic, const uchar_t *upcase,
+ const __u32 upcase_len, const ATTR_TYPES indexed_attr_type,
+ const COLLATION_RULES collation_rule,
+ const __u32 index_block_size)
+{
+ INDEX_ROOT *r;
+ INDEX_ENTRY_HEADER *e;
+ int i, err, val_len;
+
+ val_len = sizeof(INDEX_ROOT) + sizeof(INDEX_ENTRY_HEADER);
+ r = (INDEX_ROOT*)malloc(val_len);
+ if (!r)
+ return -errno;
+ r->type = indexed_attr_type == $FILE_NAME ? $FILE_NAME : 0;
+ if (indexed_attr_type == $FILE_NAME &&
+ collation_rule != COLLATION_FILE_NAME) {
+ free(r);
+ Eprintf("add_attr_index_root: indexed attribute is $FILE_NAME "
+ "but collation rule is not COLLATION_FILE_NAME.\n");
+ return -EINVAL;
+ }
+ 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) {
+ Eprintf("add_attr_index_root: index block size is not "
+ "a multiple of the vluster size.\n");
+ free(r);
+ return -EINVAL;
+ }
+ r->clusters_per_index_block = index_block_size /
+ opt.cluster_size;
+ } else {
+ if (index_block_size & index_block_size - 1) {
+ Eprintf("add_attr_index_root: index block size is not "
+ "a power of 2.\n");
+ free(r);
+ return -EINVAL;
+ }
+ r->clusters_per_index_block = -(1 << (ffs(opt.index_block_size)
+ - 1));
+ if ((1 << -r->clusters_per_index_block) !=
+ opt.index_block_size)
+ err_exit("BUG: calculated clusters_per_index_block "
+ "is wrong (= 0x%x)\n",
+ r->clusters_per_index_block);
+ }
+ memset(&r->reserved, 0, sizeof(r->reserved));
+ r->index.entries_offset = cpu_to_le32(sizeof(INDEX_HEADER));
+ r->index.index_length = cpu_to_le32(sizeof(INDEX_HEADER) +
+ sizeof(INDEX_ENTRY_HEADER));
+ r->index.allocated_size = r->index.index_length;
+ r->index.flags = SMALL_INDEX;
+ memset(&r->index.reserved, 0, sizeof(r->index.reserved));
+ e = (INDEX_ENTRY_HEADER*)((char*)&r->index +
+ le32_to_cpu(r->index.entries_offset));
+ /*
+ * No matter whether this is a file index or a view as this is a
+ * termination entry, hence no key value / data is associated with it
+ * at all. Thus, we just need the union to be all zero.
+ */
+ e->indexed_file = cpu_to_le64(0LL);
+ e->length = cpu_to_le16(sizeof(INDEX_ENTRY_HEADER));
+ e->key_length = cpu_to_le16(0);
+ e->flags = INDEX_ENTRY_END;
+ e->reserved = cpu_to_le16(0);
+ err = insert_resident_attr_in_mft_record(m, $INDEX_ROOT, name,
+ name_len, ic, upcase, upcase_len,
+ 0, 0, (char*)r, val_len);
+ free(r);
+ if (err < 0)
+ Eprintf("add_attr_index_root failed: %s\n", strerror(-err));
+ return err;
+}
+
+/* Return 0 on success or -errno on error. */
int add_attr_bitmap(MFT_RECORD *m, const char *name, const __u32 name_len,
const IGNORE_CASE_BOOL ic, const uchar_t *upcase,
@@ -2406,5 +2483,5 @@
err_exit("BUG: calculated clusters_per_mft_record "
"is wrong (= 0x%x)\n",
- opt.mft_record_size);
+ bs->clusters_per_mft_record);
}
Dprintf("Clusters per mft record = %i (0x%x)\n",
@@ -2421,5 +2498,5 @@
err_exit("BUG: calculated clusters_per_index_block "
"is wrong (= 0x%x)\n",
- opt.index_block_size);
+ bs->clusters_per_index_block);
}
Dprintf("Clusters per index block = %i (0x%x)\n",
@@ -2522,4 +2599,5 @@
Dprintf("Creating root directory (mft record 5)\n");
m = (MFT_RECORD*)(buf + 5 * opt.mft_record_size);
+ m->flags |= MFT_RECORD_IS_DIRECTORY;
if (!err)
err = add_attr_file_name(m, root_ref, 0LL, 0LL,
@@ -2531,8 +2609,11 @@
err = add_attr_sd(m, sd, i);
}
+ if (!err)
+ err = add_attr_index_root(m, "$I30", 4, IGNORE_CASE, opt.upcase,
+ opt.upcase_len, $FILE_NAME, COLLATION_FILE_NAME,
+ opt.index_block_size);
if (err < 0)
err_exit("Couldn't create root directory: %s\n",
strerror(-err));
- // add_attr_index_root(m, );
// add_attr_bitmap(m, );
// add_attr_index_alloc(m, );
|