Page 1 of 1
Homemade tool to write data from file to disk image
Posted: Thu Mar 07, 2013 5:07 pm
by Luis
Hi,
As I didn't find any simple tool to write a bootloader or some other data to disk images for Bochs or something, I made my own. Comes in handy while I don't have file system and user space properly implemented. It just takes a file and writes it (fully or not) to an image made by bximage from Bochs, etc at a given offset.
I just put it here in case anyone finds it useful and to get some feedfack because I didn't test it extensively so please report bugs.
Windows x64 cmd app
Cheers,
Luís
Re: Homemade tool to write data from file to disk image
Posted: Thu Mar 07, 2013 5:25 pm
by Combuster
There's this
stock tool that many people here use for that purpose. Comes with both msys and cygwin for windows users, and has the additional feature that it's not strictly limited to disk images.
Re: Homemade tool to write data from file to disk image
Posted: Thu Mar 07, 2013 6:29 pm
by Luis
I've seen it but I can't use it because I don't have disk space for cygwin and besides I never liked to use cygwin, I prefer the real Linux which I can't have at the moment. Thanks anyway
Re: Homemade tool to write data from file to disk image
Posted: Thu Mar 07, 2013 11:28 pm
by dozniak
Luis wrote:because I don't have disk space for cygwin
When I had a 85Mb IBM hard drive in my PS/1 machine there was just enough space for the stripped-down copy of Windows 95, Borland C++ 3.1 compiler and IDE and a few small-ish DOS games.
Re: Homemade tool to write data from file to disk image
Posted: Fri Mar 08, 2013 2:13 am
by Antti
I also wrote a simple tool that does everything I need. Currently I use it to make disk images with proper file systems. It can combine files and make modifications at any offsets. The tool takes input line by line and it can be used directly by typing "commands" or redirecting commands from so called script files.
Example script file (script.txt):
Code: Select all
# Comments are allowed
. = 16 # Offset is zero by default but can be changed
=some/path/file.bin # Include this file here (offset is incremented accordingly)
# Edit the beginning of the file
. = 16 # Set offset again
S$ "ABCD" # S$ is for strings
4$ 0x10 # Little endian 4byte
4$ 0x10, 4, 0x2 # Three little endian 4bytes
4$B 0x10 # Big endiand 4byte
4$L 0x10 # Explicit little endian 4byte (same as without 'L')
1.5$ 1,2,3,4 # Four 1.5 bytes (used for FAT 12, always little endian)
D$ SOME_DEFINE # Use builtin define ("SOME_DEFINE" is not available)
. = 0x1000 # Set offset again
=some/path/another.bin # Include this file here (offset is incremented accordingly)
Usage:
Code: Select all
Usage: ./Collector <file size>
Example: ./Collector 0x8000 < script.txt > final.img
Of course there are drawbacks and I do not claim it is a perfect tool. However, I really like it.
Source Code for Collector
Script for creating an ISO 9660 El Torito CD
Re: Homemade tool to write data from file to disk image
Posted: Fri Mar 22, 2013 1:10 pm
by Mikemk
Antti wrote:
Code: Select all
# Comments are allowed
. = 16 # Offset is zero by default but can be changed
=some/path/file.bin # Include this file here (offset is incremented accordingly)
# Edit the beginning of the file
. = 16 # Set offset again
S$ "ABCD" # S$ is for strings
4$ 0x10 # Little endian 4byte
4$ 0x10, 4, 0x2 # Three little endian 4bytes
4$B 0x10 # Big endiand 4byte
4$L 0x10 # Explicit little endian 4byte (same as without 'L')
1.5$ 1,2,3,4 # Four 1.5 bytes (used for FAT 12, always little endian)
D$ SOME_DEFINE # Use builtin define ("SOME_DEFINE" is not available)
. = 0x1000 # Set offset again
=some/path/another.bin # Include this file here (offset is incremented accordingly)
looks like a cross between assembly and a linker script
Re: Homemade tool to write data from file to disk image
Posted: Thu Mar 28, 2013 6:22 am
by bubach
partcopy.exe is quite common amongst os-developers on windows.
Re: Homemade tool to write data from file to disk image
Posted: Fri Mar 29, 2013 4:48 pm
by Mikemk
I just use flat images.
Re: Homemade tool to write data from file to disk image
Posted: Fri Mar 29, 2013 6:17 pm
by Love4Boobies
bubach wrote:partcopy.exe is quite common amongst os-developers on windows.
Is it? I don't know anyone to actually use it, only that it came up a few years ago on #osdev due to some tutorial. I remember that the problem (s)he encountered turned out to be a limitation in the utility---it choked on files exceeding some rather small size. That means it is only useful for floppy disk images (which no one seriously uses anymore) and toy images.
Most developers under Windows use Cygwin, which provides a dd implementation---the standard and more powerful tool for the job.