Changes by: szaka
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv20454/libntfs
Modified Files:
volume.c attrib.c
Log Message:
Move ntfs_set_volume_flags() from attrib[ch] to volume.[ch]
Index: volume.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/volume.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -U2 -r1.55 -r1.56
--- volume.c 14 Jul 2002 13:18:01 -0000 1.55
+++ volume.c 14 Jul 2002 17:21:32 -0000 1.56
@@ -1016,2 +1016,87 @@
}
+/**
+ * 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 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;
+ }
+
+ /* Get a pointer to the volume information attribute. */
+ ctx = ntfs_get_attr_search_ctx(NULL, m);
+ if (!ctx) {
+ Dperror("Failed to allocate attribute search context");
+ goto err_exit;
+ }
+ if (ntfs_lookup_attr(AT_VOLUME_INFORMATION, AT_NONAME, 0, 0, 0, NULL, 0,
+ ctx)) {
+ Dputs("Error: Attribute $VOLUME_INFORMATION was not found in "
+ "$Volume!");
+ goto err_out;
+ }
+ r = ctx->attr;
+ /* Sanity check. */
+ if (r->non_resident) {
+ Dputs("Error: Attribute $VOLUME_INFORMATION must be resident "
+ "(and it isn't)!");
+ errno = EIO;
+ goto err_out;
+ }
+ /* Get a pointer to the value of the attribute. */
+ c = (VOLUME_INFORMATION*)(le16_to_cpu(r->value_offset) + (char*)r);
+ /* Sanity checks. */
+ if ((char*)c + le32_to_cpu(r->value_length) >
+ 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. */
+ 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);
+err_exit:
+ if (m)
+ free(m);
+ return ret;
+}
+
Index: attrib.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/attrib.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -U2 -r1.61 -r1.62
--- attrib.c 14 Jul 2002 17:16:52 -0000 1.61
+++ attrib.c 14 Jul 2002 17:21:32 -0000 1.62
@@ -42,89 +42,4 @@
/**
- * 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 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;
- }
-
- /* Get a pointer to the volume information attribute. */
- ctx = ntfs_get_attr_search_ctx(NULL, m);
- if (!ctx) {
- Dperror("Failed to allocate attribute search context");
- goto err_exit;
- }
- if (ntfs_lookup_attr(AT_VOLUME_INFORMATION, AT_NONAME, 0, 0, 0, NULL, 0,
- ctx)) {
- Dputs("Error: Attribute $VOLUME_INFORMATION was not found in "
- "$Volume!");
- goto err_out;
- }
- r = ctx->attr;
- /* Sanity check. */
- if (r->non_resident) {
- Dputs("Error: Attribute $VOLUME_INFORMATION must be resident "
- "(and it isn't)!");
- errno = EIO;
- goto err_out;
- }
- /* Get a pointer to the value of the attribute. */
- c = (VOLUME_INFORMATION*)(le16_to_cpu(r->value_offset) + (char*)r);
- /* Sanity checks. */
- if ((char*)c + le32_to_cpu(r->value_length) >
- 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. */
- 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);
-err_exit:
- if (m)
- free(m);
- return ret;
-}
-
-/**
* get_attribute_value_length
*/
|