Skip to contentSkip to conversation

File test operator for subvols; possible bug in 'btrfs show <directory>'

DISCUSSION boris 4 participants 4 messages Nov 25, 2014 – Nov 27, 2014 Btrfs file system

lore
Share & tools
lore

boris

author
#0 lore raw

Hi all,

I was looking for a quick method of testing whether a working directory is a subvolume.

Couldn't see an obvious one, so tried 'btrfs show <somesubvol≥'. It printed a fail message as expected but returned 0 exit status. Bug?

Can I put in a feature request for a shell file test operator for subvols, please (or something of the kind)? http://tldp.org/LDP/abs/html/fto.html . The letter v (for volume, both upper and lower case forms; one for subvol, other for snapshots) is unused afaict.

Have I missed the obvious? Or scored a false positive?

TIA.

#1 lore raw
Quoted 7 lines · boris

Hi all,

I was looking for a quick method of testing whether a working directory is a subvolume.

Couldn't see an obvious one, so tried 'btrfs show <somesubvol≥'. It printed a fail message as expected but returned 0 exit status. Bug?

Hi boris,

I take a quick look at the code branch and I think it is a Bug indeed. THe code just forgot to set the proper return value before leave out.

To test whether a dir is a subvolume, what about

	# btrfs sub list | grep <dirname>
as 'btrfs sub list will list all subvolumes under <mntpoint>.
The dirname should be relative path under <mntpoint> is as I could
remember.

Thanks,
Gui

Quoted 13 lines

Can I put in a feature request for a shell file test operator for subvols, please (or something of the kind)? http://tldp.org/LDP/abs/html/fto.html . The letter v (for volume, both upper and lower case forms; one for subvol, other for snapshots) is unused afaict.

Have I missed the obvious? Or scored a false positive?

TIA.

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

#2 lore raw
In reply to boris
Quoted 4 lines · boris

Hi all,

I was looking for a quick method of testing whether a working directory is a subvolume.

Currently btrfs check that:
- the inode number is 255
- the path is a directory

Quoted 1 line

From cmds-subvolume.c

[...]
/*
* test if path is a subvolume:
* this function return
* 0-> path exists but it is not a subvolume
* 1-> path exists and it is a subvolume
* -1 -> path is unaccessible
*/
int test_issubvolume(char *path)

{
        struct stat     st;
        int             res;

        res = stat(path, &st);
        if(res < 0 )
                return -1;

        return (st.st_ino == 256) && S_ISDIR(st.st_mode);
}

[---]

Quoted 18 lines

Couldn't see an obvious one, so tried 'btrfs show <somesubvol≥'. It printed a fail message as expected but returned 0 exit status. Bug?

Can I put in a feature request for a shell file test operator for subvols, please (or something of the kind)? http://tldp.org/LDP/abs/html/fto.html . The letter v (for volume, both upper and lower case forms; one for subvol, other for snapshots) is unused afaict.

Have I missed the obvious? Or scored a false positive?

TIA.

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

Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
#3 lore raw
Quoted 8 lines · Goffredo Baroncelli
Quoted 4 lines · boris

Hi all,

I was looking for a quick method of testing whether a working directory is a subvolume.

Currently btrfs check that:
- the inode number is 255

It's 256.

Quoted 1 line
        return (st.st_ino == 256) && S_ISDIR(st.st_mode);

The shell test to identify a subvolume is

[ -d "$dir" -a stat --format=%i "$dir" = 256