[Ocfs2-tools-devel] [PATCH 07/23] tunefs rework: Add op_set_label.c

Joel Becker joel.becker at oracle.com
Mon Aug 11 17:31:59 PDT 2008


The set_label operation changes the volume label on an ocfs2 filesystem.

This is the tunefs option '-L'.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
Signed-off-by: Mark Fasheh <mfasheh at suse.com>
---
 tunefs.ocfs2/op_set_label.c |  108 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)
 create mode 100644 tunefs.ocfs2/op_set_label.c

diff --git a/tunefs.ocfs2/op_set_label.c b/tunefs.ocfs2/op_set_label.c
new file mode 100644
index 0000000..ee5e680
--- /dev/null
+++ b/tunefs.ocfs2/op_set_label.c
@@ -0,0 +1,108 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * op_set_label.c
+ *
+ * ocfs2 tune utility for updating the volume label.
+ *
+ * Copyright (C) 2004, 2008 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+#include "ocfs2/ocfs2.h"
+
+#include "libocfs2ne.h"
+
+
+static errcode_t update_volume_label(ocfs2_filesys *fs, const char *label)
+{
+	errcode_t err;
+	int len = strlen(label);
+
+	if (len > OCFS2_MAX_VOL_LABEL_LEN)
+		len = OCFS2_MAX_VOL_LABEL_LEN;
+	if (!memcmp(OCFS2_RAW_SB(fs->fs_super)->s_label, label, len)) {
+		verbosef(VL_APP,
+			 "Device \"%s\" already has the label \"%.*s\"; "
+			 "nothing to do\n",
+			 fs->fs_devname, OCFS2_MAX_VOL_LABEL_LEN, label);
+		return 0;
+	}
+
+	if (!tunefs_interact("Change the label on device \"%s\" from "
+			     "\"%.*s\" to \"%.*s\"? ",
+			     fs->fs_devname, OCFS2_MAX_VOL_LABEL_LEN,
+			     OCFS2_RAW_SB(fs->fs_super)->s_label,
+			     OCFS2_MAX_VOL_LABEL_LEN, label))
+		return 0;
+
+	memset(OCFS2_RAW_SB(fs->fs_super)->s_label, 0,
+	       OCFS2_MAX_VOL_LABEL_LEN);
+	strncpy((char *)OCFS2_RAW_SB(fs->fs_super)->s_label, label,
+		OCFS2_MAX_VOL_LABEL_LEN);
+
+	tunefs_block_signals();
+	err = ocfs2_write_super(fs);
+	tunefs_unblock_signals();
+
+	return err;
+}
+
+static int set_label_parse_option(struct tunefs_operation *op, char *arg)
+{
+	int rc = 0;
+
+	if (arg)
+		op->to_private = arg;
+	else {
+		errorf("No label specified\n");
+		rc = 1;
+	}
+
+	return rc;
+}
+
+static int set_label_run(struct tunefs_operation *op, ocfs2_filesys *fs,
+			 int flags)
+{
+	errcode_t err;
+	int rc = 0;
+	char *new_label = op->to_private;
+
+	err = update_volume_label(fs, new_label);
+	if (err) {
+		tcom_err(err,
+			 "- unable to update the label on device \"%s\"",
+			 fs->fs_devname);
+		rc = 1;
+	}
+
+	return rc;
+}
+
+
+DEFINE_TUNEFS_OP(set_label,
+		 "Usage: op_set_label [opts] <device> <label>\n",
+		 TUNEFS_FLAG_RW,
+		 set_label_parse_option,
+		 set_label_run);
+
+#ifdef DEBUG_EXE
+int main(int argc, char *argv[])
+{
+	return tunefs_op_main(argc, argv, &set_label_op);
+}
+#endif
-- 
1.5.6.3




More information about the Ocfs2-tools-devel mailing list