diff mbox series

btrfs-progs: change filename limit to 255 when creating subvolume

Message ID 20180912073903.10134-1-suyj.fnst@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: change filename limit to 255 when creating subvolume | expand

Commit Message

Su Yanjun Sept. 12, 2018, 7:39 a.m. UTC
Modify the file name length limit to meet the Linux naming convention. 
In addition, the file name length is always bigger than 0, no need to 
compare with 0 again.

Issue: #145
Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
---
 cmds-subvolume.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba Sept. 14, 2018, 2:34 p.m. UTC | #1
On Wed, Sep 12, 2018 at 03:39:03PM +0800, Su Yanjun wrote:
> Modify the file name length limit to meet the Linux naming convention. 
> In addition, the file name length is always bigger than 0, no need to 
> compare with 0 again.
> 
> Issue: #145
> Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>

Looks good, please send a test, thanks. You can copy portions of the
misc-tests/014-filesystem-label that does similar string length check
for the label.
Su Yanjun Sept. 17, 2018, 3:19 a.m. UTC | #2
On 9/14/2018 10:34 PM, David Sterba wrote:
> On Wed, Sep 12, 2018 at 03:39:03PM +0800, Su Yanjun wrote:
>> Modify the file name length limit to meet the Linux naming convention.
>> In addition, the file name length is always bigger than 0, no need to
>> compare with 0 again.
>>
>> Issue: #145
>> Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
> Looks good, please send a test, thanks. You can copy portions of the
> misc-tests/014-filesystem-label that does similar string length check
> for the label.

The following is the tests for the patch.

[suyj@sarch tests]$ vim misc-tests-results.txt
=== START TEST 
/home/suyj/btrfs-progs/tests//misc-tests/033-filename-length-limit
$TEST_DEV not given, using /home/suyj/btrfs-progs/tests//test.img as 
fallback
====== RUN CHECK /home/suyj/btrfs-progs/mkfs.btrfs -L BTRFS-TEST-LABEL 
-f /home/suyj/btrfs-progs/tests//test.img
btrfs-progs v4.17.1
See http://btrfs.wiki.kernel.org for more information.

Label:              BTRFS-TEST-LABEL
UUID:               925425a2-5557-4dea-93d3-3b4543707082
Node size:          16384
Sector size:        4096
Filesystem size:    2.00GiB
Block group profiles:
   Data:             single            8.00MiB
   Metadata:         DUP             102.38MiB
   System:           DUP               8.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata
Number of devices:  1
Devices:
    ID        SIZE  PATH
     1     2.00GiB  /home/suyj/btrfs-progs/tests//test.img

====== RUN CHECK root_helper mount -t btrfs -o loop 
/home/suyj/btrfs-progs/tests//test.img /home/suyj/btrfs-progs/tests//mnt
====== RUN CHECK root_helper chmod a+rw /home/suyj/btrfs-progs/tests//mnt
====== RUN CHECK root_helper /home/suyj/btrfs-progs/btrfs subvolume 
create aaa
Create subvolume './aaa'
====== RUN CHECK root_helper /home/suyj/btrfs-progs/btrfs subvolume 
create 
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
Create subvolume 
'./012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'
====== RUN MUSTFAIL root_helper /home/suyj/btrfs-progs/btrfs subvolume 
create 
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
ERROR: cannot access 
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345: 
File name too long
failed (expected): root_helper /home/suyj/btrfs-progs/btrfs subvolume 
create 
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
====== RUN MUSTFAIL root_helper /home/suyj/btrfs-progs/btrfs subvolume 
create 
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
ERROR: cannot access 
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234: 
File name too long
failed (expected): root_helper /home/suyj/btrfs-progs/btrfs subvolume 
create 
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
diff mbox series

Patch

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index e7a884af..fe97fca3 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -715,7 +715,7 @@  static int cmd_subvol_snapshot(int argc, char **argv)
 	}
 
 	len = strlen(newname);
-	if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
+	if (len > BTRFS_VOL_NAME_MAX) {
 		error("snapshot name too long '%s'", newname);
 		goto out;
 	}