Changes by: szaka
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv19112/libntfs
Modified Files:
attrib.c
Log Message:
Merge set_ntfs_volume_flags() and code from ntfsfix as a new library
function: ntfs_set_volume_flags(). Note, ntfs_set_volume_flags() is
moving to volume.[ch]
Index: attrib.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/attrib.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -U2 -r1.60 -r1.61
--- attrib.c 12 Jul 2002 08:18:15 -0000 1.60
+++ attrib.c 14 Jul 2002 17:16:52 -0000 1.61
@@ -41,22 +41,45 @@
uchar_t AT_NONAME[] = { const_cpu_to_le16('\0') };
-/* FIXME: Need to write the new flags to disk. */
/**
- * set_ntfs_volume_flags
+ * ntfs_set_volume_flags - set the flags of an ntfs volume
+ * @vol: ntfs volume where we set the volume flags
+ * @flags: new flags
+ *
+ * Set the on-disk volume flags in the mft record of $Volume and
+ * on volume @vol to @flags.
+ *
+ * Return 0 on successful and -1 if not, with errno set to the error code.
*/
-int set_ntfs_volume_flags(ntfs_volume *v, MFT_RECORD *b, const u16 flags)
+int ntfs_set_volume_flags(ntfs_volume *vol, const u16 flags)
{
+ MFT_RECORD *m = NULL;
ATTR_RECORD *r;
VOLUME_INFORMATION *c;
ntfs_attr_search_ctx *ctx;
+ int ret = -1; /* failure */
+
+ if (!vol) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (ntfs_read_file_record(vol, FILE_Volume, &m, NULL)) {
+ Dperror("Failed to read $Volume");
+ return -1;
+ }
+
+ /* Sanity check */
+ if (!(m->flags & MFT_RECORD_IN_USE)) {
+ Dprintf("Error: $Volume has been deleted. Cannot "
+ "handle this yet. Run chkdsk to fix this.\n");
+ errno = EIO;
+ goto err_exit;
+ }
- /* Sanity checks. */
- if (!b || !is_mft_record(b->magic))
- return 0;
/* Get a pointer to the volume information attribute. */
- ctx = ntfs_get_attr_search_ctx(NULL, b);
+ ctx = ntfs_get_attr_search_ctx(NULL, m);
if (!ctx) {
Dperror("Failed to allocate attribute search context");
- return 0;
+ goto err_exit;
}
if (ntfs_lookup_attr(AT_VOLUME_INFORMATION, AT_NONAME, 0, 0, 0, NULL, 0,
@@ -71,4 +94,5 @@
Dputs("Error: Attribute $VOLUME_INFORMATION must be resident "
"(and it isn't)!");
+ errno = EIO;
goto err_out;
}
@@ -77,19 +101,27 @@
/* Sanity checks. */
if ((char*)c + le32_to_cpu(r->value_length) >
- le16_to_cpu(b->bytes_in_use) + (char*)b ||
+ le16_to_cpu(m->bytes_in_use) + (char*)m ||
le16_to_cpu(r->value_offset) +
le32_to_cpu(r->value_length) > le32_to_cpu(r->length)) {
Dputs("Error: Attribute $VOLUME_INFORMATION in $Volume is "
"corrupt!");
+ errno = EIO;
goto err_out;
}
/* Set the volume flags. */
- v->flags = c->flags = cpu_to_le16(flags);
- ntfs_put_attr_search_ctx(ctx);
- /* Success! */
- return 1;
+ vol->flags = c->flags = cpu_to_le16(flags);
+
+ if (ntfs_write_mft_record(vol, FILE_Volume, m)) {
+ Dperror("Error writing $Volume");
+ goto err_out;
+ }
+
+ ret = 0; /* success */
err_out:
ntfs_put_attr_search_ctx(ctx);
- return 0;
+err_exit:
+ if (m)
+ free(m);
+ return ret;
}
|