Changes by: mattjf
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv8027/ntfstools
Modified Files:
ntfslabel.c
Log Message:
Code changes - still broke
Index: ntfslabel.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfslabel.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -U2 -r1.9 -r1.10
--- ntfslabel.c 25 Apr 2002 18:07:06 -0000 1.9
+++ ntfslabel.c 25 Apr 2002 18:31:20 -0000 1.10
@@ -211,5 +211,5 @@
stoucs(new_label,label,label_len);
- label_len = sizeof(char) * label_len;
+ label_len = sizeof(uchar_t) * label_len;
if (resize_resident_attribute_value(mrec, a, label_len)) {
@@ -218,13 +218,16 @@
}
+ printf("%s\n",label);
+ memcpy((char*)a + le16_to_cpu(a->value_offset), label, min(le32_to_cpu(a->value_length), label_len));
- if (modify_resident_attr_in_mft_record(mrec,
+ /*if (modify_resident_attr_in_mft_record(mrec,
AT_VOLUME_NAME, NULL, 0, 0, 0, 0, (char *)label,label_len)) {
printf("Error: Cannot modify resident attribute!\n");
exit(1);
- }
+ }*/
+
@@ -245,4 +248,5 @@
+
}
@@ -254,6 +258,5 @@
/* Return 0 on success and -errno on error. */
-int
-resize_resident_attribute_value(MFT_RECORD * m, ATTR_RECORD * a,
+int resize_resident_attribute_value(MFT_RECORD * m, ATTR_RECORD * a,
const __u32 new_vsize)
{
@@ -284,6 +287,10 @@
}
-int
-stoucs(uchar_t * dest, const char *src, int maxlen)
+
+
+
+
+
+int stoucs(uchar_t * dest, const char *src, int maxlen)
{
char c;
@@ -301,166 +308,2 @@
return i;
}
-
-/**
- * make_room_for_attribute - make room for an attribute inside an mft record
- * @m: mft record
- * @pos: position at which to make space
- * @size: byte size to make available at this position
- *
- * @pos points to the attribute in front of which we want to make space.
- *
- * Return 0 on success or -errno on error. Possible error codes are:
- *
- * -ENOSPC There is not enough space available to complete
- * operation. The caller has to make space before calling
- * this.
- * -EINVAL Can only occur if mkntfs was compiled with -DEBUG. Means
- * the input parameters were faulty.
- */
-int
-make_room_for_attribute(MFT_RECORD * m, char *pos, const __u32 size)
-{
- __u32 biu;
-
- if (!size)
- return 0;
-#ifdef DEBUG
- /*
- * Rigorous consistency checks. Always return -EINVAL even if more
- * appropriate codes exist for simplicity of parsing the return value.
- */
- if (size != ((size + 7) & ~7)) {
- fprintf(stderr, "make_room_for_attribute() received non "
- "8-byte aligned size.\n");
- return -EINVAL;
- }
- if (!m || !pos)
- return -EINVAL;
- if (pos < (char *) m || pos + size < (char *) m ||
- pos > (char *) m + le32_to_cpu(m->bytes_allocated) ||
- pos + size > (char *) m + le32_to_cpu(m->bytes_allocated))
- return -EINVAL;
- /* The -8 is for the attribute terminator. */
- if (pos - (char *) m > le32_to_cpu(m->bytes_in_use) - 8)
- return -EINVAL;
-#endif
- biu = le32_to_cpu(m->bytes_in_use);
- /* Do we have enough space? */
- if (biu + size > le32_to_cpu(m->bytes_allocated))
- return -ENOSPC;
- /* Move everything after pos to pos + size. */
- memmove(pos + size, pos, biu - (pos - (char *) m));
- /* Update mft record. */
- m->bytes_in_use = cpu_to_le32(biu + size);
- return 0;
-}
-
-
-
-
-
-/* Return 0 on success and -errno on error. */
-int modify_resident_attr_in_mft_record(MFT_RECORD *m, const ATTR_TYPES type,
- const char *name, __u32 name_len, const IGNORE_CASE_BOOL ic,
- const ATTR_FLAGS flags, const RESIDENT_ATTR_FLAGS res_flags,
- const char *val, const __u32 val_len)
-{
- ntfs_attr_search_ctx *ctx;
- ATTR_RECORD *a;
- int asize, err, i;
- uchar_t *uname;
-/*
- if (base record)
- lookup_attr();
- else
-*/
- if (name_len) {
- i = (name_len + 1) * sizeof(uchar_t);
- uname = (uchar_t*)calloc(1, i);
- name_len = stoucs(uname, name, i);
- if (name_len > 0xff)
- return -ENAMETOOLONG;
- } else
- uname = NULL;
-
-
- /* Check if the attribute is already there. */
- ctx = ntfs_get_attr_search_ctx(NULL, m);
- if (!ctx) {
- printf("Failed to allocate attribute search context.\n");
- err = -ENOMEM;
- goto err_out;
- }
- if (ic == IGNORE_CASE) {
- printf("FIXME: Hit unimplemented code path #3.\n");
- err = -ENOTSUP;
- goto err_out;
- }
-
- if (errno != ENOENT) {
- printf("Corrupt inode.\n");
- err = -errno;
- goto err_out;
- }
- a = ctx->attr;
- asize = val_len;
- /* sizeof(resident attribute record header) == 24 */
- asize = ((24 + ((name_len + 7) & ~7) + val_len) + 7) & ~7;
- err = make_room_for_attribute(m, (char*)a, asize);
- if (err == -ENOSPC) {
- // FIXME: Make space! (AIA)
- // can we make it non-resident? if yes, do that.
- // does it fit now? yes -> do it.
- // m's $DATA or $BITMAP+$INDEX_ALLOCATION resident?
- // yes -> make non-resident
- // does it fit now? yes -> do it.
- // make all attributes non-resident
- // does it fit now? yes -> do it.
- // m is a base record? yes -> allocate extension record
- // does the new attribute fit in there? yes -> do it.
- // split up run_list into extents and place each in an extension
- // record.
- // FIXME: the check for needing extension records should be
- // earlier on as it is very quick: asize > m->bytes_allocated?
- err = -ENOTSUP;
- goto err_out;
- }
-
-
-#ifdef DEBUG
- if (err == -EINVAL) {
- fprintf(stderr, "BUG(): in insert_resident_attribute_in_mft_"
- "record(): make_room_for_attribute() returned "
- "error: EINVAL!\n");
- goto err_out;
- }
-#endif
- a->type = type;
- a->length = cpu_to_le32(asize);
- a->non_resident = 0;
- a->name_length = name_len;
- a->name_offset = cpu_to_le16(24);
- a->flags = cpu_to_le16(flags);
- a->instance = m->next_attr_instance;
- m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance)
- + 1) & 0xffff);
- a->value_length = cpu_to_le32(val_len);
- a->value_offset = cpu_to_le16(24 + ((name_len + 7) & ~7));
- a->resident_flags = res_flags;
- a->reservedR = 0;
-
-
- if (name_len)
- memcpy((char*)a + 24, uname, name_len << 1);
- if (val_len)
- memcpy((char*)a + le16_to_cpu(a->value_offset), val, val_len);
-
-err_out:
- if (ctx)
- ntfs_put_attr_search_ctx(ctx);
- if (uname)
- free(uname);
- return err;
-}
-
-
|