https://github.com/superfly/fsmap
Go module to list free block ranges on Linux filesystems by calling the `GETFSMAP` ioctl.
https://github.com/superfly/fsmap
Last synced: 3 months ago
JSON representation
Go module to list free block ranges on Linux filesystems by calling the `GETFSMAP` ioctl.
- Host: GitHub
- URL: https://github.com/superfly/fsmap
- Owner: superfly
- License: apache-2.0
- Created: 2024-07-18T20:06:46.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-18T20:55:38.000Z (11 months ago)
- Last Synced: 2025-03-07T01:18:44.985Z (3 months ago)
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fsmap
Go module to list free block ranges on Linux filesystems by calling the [`GETFSMAP` ioctl](https://man7.org/linux/man-pages/man2/ioctl_getfsmap.2.html).
Works with a raw block device containing a mountable ext4 filesystem (which it will temporarily mount), or an already-mounted filesystem.## Example
```shell
$ go get github.com/superfly/fsmap
``````go
package mainimport "github.com/superfly/fsmap"
import "os"func main() {
file, _ := os.Open(os.Args[1])
entries, _ := fsmap.GetFreeBlocks(file)
free, total := 0, 0
for _, entry := range entries {
println(entry.Physical, "(", entry.Length, "bytes)")
free += int(entry.Length)
total = int(entry.Physical + entry.Length)
}
println("Total free:", int(float64(free)/float64(total)*100),"%")
}
``````shell
$ fallocate -l 1G file &&
mkfs.ext4 -qF file &&
mkdir -p mount &&
sudo mount -ro loop file mount# mountpoint argument
$ sudo ./fsmap-test mount
17395712 ( 116822016 bytes)
134746112 ( 267907072 bytes)
403181568 ( 133689344 bytes)
570425344 ( 100663296 bytes)
671617024 ( 267907072 bytes)
940052480 ( 133689344 bytes)
Total free: 95 %# block device argument
$ sudo ./fsmap-test $(losetup -j file | cut -d: -f1)
Free space at: 17395712 116822016
Free space at: 134746112 267907072
Free space at: 403181568 133689344
Free space at: 570425344 100663296
Free space at: 671617024 267907072
Free space at: 940052480 133689344
Total free: 95 %
```