All of lore.kernel.org
 help / color / mirror / Atom feed
* Is there some doc or some example of libbtrfs ?
@ 2020-08-07  9:36 Pierre Couderc
  2020-08-07 10:17 ` Nikolay Borisov
  2020-08-10 15:13 ` David Sterba
  0 siblings, 2 replies; 6+ messages in thread
From: Pierre Couderc @ 2020-08-07  9:36 UTC (permalink / raw)
  To: linux-btrfs

Ho do I get programmatically the list of the snapshots of a volume in C/C++?

I can analyse the output of "btrfs li sh", but is there an easier way ?

I have found no doc or example...

Thanks

PC


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

* Re: Is there some doc or some example of libbtrfs ?
  2020-08-07  9:36 Is there some doc or some example of libbtrfs ? Pierre Couderc
@ 2020-08-07 10:17 ` Nikolay Borisov
  2020-08-07 10:38   ` Pierre Couderc
  2020-08-07 15:20   ` Pierre Couderc
  2020-08-10 15:13 ` David Sterba
  1 sibling, 2 replies; 6+ messages in thread
From: Nikolay Borisov @ 2020-08-07 10:17 UTC (permalink / raw)
  To: Pierre Couderc, linux-btrfs



On 7.08.20 г. 12:36 ч., Pierre Couderc wrote:
> Ho do I get programmatically the list of the snapshots of a volume in
> C/C++?
> 
> I can analyse the output of "btrfs li sh", but is there an easier way ?
> 
> I have found no doc or example...

Well, the example is in the source code of btrfs-progs, namely :

btrfs_list_subvols_print
 list_subvol_search

TLDR You'd have to use the TREE_SEARCH ioctl which allows you to get
data from btrfs' various trees. In order to figure out what data to pass
to  the ioctl you'd have to familiarize yourself with the internal
structure of btrfs trees to know which items represent a snapshot and
which proper subvolumes. You should check the "ROOT ITEM" description at
https://github.com/btrfs/btrfs-dev-docs/blob/master/tree-items.txt to
see when a root item is a snapshot and not a subvolume.

> 
> Thanks
> 
> PC
> 

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

* Re: Is there some doc or some example of libbtrfs ?
  2020-08-07 10:17 ` Nikolay Borisov
@ 2020-08-07 10:38   ` Pierre Couderc
  2020-08-07 15:20   ` Pierre Couderc
  1 sibling, 0 replies; 6+ messages in thread
From: Pierre Couderc @ 2020-08-07 10:38 UTC (permalink / raw)
  To: linux-btrfs


On 8/7/20 12:17 PM, Nikolay Borisov wrote:
>
> On 7.08.20 г. 12:36 ч., Pierre Couderc wrote:
>> Ho do I get programmatically the list of the snapshots of a volume in
>> C/C++?
>>
>>
>> Well, the example is in the source code of btrfs-progs, namely :
>>
>> btrfs_list_subvols_print
>>   list_subvol_search
>>
>> TLDR You'd have to use the TREE_SEARCH ioctl which allows you to get
>> data from btrfs' various trees. In order to figure out what data to pass
>> to  the ioctl you'd have to familiarize yourself with the internal
>> structure of btrfs trees to know which items represent a snapshot and
>> which proper subvolumes. You should check the "ROOT ITEM" description at
>> https://github.com/btrfs/btrfs-dev-docs/blob/master/tree-items.txt to
>> see when a root item is a snapshot and not a subvolume.
>>
Thank you, you are the light in the dark..

I start on that.

PC

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

* Re: Is there some doc or some example of libbtrfs ?
  2020-08-07 10:17 ` Nikolay Borisov
  2020-08-07 10:38   ` Pierre Couderc
@ 2020-08-07 15:20   ` Pierre Couderc
  1 sibling, 0 replies; 6+ messages in thread
From: Pierre Couderc @ 2020-08-07 15:20 UTC (permalink / raw)
  To: linux-btrfs


On 8/7/20 12:17 PM, Nikolay Borisov wrote:
>
> On 7.08.20 г. 12:36 ч., Pierre Couderc wrote:
>> Ho do I get programmatically btrfs xxxxx....?
>>
> Well, the example is in the source code of btrfs-progs, namely :
>
> btrfs_list_subvols_print
>   list_subvol_search
>
> TLDR You'd have to use the TREE_SEARCH ioctl which allows you to get
> data from btrfs' various trees. In order to figure out what data to pass
> to  the ioctl you'd have to familiarize yourself with the internal
> structure of btrfs trees to know which items represent a snapshot and
> which proper subvolumes. You should check the "ROOT ITEM" description at
> https://github.com/btrfs/btrfs-dev-docs/blob/master/tree-items.txt to
> see when a root item is a snapshot and not a subvolume.
>
A small tip for the next one :

To understand how and where some function is called (here 
btrfs_list_subvols_print), grep in in "cmds" subdirectory (here 
logically subvolume.c).


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

* Re: Is there some doc or some example of libbtrfs ?
  2020-08-07  9:36 Is there some doc or some example of libbtrfs ? Pierre Couderc
  2020-08-07 10:17 ` Nikolay Borisov
@ 2020-08-10 15:13 ` David Sterba
  2020-08-10 16:02   ` Pierre Couderc
  1 sibling, 1 reply; 6+ messages in thread
From: David Sterba @ 2020-08-10 15:13 UTC (permalink / raw)
  To: Pierre Couderc; +Cc: linux-btrfs

On Fri, Aug 07, 2020 at 11:36:10AM +0200, Pierre Couderc wrote:
> Ho do I get programmatically the list of the snapshots of a volume in C/C++?
> 
> I can analyse the output of "btrfs li sh", but is there an easier way ?
> 
> I have found no doc or example...

Please don't use libbtrfs, that's going to be removed in the future.
There's a proper library libbtrfsutil. See
btrfs_util_create_subvolume_iterator.

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

* Re: Is there some doc or some example of libbtrfs ?
  2020-08-10 15:13 ` David Sterba
@ 2020-08-10 16:02   ` Pierre Couderc
  0 siblings, 0 replies; 6+ messages in thread
From: Pierre Couderc @ 2020-08-10 16:02 UTC (permalink / raw)
  To: dsterba, linux-btrfs

On 8/10/20 5:13 PM, David Sterba wrote:
> On Fri, Aug 07, 2020 at 11:36:10AM +0200, Pierre Couderc wrote:
>> Ho do I get programmatically the list of the snapshots of a volume in C/C++?
>>
>> I can analyse the output of "btrfs li sh", but is there an easier way ?
>>
>> I have found no doc or example...
> Please don't use libbtrfs, that's going to be removed in the future.
> There's a proper library libbtrfsutil. See
> btrfs_util_create_subvolume_iterator.

ok I note that. Thnak you.



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

end of thread, other threads:[~2020-08-10 16:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07  9:36 Is there some doc or some example of libbtrfs ? Pierre Couderc
2020-08-07 10:17 ` Nikolay Borisov
2020-08-07 10:38   ` Pierre Couderc
2020-08-07 15:20   ` Pierre Couderc
2020-08-10 15:13 ` David Sterba
2020-08-10 16:02   ` Pierre Couderc

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.