linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* File test operator for subvols; possible bug in 'btrfs show <directory>'
@ 2014-11-25  2:11 boris
  2014-11-25  5:33 ` Gui Hecheng
  2014-11-25  7:32 ` Goffredo Baroncelli
  0 siblings, 2 replies; 4+ messages in thread
From: boris @ 2014-11-25  2:11 UTC (permalink / raw)
  To: linux-btrfs

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: File test operator for subvols; possible bug in 'btrfs show <directory>'
  2014-11-25  2:11 File test operator for subvols; possible bug in 'btrfs show <directory>' boris
@ 2014-11-25  5:33 ` Gui Hecheng
  2014-11-25  7:32 ` Goffredo Baroncelli
  1 sibling, 0 replies; 4+ messages in thread
From: Gui Hecheng @ 2014-11-25  5:33 UTC (permalink / raw)
  To: boris; +Cc: linux-btrfs

On Tue, 2014-11-25 at 02:11 +0000, boris wrote:
> 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

> 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: File test operator for subvols; possible bug in 'btrfs show <directory>'
  2014-11-25  2:11 File test operator for subvols; possible bug in 'btrfs show <directory>' boris
  2014-11-25  5:33 ` Gui Hecheng
@ 2014-11-25  7:32 ` Goffredo Baroncelli
  2014-11-27 17:21   ` David Sterba
  1 sibling, 1 reply; 4+ messages in thread
From: Goffredo Baroncelli @ 2014-11-25  7:32 UTC (permalink / raw)
  To: boris; +Cc: linux-btrfs

On 11/25/2014 03:11 AM, boris wrote:
> 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

>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);
}
[---]
> 
> 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: File test operator for subvols; possible bug in 'btrfs show <directory>'
  2014-11-25  7:32 ` Goffredo Baroncelli
@ 2014-11-27 17:21   ` David Sterba
  0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2014-11-27 17:21 UTC (permalink / raw)
  To: Goffredo Baroncelli; +Cc: boris, linux-btrfs

On Tue, Nov 25, 2014 at 08:32:36AM +0100, Goffredo Baroncelli wrote:
> On 11/25/2014 03:11 AM, boris wrote:
> > 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.

>         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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-11-27 17:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-25  2:11 File test operator for subvols; possible bug in 'btrfs show <directory>' boris
2014-11-25  5:33 ` Gui Hecheng
2014-11-25  7:32 ` Goffredo Baroncelli
2014-11-27 17:21   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).