Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv27223/ntfstools
Modified Files:
mkntfs.c
Log Message:
More work on mkntfs dir stuff.
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -U2 -r1.7 -r1.8
--- mkntfs.c 2001/06/04 11:29:45 1.7
+++ mkntfs.c 2001/06/04 14:04:31 1.8
@@ -1814,4 +1814,20 @@
/* Return 0 on success or -errno on error. */
+int add_attr_index_alloc(MFT_RECORD *m, const char *name, const __u32 name_len,
+ const IGNORE_CASE_BOOL ic, const uchar_t *upcase,
+ const __u32 upcase_len, const char *index_alloc_val,
+ const __u32 index_alloc_val_len)
+{
+ int err;
+
+ err = insert_non_resident_attr_in_mft_record(m, $INDEX_ALLOCATION, name,
+ name_len, ic, upcase, upcase_len, 0,
+ index_alloc_val, index_alloc_val_len);
+ if (err < 0)
+ Eprintf("add_attr_index_alloc 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,
@@ -1851,8 +1867,9 @@
ATTR_RECORD *a;
INDEX_ROOT *r;
- INDEX_ENTRY *e, *e_end;
- INDEX_ALLOCATION *a;
+ INDEX_ENTRY *re, *ae;
+ INDEX_ALLOCATION *ia_val;
uchar_t *uname;
char bmp[8];
+ char *re_end;
int i, err, r_size, index_block_size;
@@ -1860,7 +1877,11 @@
i = (name_len + 1) * sizeof(uchar_t);
uname = (uchar_t*)calloc(1, i);
+ if (!uname)
+ return -errno;
name_len = stoucs(uname, name, i);
- if (name_len > 0xff)
+ if (name_len > 0xff) {
+ free(uname);
return -ENAMETOOLONG;
+ }
} else
uname = NULL;
@@ -1868,18 +1889,19 @@
memset(&ctx, 0, sizeof(ctx));
ctx.mrec = m;
- if (!find_first_attr($INDEX_ROOT, uname, name_len, ic, upcase,
- upcase_len, NULL, NULL, &ctx)) {
- if (uname)
- free(uname);
+ err = find_first_attr($INDEX_ROOT, uname, name_len, ic, upcase,
+ upcase_len, NULL, NULL, &ctx);
+ if (uname)
+ free(uname);
+ if (!err)
return -ENOTDIR;
- }
a = ctx.attr;
if (a->non_resident || a->flags)
return -EINVAL;
r = (INDEX_ROOT*)((char*)a + le16_to_cpu(a->value_offset));
- e_end = (INDEX_ENTRY*)((char)*r + le32_to_cpu(a->value_length));
- e = (INDEX_ENTRY*)((char*)&r->index + r->index.entries_offset);
+ re_end = (char*)r + le32_to_cpu(a->value_length);
+ re = (INDEX_ENTRY*)((char*)&r->index + r->index.entries_offset);
index_block_size = le32_to_cpu(r->index_block_size);
memset(bmp, 0, sizeof(bmp));
+ ntfs_set_bit(&bmp, 0, 1);
/* Bitmap has to be at least 8 bytes in size. */
err = add_attr_bitmap(m, uname, name_len, ic, upcase, upcase_len,
@@ -1887,4 +1909,44 @@
if (err)
return err;
+ ia_val = calloc(1, index_block_size);
+ if (!ia_val)
+ return = -errno;
+ /* Setup header. */
+ ia_val->magic = magic_INDX;
+ ia_val->usa_ofs = cpu_to_le16(sizeof(INDEX_ALLOCATION));
+ ia_val->usa_count = cpu_to_le16();
+ /* Set USN to 1. */
+ *(__u16)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) =
+ cpu_to_le16(1);
+ ia_val->lsn = cpu_to_le64(0);
+ ia_val->index_block_vcn = cpu_to_le64(0);
+ /* FIXME: Do we need alignment? */
+ ia_val->index.entries_offset = cpu_to_le32(sizeof(INDEX_HEADER) +
+ le16_to_cpu(ia_val->usa_count) * 2);
+ /* FIXME: Does the size really include the USA?!? */
+ ia_val->index.allocated_size = cpu_to_le32(index_block_size -
+ (sizeof(INDEX_ALLOCATION) - sizeof(INDEX_HEADER)));
+ ae = (INDEX_ENTRY*)((char*)ia_val +
+ le32_to_cpu(ia_val->index.entries_offset));
+ /* Move all entries. */
+ do {
+ /* FIXME: Is it that easy? If so we could walk the list only
+ * and when we reach the end just copy the lot in one go! */
+ memcpy(ae, re, le16_to_cpu(re->length));
+ /* Next entry in index root. */
+ re = (INDEX_ENTRY*)((char*)re + le16_to_cpu(re->length));
+ /* Next entry in index allocation. */
+ ae = (INDEX_ENTRY*)((char*)ae + le16_to_cpu(ae->length));
+ } while ((char*)re < re_end && !(re->flags & INDEX_ENTRY_END));
+ /* TODO: Terminate the index allocation (how?). */
+ // ae points to the position in the index allocation, where the
+ // termination index entry has to go
+ ia_val->index.index_length = cpu_to_le32((char*)ae -
+ (char*)&ia_val->index + sizeof(INDEX_ENTRY));
+ /* TODO: Modify index root to be empty and just to point to the
+ * index allocation: need to change the r->index.index_length and
+ * .allocated_size and make the first entry to be a terminator with
+ * vcn inside it which is 0LL. */
+ // re at the moment points to the index root termination index entry
err = add_attr_index_alloc(m, uname, name_len, ic, upcase, upcase_len,
/*TODO: ...*/);
|