Homemade tool to write data from file to disk image

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Post Reply
User avatar
Luis
Member
Member
Posts: 39
Joined: Sat Feb 16, 2013 11:19 am

Homemade tool to write data from file to disk image

Post 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
Attachments
diskwrite.zip
(4.35 KiB) Downloaded 120 times
Last edited by Luis on Fri Mar 29, 2013 5:00 pm, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Homemade tool to write data from file to disk image

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Luis
Member
Member
Posts: 39
Joined: Sat Feb 16, 2013 11:19 am

Re: Homemade tool to write data from file to disk image

Post 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 :)
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Homemade tool to write data from file to disk image

Post 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.
Learn to read.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Homemade tool to write data from file to disk image

Post 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
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Homemade tool to write data from file to disk image

Post 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
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Homemade tool to write data from file to disk image

Post by bubach »

partcopy.exe is quite common amongst os-developers on windows.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Homemade tool to write data from file to disk image

Post by Mikemk »

I just use flat images.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Homemade tool to write data from file to disk image

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply