btrfs-progs fix wrong memory free on check_is_root

When "/" is Btrfs, "btrfs property <subcommand> /" regards it
as non-root by mistake.

check_is_root() regards @object as a file system root if
the following two conditions are satisfied.

 a) Both @object and its parent directory are Btrfs object
    (file system root, subvolume, inode, and device
    used for Btrfs).
 b) fsid of the above mentioned two objects are different.

It doesn't work if @object is "/" because, in this case,
fsid of "/" and its parent (it's also "/"), are the same.

* Test environment

Two Btrfs file system (not subvolume) "/" and "/home/sat/mnt".

* How to reproduce

Submit "btrfs prop get" against the above mentioned file systems.

* Test Result

** Actual result (without my patch)

==========================
ro=false
label=                 # label is displayed because it's a file system root
ro=false               # label is not displayed even if it's a file system root
==========================
** Expected result (with my patch)

==========================
ro=false
label=
ro=false
label=foo            # label is displayed
===========================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Reported-by: Naohiro Aota <naota@elisp.net>
Reviewed-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Satoru Takeuchi 2014-12-18 16:39:26 +09:00 committed by David Sterba
parent fb7ddc498f
commit 44d3ee3e1f
1 changed files with 13 additions and 1 deletions

View File

@ -124,7 +124,18 @@ static int check_is_root(const char *object)
int ret; int ret;
u8 fsid[BTRFS_FSID_SIZE]; u8 fsid[BTRFS_FSID_SIZE];
u8 fsid2[BTRFS_FSID_SIZE]; u8 fsid2[BTRFS_FSID_SIZE];
char *tmp; char *tmp = NULL;
char *rp;
rp = realpath(object, NULL);
if (!rp) {
ret = -errno;
goto out;
}
if (!strcmp(rp, "/")) {
ret = 0;
goto out;
}
tmp = malloc(strlen(object) + 5); tmp = malloc(strlen(object) + 5);
if (!tmp) { if (!tmp) {
@ -165,6 +176,7 @@ static int check_is_root(const char *object)
out: out:
free(tmp); free(tmp);
free(rp);
return ret; return ret;
} }