]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/label.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018 Red Hat, Inc. All Rights Reserved.
7 #include "platform_defs.h"
14 #ifndef FS_IOC_GETFSLABEL
15 /* Max chars for the interface; fs limits may differ */
16 #define FSLABEL_MAX 256
17 #define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX])
18 #define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX])
21 static cmdinfo_t label_cmd
;
28 " Manipulate or query the filesystem label while mounted.\n"
30 " With no arguments, displays the current filesystem label.\n"
31 " -s newlabel -- set the filesystem label to newlabel\n"
32 " -c -- clear the filesystem label (sets to NULL string)\n"
43 char label
[FSLABEL_MAX
+ 1];
46 memset(label
, 0, sizeof(label
));
47 error
= ioctl(file
->fd
, FS_IOC_GETFSLABEL
, &label
);
51 while ((c
= getopt(argc
, argv
, "cs:")) != EOF
) {
57 if (strlen(optarg
) > FSLABEL_MAX
) {
62 strncpy(label
, optarg
, sizeof(label
) - 1);
63 label
[sizeof(label
) - 1] = 0;
66 return command_usage(&label_cmd
);
70 /* Check for trailing arguments */
72 return command_usage(&label_cmd
);
74 error
= ioctl(file
->fd
, FS_IOC_SETFSLABEL
, label
);
80 printf("label = \"%s\"\n", label
);
89 label_cmd
.name
= "label";
90 label_cmd
.cfunc
= label_f
;
93 label_cmd
.args
= _("[-s label|-c]");
94 label_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
96 _("query, set, or clear the filesystem label while mounted");
97 label_cmd
.help
= label_help
;
99 add_command(&label_cmd
);