https://github.com/grisp/edifa
Erlang Disk and Image File Abstraction Library
https://github.com/grisp/edifa
Last synced: 11 months ago
JSON representation
Erlang Disk and Image File Abstraction Library
- Host: GitHub
- URL: https://github.com/grisp/edifa
- Owner: grisp
- License: apache-2.0
- Created: 2024-08-22T22:35:28.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-30T12:46:28.000Z (almost 2 years ago)
- Last Synced: 2024-09-07T14:50:17.555Z (almost 2 years ago)
- Language: Erlang
- Size: 97.7 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# edifa
Erlang Disk and Image File Abstraction Library
Library to create system images without root privilege on both Linux and MacOS.
## Build
$ rebar3 compile
## Runtime Dependencies
### MacOS
Commands that must be available:
- rm
- mv
- mkdir
- dd
- mktemp
- gzip
- hdiutil
- fdisk
- diskutil
- newfs_msdos
### Linux
Commands that must be available:
- rm
- mv
- mkdir
- dd
- mktemp
- gzip
- id
- sfdisk
- fusefat
- fusermount
- mkfs.vfat
Install dependencies:
sudo apt-get install coreutils fdisk fusefat dosfstools gzip
## Usage
Create an image file (64 MiB):
```erlang
{ok, Img} = edifa:create("test.img", 64 * 1024 * 1024).
```
Write some bootloader (2 MiB):
```erlang
ok = edifa:write(Img, "bootloader.bin", #{count => 2 * 1024 * 1024}).
```
Create partitions:
```erlang
{ok, P1, P2} = edifa:partition(Img, mbr, [
#{type => fat32, size => 31 * 1024 * 1024, start => 2 * 1024 * 1024},
#{type => fat32, size => 31 * 1024 * 1024}
]).
```
Format partition 1:
```erlang
ok = edifa:format(Img, P1, fat, #{label => "foobar"}).
```
Mount partition 1:
```erlang
{ok, MountPoint} = edifa:mount(Img, P1).
```
Create some files in partition 1 filesystem:
```erlang
ok = file:write_file(filename:join(MountPoint, "test.txt"), <<"some data\n">>).
```
Unmount partition 1:
```erlang
ok = edifa:unmount(Img, P1).
```
Extract partition 1 into its own file:
```erlang
ok = edifa:extract(Img, P1, "system.fs").
```
Generate a tuncated disk image containing the reserved space before the first
partition with the bootloader and the partition definition, and partition 1:
```erlang
ok = edifa:extract(Img, reserved, P1, "disk.img").
```
Extract into a gziped file:
Close the image:
```erlang
ok = edifa:close(Img).
```
```erlang
ok = edifa:extract(Img, P2, P2, "system.fs.gz").
```
## Limitations
- All partitions involved must be unmounted before extracting data.
- Only support MBR partition tables for now.
- Active/Bootable partition flag is not supported yet.
- Only support FAT filesystem for now.