aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDongwoo Lee <dwoo08.lee@samsung.com>2021-05-21 19:32:38 +0900
committerJaegeuk Kim <jaegeuk@kernel.org>2021-05-24 10:10:52 -0700
commit6afd3e9df00aa3f90b54c8210bdcba7f7a190c30 (patch)
tree33f3f7251476bc533ec43474d7c4b3e229e27310
parent3218ff95d95c3e34de34813dea5c63d56ff37532 (diff)
downloadf2fs-tools-6afd3e9df00aa3f90b54c8210bdcba7f7a190c30.tar.gz
tools: Introduce f2fslabel
Although many other filesystems provide a tool for changing volume label, e.g. e2label for ext filesystem, but f2fs has no way to change volume label except set it while formatting with mkfs.f2fs. This introduces f2fslabel, simple tool for changing label of f2fs volume. Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fsck/Makefile.am1
-rw-r--r--fsck/main.c79
-rw-r--r--include/f2fs_fs.h2
-rw-r--r--man/Makefile.am2
-rw-r--r--man/f2fslabel.833
5 files changed, 116 insertions, 1 deletions
diff --git a/fsck/Makefile.am b/fsck/Makefile.am
index e7d599c..e31d416 100644
--- a/fsck/Makefile.am
+++ b/fsck/Makefile.am
@@ -18,3 +18,4 @@ install-data-hook:
ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/defrag.f2fs
ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/resize.f2fs
ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/sload.f2fs
+ ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/f2fslabel
diff --git a/fsck/main.c b/fsck/main.c
index 64efa87..f42ab0c 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -155,6 +155,14 @@ void sload_usage()
exit(1);
}
+void label_usage()
+{
+ MSG(0, "\nUsage: f2fslabel [options] device [volume-label]\n");
+ MSG(0, "[options]:\n");
+ MSG(0, " -V print the version number and exit\n");
+ exit(1);
+}
+
static int is_digits(char *optarg)
{
unsigned int i;
@@ -177,6 +185,8 @@ static void error_out(char *prog)
resize_usage();
else if (!strcmp("sload.f2fs", prog))
sload_usage();
+ else if (!strcmp("f2fslabel", prog))
+ label_usage();
else
MSG(0, "\nWrong program.\n");
}
@@ -722,6 +732,39 @@ void f2fs_parse_options(int argc, char *argv[])
}
}
#endif /* WITH_SLOAD */
+ } else if (!strcmp("f2fslabel", prog)) {
+#ifdef WITH_LABEL
+ const char *option_string = "V";
+
+ c.func = LABEL;
+ while ((option = getopt(argc, argv, option_string)) != EOF) {
+ switch (option) {
+ case 'V':
+ show_version(prog);
+ exit(0);
+ default:
+ err = EUNKNOWN_OPT;
+ break;
+ }
+ if (err != NOERROR)
+ break;
+ }
+
+ if (argc > (optind + 2)) { /* unknown argument(s) is(are) passed */
+ optind += 2;
+ err = EUNKNOWN_ARG;
+ } else if (argc == (optind + 2)) { /* change label */
+ c.vol_label = argv[optind + 1];
+ argc--;
+ } else { /* print label */
+ /*
+ * Since vol_label was initialized as "", in order to
+ * distinguish between clear label and print, set
+ * vol_label as NULL for print case
+ */
+ c.vol_label = NULL;
+ }
+#endif /* WITH_LABEL */
}
if (err == NOERROR) {
@@ -971,6 +1014,36 @@ static int do_sload(struct f2fs_sb_info *sbi)
}
#endif
+#ifdef WITH_LABEL
+static int do_label(struct f2fs_sb_info *sbi)
+{
+ struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
+
+ if (!c.vol_label) {
+ char label[MAX_VOLUME_NAME];
+
+ utf16_to_utf8(label, sb->volume_name,
+ MAX_VOLUME_NAME, MAX_VOLUME_NAME);
+ MSG(0, "Info: volume label = %s\n", label);
+ return 0;
+ }
+
+ if (strlen(c.vol_label) > MAX_VOLUME_NAME) {
+ ERR_MSG("Label should not exceed %d characters\n", MAX_VOLUME_NAME);
+ return -1;
+ }
+
+ utf8_to_utf16(sb->volume_name, (const char *)c.vol_label,
+ MAX_VOLUME_NAME, strlen(c.vol_label));
+
+ update_superblock(sb, SB_MASK_ALL);
+
+ MSG(0, "Info: volume label is changed to %s\n", c.vol_label);
+
+ return 0;
+}
+#endif
+
#if defined(__APPLE__)
static u64 get_boottime_ns()
{
@@ -1085,6 +1158,12 @@ fsck_again:
c.fix_on = 1;
goto fsck_again;
#endif
+#ifdef WITH_LABEL
+ case LABEL:
+ if (do_label(sbi))
+ goto out_err;
+ break;
+#endif
default:
ERR_MSG("Wrong program name\n");
ASSERT(0);
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index cdcce2c..5d49ed1 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -35,6 +35,7 @@
#define WITH_DEFRAG
#define WITH_RESIZE
#define WITH_SLOAD
+#define WITH_LABEL
#endif
#include <inttypes.h>
@@ -343,6 +344,7 @@ enum f2fs_config_func {
DEFRAG,
RESIZE,
SLOAD,
+ LABEL,
};
enum default_set {
diff --git a/man/Makefile.am b/man/Makefile.am
index 1d16c6f..9363b82 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -1,3 +1,3 @@
## Makefile.am
-dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8 f2fs_io.8
+dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8 f2fs_io.8 f2fslabel.8
diff --git a/man/f2fslabel.8 b/man/f2fslabel.8
new file mode 100644
index 0000000..848ed3b
--- /dev/null
+++ b/man/f2fslabel.8
@@ -0,0 +1,33 @@
+.\" Copyright (c) 2021 Samsung Electronics Co., Ltd.
+.\"
+.TH F2FSLABEL 8
+.SH NAME
+f2fslabel \- Change the label on an f2fs volume
+.SH SYNOPSIS
+.B f2fslabel
+.I device
+[
+.I volume-label
+]
+.SH DESCRIPTION
+.B f2fslabel
+will display or change the volume label on the f2fs located on
+.I device.
+.PP
+If the optional argument
+.I volume-label
+is present, then
+.B f2fslabel
+will set the volume label to be
+.IR volume-label .
+.PP
+Otherwise,
+.B f2fslabel
+will simply show the current label.
+.PP
+.SH AUTHOR
+.B f2fslabel
+was written by Dongwoo Lee (dwoo08.lee@samsung.com).
+.SH AVAILABILITY
+.B f2fslabel
+is available from git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git.