forked from mikael-lovqvist/fa2json
Compare commits
2 Commits
850d2ceb75
...
f8aed56faf
| Author | SHA1 | Date | |
|---|---|---|---|
| f8aed56faf | |||
| c7c46dc15d |
82
test/Manual experiment.md
Normal file
82
test/Manual experiment.md
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
## Manual experiment
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This manual experiment shows how we can do the testing (teardown not included). Note that we don't need the `losetup`-stuff, we know where everything is.
|
||||||
|
|
||||||
|
### Compile
|
||||||
|
```sh
|
||||||
|
gcc fs-watcher.c json-writer.c -o fa2json
|
||||||
|
```
|
||||||
|
### Create image file
|
||||||
|
```sh
|
||||||
|
mktemp /tmp/fa2json-test-XXXXXX.img
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
/tmp/fa2json-test-UrwpOb.img
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
truncate -s 10M /tmp/fa2json-test-UrwpOb.img
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mkfs.ext4 /tmp/fa2json-test-UrwpOb.img
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
mke2fs 1.47.3 (8-Jul-2025)
|
||||||
|
Discarding device blocks: done
|
||||||
|
Creating filesystem with 10240 1k blocks and 2560 inodes
|
||||||
|
Filesystem UUID: 035c508e-dec0-4a21-a4d1-1efb6fa72415
|
||||||
|
Superblock backups stored on blocks:
|
||||||
|
8193
|
||||||
|
|
||||||
|
Allocating group tables: done
|
||||||
|
Writing inode tables: done
|
||||||
|
Creating journal (1024 blocks): done
|
||||||
|
Writing superblocks and filesystem accounting information: done
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Create mount point
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mktemp -d /tmp/fa2json-mnt-XXXXXX
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
/tmp/fa2json-mnt-ts2Dik
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mount loop device
|
||||||
|
```sh
|
||||||
|
sudo mount /tmp/fa2json-test-UrwpOb.img /tmp/fa2json-mnt-ts2Dik/
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> In a different terminal I now ran - but we could do this after `chown` or possibly `chown` + `sync`?
|
||||||
|
> ```sh
|
||||||
|
> fa2json /tmp/fa2json-mnt-ts2Dik
|
||||||
|
> ```
|
||||||
|
|
||||||
|
### Let current user own file system
|
||||||
|
```sh
|
||||||
|
sudo chown $(id -u) /tmp/fa2json-mnt-ts2Dik/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `fa2json` output
|
||||||
|
```json
|
||||||
|
{"ts": [1772658052, 704412412, 386988, 865842867], "name": "/tmp/fa2json-mnt-ts2Dik/.", "mask": 1073741828}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Touch marker
|
||||||
|
```sh
|
||||||
|
touch /tmp/fa2json-mnt-ts2Dik/MARKER
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `fa2json` output
|
||||||
|
```json
|
||||||
|
{"ts": [1772658064, 151070715, 387000, 312501190], "name": "/tmp/fa2json-mnt-ts2Dik/MARKER", "mask": 256}
|
||||||
|
{"ts": [1772658064, 151099105, 387000, 312529600], "name": "/tmp/fa2json-mnt-ts2Dik/MARKER", "mask": 12}
|
||||||
|
```
|
||||||
24
test/PLAN.md
24
test/PLAN.md
@@ -21,15 +21,20 @@ Requires root (`fanotify` FID reporting and `mount` both need `CAP_SYS_ADMIN`).
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. Create a temporary image file (`mktemp`)
|
1. Create a temporary image file (`mktemp /tmp/fa2json-test-XXXXXX.img`)
|
||||||
2. `dd` 10M of zeros into it
|
2. `truncate -s 10M` the image (sparse file, no need for `dd`)
|
||||||
3. `mkfs.ext4` the image
|
3. `mkfs.ext4` the image
|
||||||
4. `losetup --find --show` to attach it as a loop device
|
4. Create a temporary mount directory (`mktemp -d /tmp/fa2json-mnt-XXXXXX`)
|
||||||
5. `mount` the loop device to a temporary directory (`mktemp -d`)
|
5. `sudo mount <img> <mntdir>` (no `losetup` needed — `mount` accepts image files directly)
|
||||||
6. Spawn `fa2json <mountpoint>` as a child process
|
6. `sudo chown $(id -u) <mntdir>` to hand ownership to the current user
|
||||||
7. Attach a `readline` interface to its stdout; parse each line as JSON and
|
7. `sync` to flush before fa2json starts listening
|
||||||
|
8. `sudo` spawn `fa2json <mountpoint>` as a child process (needs `CAP_SYS_ADMIN`)
|
||||||
|
9. Attach a `readline` interface to its stdout; parse each line as JSON and
|
||||||
push into an event buffer
|
push into an event buffer
|
||||||
|
|
||||||
|
Steps 6 and 7 ensure the `chown` event never enters the fa2json stream, and
|
||||||
|
all subsequent FS operations run unprivileged.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Teardown
|
## Teardown
|
||||||
@@ -37,10 +42,9 @@ Requires root (`fanotify` FID reporting and `mount` both need `CAP_SYS_ADMIN`).
|
|||||||
Runs unconditionally in a `finally` block:
|
Runs unconditionally in a `finally` block:
|
||||||
|
|
||||||
1. Kill the `fa2json` child process
|
1. Kill the `fa2json` child process
|
||||||
2. `umount <mountpoint>`
|
2. `sudo umount <mountpoint>`
|
||||||
3. `losetup -d <loopdev>`
|
3. `rm` the image file
|
||||||
4. `rm` the image file
|
4. `rmdir` the mount directory
|
||||||
5. `rmdir` the mount directory
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user