News for hackers. Stuff that matters.
Re:Petit Fat File System Module by howerj on Tuesday October 13, 2020 @01:36PM (#24767795)
I have noticed there are quite a few FAT-32 implementations out there, but none that do what I want. Ideally what I want is something that would do the following; allow the creation of a new FAT-32 image file of a specified length given a target directory.

The program (or programs/scripts) must be command line driven and run under both Windows and Linux (so they can be integrated into our build system).

The use case is the following; the creation of a single binary image containing some firmware and a (per-unit) custom FAT-32 partition, both of which would effectively concatenated together.

Does anyone have any ideas? Otherwise I might have to make something myself.

Re:Petit Fat File System Module by a1369209993 on Tuesday October 13, 2020 @03:56PM (#24769628)
> allow the creation of a new FAT-32 image file of a specified length given a target directory [emphasis added]

I think that's your problem: file systems are supposed to go onto a preexisting block device, which you'll need to create seperately. For example, on my system:

  dd if=/dev/zero of=/tmp/foo.dos bs=512 count=128K
  mkdosfs -F 32 /tmp/foo.dos
Once you've created the filesystem, fill it with:

  mkdir /tmp/foo/
  sudo mount -t msdos -o loop /tmp/foo.dos /tmp/foo/
  # dump stuff into /tmp/foo/
  sudo umount /tmp/foo.dos # or /tmp/foo/
  # filesystem is in /tmp/foo.dos
Re:Petit Fat File System Module by koolba on Tuesday October 13, 2020 @01:41PM (#24767846)
I can’t speak for Windows, but on any *nix OS you can do this with a loop back device. You’d have to determining in advance and likely round up a bit. But it’s a literally a couple line shell script.
Re:Petit Fat File System Module by shawnz on Tuesday October 13, 2020 @02:34PM (#24768565)
On Windows you could create and mount a VHD file and format it as FAT32 by using the diskpart utility, with the commands "create vdisk", "attach vdisk", and "format"
Re:Petit Fat File System Module by howerj on Tuesday October 13, 2020 @01:49PM (#24767913)
Yeah, it is easy to do, but only on Unixen, the dev environment I am working on is primarily run under Windows (and also maybe Linux in the future).
Re:Petit Fat File System Module by m463 on Tuesday October 13, 2020 @02:06PM (#24768069)
WSL / WSL2 might be one answer
Re:Petit Fat File System Module by ptspts on Tuesday October 13, 2020 @01:40PM (#24767837)
mtools, containing the mformat and mcopy tools.
Re:Petit Fat File System Module by jaclaz on Tuesday October 13, 2020 @01:50PM (#24767928)
+1

The mtools/mformat are not AFAIK released pre-built for Windows, in case of need here is a build:

http://reboot.pro/topic/14354-buidlingmodifying-floppy-image...

Syntax/option for mformat are a bit complex, again in case of need here is a small batch that hopefuly makes commands clearer:

http://reboot.pro/topic/21664-makeiso/page-4#entry205455

Re:Petit Fat File System Module by any1 on Tuesday October 13, 2020 @03:07PM (#24769029)
There's also genimage [1] which uses mtools for FAT, but it can also do ext2 and more.

[1] https://github.com/pengutronix/genimage

Re:Petit Fat File System Module by howerj on Tuesday October 13, 2020 @01:47PM (#24767897)
That looks like it might work, thank you. My search did not find this.
Re:Petit Fat File System Module by sgtnoodle on Tuesday October 13, 2020 @10:44PM (#24772613)
You could use the non-petit version of this FAT library to do all the image twiddling from userspace, without having to rely on any kernel support. The only trick then would be compiling the code to run on windows. If you already support that in your build system, then great.

Otherwise, you could try to find a suitable FAT implementation written in a cross platform language like python.

Otherwise you're looking at some fairly nasty scripting to get windows to do the FAT filesystem manipulation for you. As far as I know, windows doesn't support loopback devices out of the box for example.

Do you really need a baked FAT32 filesystem? Could you get away with a simpler payload like a tar?

Re:Petit Fat File System Module by kevin_thibedeau on Tuesday October 13, 2020 @05:57PM (#24770798)
You can adapt FatFS to do this. You just have to implement a few low level I/O routines to work using an conventional file as a fake block device.