Patch - btrfslabel program
Subsystems (2)
I'm new and just getting starting on the source code and figured I would start by working on some of the utility programs. So here is my first addition a program called btrfslabel which works pretty much just like e2label. It currently doesn't work on a mounted filesystem and I will look at that next.
Thanks,
Morey
Makefile +0 -0
@@ -4,7 +4,7 @@
objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ root-tree.o dir-item.o hash.o file-item.o inode-item.o \ inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \
- volumes.o utils.o
+ volumes.o sanity-checks.o utils.o
#
CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
-Wuninitialized -Wshadow -Wundef
@@ -15,7 +15,7 @@
bindir = $(prefix)/bin
LIBS=-luuid
-progs = btrfsctl btrfsck mkfs.btrfs debug-tree btrfs-show btrfs-vol +progs = btrfsctl btrfsck mkfs.btrfs debug-tree btrfs-show btrfs-vol btrfslabel
# make C=1 to enable sparse ifdef C @@ -45,6 +45,9 @@
btrfsck: $(objects) btrfsck.o bit-radix.o
gcc $(CFLAGS) -o btrfsck btrfsck.o $(objects) bit-radix.o $(LDFLAGS) $(LIBS)
+
+btrfslabel: $(objects) btrfslabel.o
+ gcc $(CFLAGS) -o btrfslabel btrfslabel.o $(objects) $(LDFLAGS) $(LIBS)
mkfs.btrfs: $(objects) mkfs.o
gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
btrfslabel.c new file +179 -0
179 lines not on this page · raw message
mkfs.c +0 -0
@@ -42,6 +42,7 @@
#include "transaction.h"
#include "utils.h"
#include "version.h"
+#include "sanity-checks.h"
static u64 parse_size(char *s)
{
@@ -246,6 +247,7 @@
fprintf(stderr, "options:\n"); fprintf(stderr, "\t -b --byte-count total number of bytes in the FS\n"); fprintf(stderr, "\t -l --leafsize size of btree leaves\n"); + fprintf(stderr, "\t -L --label of the filesystem\n"); fprintf(stderr, "\t -n --nodesize size of btree leaves\n"); fprintf(stderr, "\t -s --sectorsize min block allocation\n"); fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
@@ -271,20 +273,19 @@
static char *parse_label(char *input)
{
- int i;
- int len = strlen(input);
+ int check_val = check_label(input);
- if (len > BTRFS_LABEL_SIZE) {
+ if (check_val == -1) {
fprintf(stderr, "Label %s is too long (max %d)\n", input,
BTRFS_LABEL_SIZE);
exit(1);
}- for (i = 0; i < len; i++) {
- if (input[i] == '/' || input[i] == '\\') {
- fprintf(stderr, "invalid label %s\n", input);
- exit(1);
- }
+
+ if (check_val == -2) {
+ fprintf(stderr, "invalid label %s\n", input);
+ exit(1); } + return strdup(input); }
sanity-checks.c new file +46 -0
46 lines not on this page · raw message
sanity-checks.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (C) 2008 Morey Roof. 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 v2 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. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +*/ + +#ifndef __SANITY_CHECKS__ +#define __SANITY_CHECKS__ + +int check_label (char *input); + +#endif /* __SANITY_CHECKS__ */
utils.c +0 -0
@@ -572,7 +572,7 @@
}
/*
- * returns 1 if the device was mounted, < 0 on error or 0 if everything
+ * returns 1 if the device is mounted, < 0 on error or 0 if everything
* is safe to continue. TODO, this should also scan multi-device filesystems */
int check_mounted(char *file)
Quoted 5 lines · Morey Roof
I'm new and just getting starting on the source code and figured I would start by working on some of the utility programs. So here is my first addition a program called btrfslabel which works pretty much just like e2label. It currently doesn't work on a mounted filesystem and I will look at that next.
Neat, thanks. Could you please move the santiy-checks code into utils.[ch]?
You'll just need to add an ioctl to change the label on a mounted FS.
-chris