Skip to main content

Raw block-level read/write of exFAT filesystem timestamps (birth time, modification time)

Project description

exfat-raw

PyPI version Python License OS

CI codecov

Downloads total Downloads/month Downloads/week

Raw block-level read/write of exFAT filesystem timestamps — birth time (btime) and modification time (mtime), directly from the on-disk directory entry, bypassing the kernel driver's cache.

Features

  • Read btime/mtime — parse the exFAT directory entry on the raw block device
  • Write btime and mtime — atomically update both timestamps in one raw-block access
  • 3-tier I/O fallback — tries direct os.pread/os.pwrite first (works on regular image files and accessible block devices), then loop device backing files, and finally falls back to sudo dd for restricted block devices
  • No kernel cache corruption — understands the exFAT kernel driver's directory-entry cache incoherence and avoids os.utime() / sync() after raw writes
  • Pure stdlib — zero runtime dependencies

Usage

from exfat_raw import ExfatRawIO, ExfatRawFilesystem, ExfatRawOps
from datetime import datetime, timezone

io = ExfatRawIO()
fs = ExfatRawFilesystem(io)
ops = ExfatRawOps(io, fs)

# Read birth time from a file on an exFAT mount
ts = ops.read_btime_raw("/mnt/sdcard/DCIM/100GOPRO/GH010001.MP4")
print(datetime.fromtimestamp(ts, tz=timezone.utc))

# Correct the timestamp
target = datetime(2025, 6, 15, 12, 0, 0, tzinfo=timezone.utc)
ops.fix_exfat_raw("/mnt/sdcard/DCIM/100GOPRO/GH010001.MP4", target, dry_run=False)

# Preserve btime while updating mtime
orig_btime_ts = ops.read_btime_raw(filepath)
orig_btime_dt = datetime.fromtimestamp(orig_btime_ts, tz=timezone.utc)
ops.fix_exfat_raw(filepath, new_mtime_dt, dry_run=False, btime_dt=orig_btime_dt)

# Work directly on a raw image file (no sudo, no mount)
io = ExfatRawIO()
fs = ExfatRawFilesystem(io)
boot = io.parse_boot("path/to/sdcard.img")
chain = fs.cluster_chain(boot, "path/to/sdcard.img", boot["root_cluster"])

Note: All datetime parameters must be timezone-aware (e.g., tzinfo=timezone.utc). Naive datetimes are rejected with ValueError.

Dependencies

  • Python ≥ 3.10 (stdlib only — os, struct, subprocess, tempfile, pathlib)
  • System tools: sudo, dd, findmnt, losetup — only needed for physical block devices; regular image files work with stdlib alone

License

GNU General Public License v3.0 or later.


Development

Running tests

Sandbox-safe (no sudo, no mount — runs a pure-Python exFAT image):

python -m unittest discover -s tests -p 'test_exfat_raw_image.py' -v

Full suite (requires sudo + loop device + exfat-fuse):

python -m unittest discover -s tests -p 'test_*.py' -v

With Nix:

nix develop                   # enter dev shell
python -m unittest discover -s tests -p 'test_*.py' -v

The Nix package's checkPhase runs only the sandbox-safe tests (see nix/exfat-raw/default.nix).


Extracted from gopro-timestamp-corrector.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exfat_raw-0.2.0.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exfat_raw-0.2.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file exfat_raw-0.2.0.tar.gz.

File metadata

  • Download URL: exfat_raw-0.2.0.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for exfat_raw-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5b1d15f58965fdf0807fd9b7ec69d239b06de8bcd9b3802a8f442d7eff3e8190
MD5 6af1b62f560eb2d8ad96cea831be925b
BLAKE2b-256 2b149491c6771ba125969b99c0dec12cbdde693ba227a5b4760317cc0d6fff86

See more details on using hashes here.

Provenance

The following attestation bundles were made for exfat_raw-0.2.0.tar.gz:

Publisher: publish.yml on MBanucu/exfat-raw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exfat_raw-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: exfat_raw-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for exfat_raw-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e632160ff896bece2908ed270ee9d707779304fc8c708c767b7783d3f947f078
MD5 0ac6a7682bc6a86c69703558a2b92d0b
BLAKE2b-256 7878633c3fb9007f60671db682f9c1291fab051d4f34933b748106bf3802c22f

See more details on using hashes here.

Provenance

The following attestation bundles were made for exfat_raw-0.2.0-py3-none-any.whl:

Publisher: publish.yml on MBanucu/exfat-raw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page