All Projects → knorrie → Python Btrfs

knorrie / Python Btrfs

Licence: lgpl-3.0
Python Btrfs module

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Python Btrfs

Janus
Janus: a state-of-the-art file system fuzzer on Linux
Stars: ✭ 139 (+93.06%)
Mutual labels:  btrfs, filesystem
Backup And Recovery Howtos
Guides to setting up a media storage system, backing it up, and recovering from failures
Stars: ✭ 235 (+226.39%)
Mutual labels:  btrfs, filesystem
arch-btrfs-install-guide
Arch Linux installation guide with btrfs and snapper, this guide is based on the information from unicks.eu guide https://www.youtube.com/watch?v=TKdZiCTh3EM, and Arch Linux UEFI step-by-step installation guide https://www.youtube.com/watch?v=dOXYZ8hKdmc from ALU.
Stars: ✭ 32 (-55.56%)
Mutual labels:  filesystem, btrfs
Glusterfs Java Filesystem
GlusterFS for Java
Stars: ✭ 50 (-30.56%)
Mutual labels:  filesystem
F2fs Notes
F2FS的学习笔记以及源码分析。这个github的分析都是初版,CSDN的版本是经过修改的,应该逻辑更为通畅,建议去CSDN进行阅读,连接如下。
Stars: ✭ 56 (-22.22%)
Mutual labels:  filesystem
Linux Apfs
APFS module for linux, with experimental write support. This tree is just for development, please use linux-apfs-oot instead.
Stars: ✭ 63 (-12.5%)
Mutual labels:  filesystem
Onedrive Fuse Fs
Script to mount Microsoft OneDrive (formerly known as SkyDrive) folder as a FUSE filesystem
Stars: ✭ 68 (-5.56%)
Mutual labels:  filesystem
Flysystem Backblaze
💿 A backblaze adapter which can be used with flysystem(http://flysystem.thephpleague.com/)
Stars: ✭ 49 (-31.94%)
Mutual labels:  filesystem
Hardware
The devices I have, what runs on them, their configurations, issues, solutions, and associated projects
Stars: ✭ 67 (-6.94%)
Mutual labels:  btrfs
Mkinitcpio Systemd Tool
Provisioning tool for systemd in initramfs (systemd-tool)
Stars: ✭ 60 (-16.67%)
Mutual labels:  btrfs
Browser Shell
A Linux command-line shell in the browser
Stars: ✭ 60 (-16.67%)
Mutual labels:  filesystem
30daysofnode
30 days of node is a code base tutorial series for node.js which deals with providing a practical project based learning experience instead of talking about its conceptual details.
Stars: ✭ 57 (-20.83%)
Mutual labels:  filesystem
Notify
🔭 Cross-platform filesystem notification library for Rust.
Stars: ✭ 1,123 (+1459.72%)
Mutual labels:  filesystem
Cords
File-system fault injection framework for distributed storage systems
Stars: ✭ 55 (-23.61%)
Mutual labels:  filesystem
Includedir
Include a whole directory tree at compile time
Stars: ✭ 67 (-6.94%)
Mutual labels:  filesystem
Btdu
sampling disk usage profiler for btrfs
Stars: ✭ 50 (-30.56%)
Mutual labels:  btrfs
Raspi Overlayroot
Protect your SD card against wear and tear
Stars: ✭ 66 (-8.33%)
Mutual labels:  filesystem
Win10 Explorer
A new windows 10 file explorer
Stars: ✭ 58 (-19.44%)
Mutual labels:  filesystem
Linux Apfs Oot
APFS module for linux (out-of-tree repository)
Stars: ✭ 58 (-19.44%)
Mutual labels:  filesystem
Fsq
A tool for querying the file system with a SQL-like language.
Stars: ✭ 60 (-16.67%)
Mutual labels:  filesystem

python-btrfs

What is python-btrfs?

python-btrfs is a Python 3 library that provides ways to interact programmatically with an online btrfs file system.

It provides a pure python shadow implementation of data structures used in btrfs together with convenient wrappers around the collection of kernel functions that are available in the btrfs kernel API.

Using them, we can examine the secret inner world of a btrfs file system for educational purposes.

Where do I get it?

Your favourite GNU/Linux distro probably has it packaged as either python-btrfs or python3-btrfs package.

This git repository with source code can also directly be used with python 3. No dependencies other than the python standard library are needed.

Should I be using this?

The target audience for using the library is system administrators and developers who want to discover more about the internals of a btrfs file system, or want to create adjusted monitoring or administration tools that are optimized for their specific use cases.

Of course, it's python, so, this is for who prefers programming python over programming C for quickly building fun stuff.

I have a broken file system, can I repair it using python-btrfs?

python-btrfs does not directly access disk storage, it only uses functions available in the kernel interface, using system calls. This also means that python-btrfs can not be used to repair a broken filesystem whenever the running Linux kernel cannot properly mount it.

What can I do with python-btrfs?

Using it allows one to take a peek behind the curtains of the regular functionality provided by the btrfs-progs programs and the libbtrfsutil C and Python library.

You can basically do anything that btrfs-progs or libbtrfsutil can do with an online file system. However, at the same time we're operating on a bit lower abstraction level. However again, that allows us to also be creative and make optimized utilities for our own special use cases.

An example is the btrfs-balance-least-used program that you can find in the bin directory. It's a modified algorithm for using btrfs balance to compact allocated space (i.e. defragment free space) as fast and efficient as possible by taking the usage ratio of the individual allocations of raw disk space into account.

Show me some example code!

Let's for example have a look at the equivalent of the btrfs fi df / command:

>>> import btrfs
>>> with btrfs.FileSystem('/') as fs:
...     for space in fs.space_info():
...         print(space)
... 
Data, single: total=839.01GiB, used=838.47GiB
System, DUP: total=8.00MiB, used=112.00KiB
Metadata, DUP: total=4.00GiB, used=2.38GiB
GlobalReserve, single: total=512.00MiB, used=0.00B

Well, that was easy! But, say, instead of this text, you want to create a pie chart out of it. Now, instead of writing a horrible program that parses back the text output of the btrfs fi df command, we can access the values directly.

>>> spaces = fs.space_info()
>>> len(spaces)
4

The space_info() function calls the FS_INFO kernel function, which returns a list of SpaceInfo objects. By feeding one of those to the pretty printer in the utils module, we can see all contents. The attributes are directly accessible in our code:

>>> btrfs.utils.pretty_print(spaces[0])
<btrfs.ioctl.SpaceInfo>
flags: Data, single
total_bytes: 839.01GiB
used_bytes: 838.50GiB

>>> spaces[0].flags
1
>>> btrfs.utils.block_group_flags_str(spaces[0].flags)
'DATA'
>>> spaces[0].total_bytes
900877778944

So, using these values, we could create a nice picture using an imaging library.

More examples!

The bin and examples directory in the source code contain an example collection of programs that are built using the library.

Documentation

Reference documentation of the stable API of the library is written in Sphinx autodoc format. An online version of the HTML documentation is also available.

In general, the btrfs.FileSystem object, shown above, is the best starting point for exploring available functionality.

Tutorial style documentation will be added in the future.

License

The python-btrfs library itself is licensed under the LGPL-3.0.

Example scripts in the bin directory are licensed under the MIT License (Expat). Feel free to use all the ideas and code from them to build new stuff using python-btrfs!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].