Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Pierre Couderc <pierre@couderc.eu>, linux-btrfs@vger.kernel.org
Subject: Re: Is there some doc or some example of libbtrfs ?
Date: Fri, 7 Aug 2020 13:17:58 +0300	[thread overview]
Message-ID: <4700f999-7914-0453-7096-f2ca360b4be7@suse.com> (raw)
In-Reply-To: <4bf44e81-0b4f-9c99-3010-410e110aec2d@couderc.eu>



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
> 

  reply	other threads:[~2020-08-07 10:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-07  9:36 Is there some doc or some example of libbtrfs ? Pierre Couderc
2020-08-07 10:17 ` Nikolay Borisov [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4700f999-7914-0453-7096-f2ca360b4be7@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=pierre@couderc.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox