summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorGoffredo Baroncelli <kreijack@inwind.it>2010-12-05 17:46:44 +0000
committerChris Mason <chris.mason@oracle.com>2011-10-25 09:18:31 -0400
commite8f47cf068c3a4b5de7770ebb9eef37e28e09ef7 (patch)
treefbf620453d16c5dd3dbd048556accd48ebabace2 /utils.c
parent002d021c5f2d838394e850e304546ffad283518a (diff)
Add the "btrfs filesystem label" command
Hi all, this patch adds the command "btrfs filesystem label" to change (or show) the label of a filesystem. This patch is a subset of the one written previously by Morey Roof. I included the user space part only. So it is possible only to change/show a label of a *single device* and *unounted* filesystem. The reason of excluding the kernel space part, is to simplify the patch in order to speed the check and then the merging of the patch itself. In fact I have to point out that in the past there was almost three attempts to propose this patch, without success neither complaints. Chris, let me know how you want to proceed. I know that you are very busy, and you prefer to work to stabilize btrfs instead adding new feature. But I think that changing a label is a *essential* feature for a filesystem managing tool. Think about a mount by LABEL. To show a label $ btrfs filesystem label <device> To set a label $ btrfs filesystem label <device> <newlabel> Please guys, give a look to the source. Comments are welcome. You can pull the source from the branch "label" of the repository http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git Regards G.Baroncelli Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index ad980aed..13373c99 100644
--- a/utils.c
+++ b/utils.c
@@ -812,6 +812,39 @@ out_mntloop_err:
return ret;
}
+/* Gets the mount point of btrfs filesystem that is using the specified device.
+ * Returns 0 is everything is good, <0 if we have an error.
+ * TODO: Fix this fucntion and check_mounted to work with multiple drive BTRFS
+ * setups.
+ */
+int get_mountpt(char *dev, char *mntpt, size_t size)
+{
+ struct mntent *mnt;
+ FILE *f;
+ int ret = 0;
+
+ f = setmntent("/proc/mounts", "r");
+ if (f == NULL)
+ return -errno;
+
+ while ((mnt = getmntent(f)) != NULL )
+ {
+ if (strcmp(dev, mnt->mnt_fsname) == 0)
+ {
+ strncpy(mntpt, mnt->mnt_dir, size);
+ break;
+ }
+ }
+
+ if (mnt == NULL)
+ {
+ /* We didn't find an entry so lets report an error */
+ ret = -1;
+ }
+
+ return ret;
+}
+
struct pending_dir {
struct list_head list;
char name[256];
@@ -1002,3 +1035,27 @@ char *pretty_sizes(u64 size)
return pretty;
}
+/*
+ * Checks to make sure that the label matches our requirements.
+ * Returns:
+ 0 if everything is safe and usable
+ -1 if the label is too long
+ -2 if the label contains an invalid character
+ */
+int check_label(char *input)
+{
+ int i;
+ int len = strlen(input);
+
+ if (len > BTRFS_LABEL_SIZE) {
+ return -1;
+ }
+
+ for (i = 0; i < len; i++) {
+ if (input[i] == '/' || input[i] == '\\') {
+ return -2;
+ }
+ }
+
+ return 0;
+}