diff mbox

[1/2] btrfs-progs: refactor check_label()

Message ID 51076B0C.2060602@oracle.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

jeff.liu Jan. 29, 2013, 6:24 a.m. UTC
Refactor check_label().

Make it be static at first, this is a preparation step since we'll remove
btrfslabel.[c|h] and move those functions at them to utils.[c|h], we can do
pre-checking against the input label string with it.

Also, fix the input lable length verfication from BTRFS_LABEL_SIZE to
BTRFS_LABEL_SIZE - 1.

Signed-off-by: Jie Liu <jeff.liu@oracle.com>
CC: David Sterba <dsterba@suse.cz>
CC: Gene Czarcinski <gene@czarc.net>
---
 utils.c |    8 ++++++--
 utils.h |    1 -
 2 files changed, 6 insertions(+), 3 deletions(-)

Comments

David Sterba Jan. 29, 2013, 3:19 p.m. UTC | #1
On Tue, Jan 29, 2013 at 02:24:12PM +0800, Jeff Liu wrote:
> --- a/utils.c
> +++ b/utils.c
> @@ -1122,17 +1122,21 @@ char *pretty_sizes(u64 size)
>        -1    if the label is too long
>        -2    if the label contains an invalid character
>   */
> -int check_label(char *input)
> +static int check_label(char *input)
>  {
>         int i;
>         int len = strlen(input);
>  
> -       if (len > BTRFS_LABEL_SIZE) {
> +       if (len > BTRFS_LABEL_SIZE - 1) {
> +		fprintf(stderr, "ERROR: Label %s is too long (max %d)\n",
> +			input, BTRFS_LABEL_SIZE - 1);
>                 return -1;
>         }
>  
>         for (i = 0; i < len; i++) {
>                 if (input[i] == '/' || input[i] == '\\') {
> +			fprintf(stderr, "ERROR: Label %s contains invalid "
> +				"characters\n", input);
>                         return -2;
>                 }

Plase drop this check, see
http://repo.or.cz/w/btrfs-progs-unstable/devel.git/commit/79e0e445fc2365e47fc7f060d5a4445d37e184b8
(also function comment and maybe the callers)

"btrfs-progs: kill check for /'s in labels

This patch kills a check in mkfs's label stuff which doesn't allow
labels that have /'s in them.  This causes problems for Anaconda which
try to label volumes with their mountpoints."
(mkfs.c)

thanks,
david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
jeff.liu Jan. 29, 2013, 4:52 p.m. UTC | #2
On 01/29/2013 11:19 PM, David Sterba wrote:
> On Tue, Jan 29, 2013 at 02:24:12PM +0800, Jeff Liu wrote:
>> --- a/utils.c
>> +++ b/utils.c
>> @@ -1122,17 +1122,21 @@ char *pretty_sizes(u64 size)
>>        -1    if the label is too long
>>        -2    if the label contains an invalid character
>>   */
>> -int check_label(char *input)
>> +static int check_label(char *input)
>>  {
>>         int i;
>>         int len = strlen(input);
>>  
>> -       if (len > BTRFS_LABEL_SIZE) {
>> +       if (len > BTRFS_LABEL_SIZE - 1) {
>> +		fprintf(stderr, "ERROR: Label %s is too long (max %d)\n",
>> +			input, BTRFS_LABEL_SIZE - 1);
>>                 return -1;
>>         }
>>  
>>         for (i = 0; i < len; i++) {
>>                 if (input[i] == '/' || input[i] == '\\') {
>> +			fprintf(stderr, "ERROR: Label %s contains invalid "
>> +				"characters\n", input);
>>                         return -2;
>>                 }
> 
> Plase drop this check, see
> http://repo.or.cz/w/btrfs-progs-unstable/devel.git/commit/79e0e445fc2365e47fc7f060d5a4445d37e184b8
> (also function comment and maybe the callers)
> 
> "btrfs-progs: kill check for /'s in labels
> 
> This patch kills a check in mkfs's label stuff which doesn't allow
> labels that have /'s in them.  This causes problems for Anaconda which
> try to label volumes with their mountpoints."
> (mkfs.c)
Ok, so looks we can safely clean this routine out of the code base since
there is no other users call it if am not missing anything.

Thanks,
-Jeff

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/utils.c b/utils.c
index d59bca3..034da8f 100644
--- a/utils.c
+++ b/utils.c
@@ -1122,17 +1122,21 @@  char *pretty_sizes(u64 size)
       -1    if the label is too long
       -2    if the label contains an invalid character
  */
-int check_label(char *input)
+static int check_label(char *input)
 {
        int i;
        int len = strlen(input);
 
-       if (len > BTRFS_LABEL_SIZE) {
+       if (len > BTRFS_LABEL_SIZE - 1) {
+		fprintf(stderr, "ERROR: Label %s is too long (max %d)\n",
+			input, BTRFS_LABEL_SIZE - 1);
                return -1;
        }
 
        for (i = 0; i < len; i++) {
                if (input[i] == '/' || input[i] == '\\') {
+			fprintf(stderr, "ERROR: Label %s contains invalid "
+				"characters\n", input);
                        return -2;
                }
        }
diff --git a/utils.h b/utils.h
index 8750f28..a0b782b 100644
--- a/utils.h
+++ b/utils.h
@@ -42,7 +42,6 @@  int check_mounted_where(int fd, const char *file, char *where, int size,
 int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
 				 int super_offset);
 char *pretty_sizes(u64 size);
-int check_label(char *input);
 int get_mountpt(char *dev, char *mntpt, size_t size);
 
 int btrfs_scan_block_devices(int run_ioctl);