fuse byteswapping

General Discussion, STOS.
foft
Posts: 342
Joined: 28 Mar 2022 12:20

fuse byteswapping

Post by foft »

I'm trying to get access to my Falcon compact flash nicely from Linux.

I see that there is kind of partial support...

So I can use:

Code: Select all

dd if=/dev/sdc of=somewhere/sdc conv=swab
... to copy the contents and byte swap it.

Usually I could then use kpartx to make devices for each partition, but it doesn't seem to support the Atari partitions. Neither does fdisk. However parted does and Irek Pelech wrote a wrapper script to make/mount loop devices using parted and losetup. https://www.seniorlinuxadmin.co.uk/atari-fs.html.

So this is pretty good, I can access C:. But its painfully slow to copy out and back the data. So I made a simple python fuse script to help with this using fusepy - shared in attachment.

Code: Select all

mkdir -p dev_swapped
python byteswapfs.py /dev/ dev_swapped &
parted dev_swapped/sdc -- print
Then you can directly modify the compact flash.

The problem I have now is mounting with vfat is not working for my large partitions. So I can read/write C:, but not D: or E:. This also happened with dd, so its not a fuse issue...
You do not have the required permissions to view the files attached to this post.
User avatar
Badwolf
Site sponsor
Site sponsor
Posts: 3043
Joined: 19 Nov 2019 12:09

Re: fuse byteswapping

Post by Badwolf »

foft wrote: 03 Jan 2023 21:40 I'm trying to get access to my Falcon compact flash nicely from Linux.
So this is pretty good, I can access C:. But its painfully slow to copy out and back the data. So I made a simple python fuse script to help with this using fusepy - shared in attachment.
Ooo. This looks great.

So this is a plugin to fuse that byte swaps the entire /dev directory?

I'll have to give this a try when I get a minute.

Does partprobe(8) work on this swapped directory?

When I do the dd conv=swab thing you do linux will happily identify all the partitions on my loopback device (/dev/loop0p0...p6 etc), but if this shortcuts that process you're correct it'll be a massive speed boost.

BW
DFB1 Open source 50MHz 030 and TT-RAM accelerator for the Falcon
Smalliermouse ST-optimised USB mouse adapter based on SmallyMouse2
FrontBench The Frontier: Elite 2 intro as a benchmark
foft
Posts: 342
Joined: 28 Mar 2022 12:20

Re: fuse byteswapping

Post by foft »

Yes exactly.

It’s a very simple fuse filesystem, just overriding read and write to byte swap. It also makes it appear like a usual file since fusepy doesn’t support character devices.

I’m not sure about partprobe, if it doesn’t work perhaps I should try cusepy to expose a true character device. Or a byteswapping kernel module…

I’m also wondering about handling the fat file system too, there is a python fat implementation.
User avatar
Badwolf
Site sponsor
Site sponsor
Posts: 3043
Joined: 19 Nov 2019 12:09

Re: fuse byteswapping

Post by Badwolf »

foft wrote: 04 Jan 2023 10:52 Yes exactly.

It’s a very simple fuse filesystem, just overriding read and write to byte swap. It also makes it appear like a usual file since fusepy doesn’t support character devices.
I had in the past thought about looking at the loopback device driver and seeing if byteswapping could be implemented in that. I had thought fuse would be too 'high up' the stack, but it sounds like it might be just the ticket.

BW
DFB1 Open source 50MHz 030 and TT-RAM accelerator for the Falcon
Smalliermouse ST-optimised USB mouse adapter based on SmallyMouse2
FrontBench The Frontier: Elite 2 intro as a benchmark
foft
Posts: 342
Joined: 28 Mar 2022 12:20

Re: fuse byteswapping

Post by foft »

One thing to be cautious of about losetup, is that the sector size is a parameter on the command! The correct sector size needs to be set in order that the fat tools work properly. For example mkfs.vfat -A on /dev/loopN doesn't work for large partitions without an appropriate sector size set with losetup!

It's a bit chicken and egg... mkfs chooses the sector size, but I need it to run losetup to run mkfs.

This is probably why I couldn't mount my large Atari partitions properly via losetup...

I might make fuse expose the partitions as files, that can be mounted with mount -o.

Additionally... losetup -b 32768 doesn't even work! Also I can't event mount -o something large that I just made with mkfs.vfat -A...

----
ok got it...
mkfs.vfat -A uses the sector size from losetup
losetup can have a max sector size of 4k
mount -t vfat can't mount over 4k sectors (at least of a loop device)
mkfs.vfat -A of over 256MB uses 8K sector sizes
foft
Posts: 342
Joined: 28 Mar 2022 12:20

Re: fuse byteswapping

Post by foft »

Hmmm, I wonder if we can just change this to increase that 4096 to 32768 and it'd work for large Atari partitions?:
https://github.com/torvalds/linux/blob/ ... at/inode.c

Code: Select all

	if (!is_power_of_2(bpb->fat_sector_size)
	    || (bpb->fat_sector_size < 512)
	    || (bpb->fat_sector_size > 4096)) {
		if (!silent)
			fat_msg(sb, KERN_ERR, "bogus logical sector size %u",
			       (unsigned)bpb->fat_sector_size);
		goto out;
	}
foft
Posts: 342
Joined: 28 Mar 2022 12:20

Re: fuse byteswapping

Post by foft »

Unfortunately when changing that (to 16384, not 32768 btw...) it then fails on amd64 with the block size. This seems to have a maximum of the kernel pagesize, which on amd64 is 4KB...

Code: Select all

>getconf PAGESIZE
4096
In set_blocksize in block/bdev.c

Code: Select all

if (size > PAGE_SIZE ...)
    return -EINVAL
'unable to set block size 8192'

Plan B:
https://github.com/virtualsquare/fusefatfs
(doesn't work out the box, hard configured to sector size 512)

P.S. Yes I know I can just use Hatari, but... :D

Update: Seems all this is known since like at least a decade or two.
This is a great document: http://info-coach.fr/atari/documents/_m ... _Guide.pdf
Perhaps I should write a full fuse filesystem rather than trying to use vfat.

Return to “SOFTWARE”

Who is online

Users browsing this forum: ClaudeBot and 0 guests