Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light-weight test for FAT validity of a given file object #42

Open
mxmlnkn opened this issue Sep 15, 2024 · 0 comments
Open

Light-weight test for FAT validity of a given file object #42

mxmlnkn opened this issue Sep 15, 2024 · 0 comments

Comments

@mxmlnkn
Copy link

mxmlnkn commented Sep 15, 2024

As mentioned in #41, I am trying to use this project via FUSE. The current work in progress works quite fine already.

Bash script to test the work-in-progress state.
# Would be nice to have this without sudo, but I don't want to create test cases with the same program being tested.
head -c $(( 1024 * 1024 )) /dev/zero > 'folder-symlink.fat'
mkfs.fat 'folder-symlink.fat'
mkdir mounted
sudo mount 'folder-symlink.fat' mounted
cd mounted
sudo mkdir -p foo/fighter
echo bar | sudo tee > foo/fighter/ufo
sudo umount mounted

python3 -m pip install --user --force-reinstall \
    'git+https://github.com/mxmlnkn/ratarmount.git@fat#egginfo=ratarmountcore&subdirectory=core' \
    'git+https://github.com/mxmlnkn/ratarmount.git@fat#egginfo=ratarmount'

ratarmount folder-symlink.fat mounted
tree mounted
# mounted/
# └── foo
#     └── fighter
#         └── ufo
# 
# 2 directories, 1 file

However, for integration, I need a isFATImage function that can relatively quickly check a given bytes file object whether it is a FAT file / image. Normally, these check functions would only require checking the first 2-10 bytes, depending on the file format, but for FAT it is probably not all that easy. Currently, I call private functions of pyfatfs to achieve something like this:

fs = PyFat.PyFat()
fs._PyFat__set_fp(fileObject)
fs.is_read_only = True
try:
    fs.parse_header()
    return True
except pyfatfs.PyFATException:
    return False
finally:
    # Reset file object so that it does not get closed! Cannot be None because that is checked.
    fs._PyFat__fp = io.BytesIO()

It would be nice to have some officially supported way to do something like this. I am not sure whether _parse_fat, in addition to parse_header, should be included in such a check. It depends a bit on how much it checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant