From: Chao Yu <chao@kernel.org>
To: Dongwoo Lee <dwoo08.lee@samsung.com>,
linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v2] tools: Introduce f2fslabel
Date: Thu, 20 May 2021 19:26:19 +0800 [thread overview]
Message-ID: <d8a50e74-be7e-3242-c3af-2fc6b8ad10b8@kernel.org> (raw)
In-Reply-To: <20210512090842.162973-1-dwoo08.lee@samsung.com>
On 2021/5/12 17:08, Dongwoo Lee wrote:
> 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>
> ---
>
> Changes in v2:
> - Integrated into fsck/main.c instead of individual tool
>
> fsck/Makefile.am | 1 +
> fsck/main.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++
> include/f2fs_fs.h | 2 ++
> man/Makefile.am | 2 +-
> man/f2fslabel.8 | 33 ++++++++++++++++++++
> 5 files changed, 116 insertions(+), 1 deletion(-)
> create mode 100644 man/f2fslabel.8
>
> 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..6a9668a 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 = strdup(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);
It needs to free c.vol_label here?
Thanks,
> +
> + return 0;
> +}
> +#endif
> +
> #if defined(__APPLE__)
> static u64 get_boottime_ns()
> {
> @@ -1084,6 +1157,12 @@ fsck_again:
> c.func = FSCK;
> 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");
> 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.
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2021-05-20 11:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20210512090846epcas1p1c19254a0f25b579c697a497fe94f68ad@epcas1p1.samsung.com>
2021-05-12 9:08 ` [f2fs-dev] [PATCH v2] tools: Introduce f2fslabel Dongwoo Lee
2021-05-20 11:26 ` Chao Yu [this message]
2021-05-21 3:19 ` Dongwoo Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d8a50e74-be7e-3242-c3af-2fc6b8ad10b8@kernel.org \
--to=chao@kernel.org \
--cc=dwoo08.lee@samsung.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).