OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 1:48 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Homemade tool to write data from file to disk image
PostPosted: Thu Mar 07, 2013 5:07 pm 
Offline
Member
Member
User avatar

Joined: Sat Feb 16, 2013 11:19 am
Posts: 39
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 97 times


Last edited by Luis on Fri Mar 29, 2013 5:00 pm, edited 1 time in total.
Top
 Profile  
 
 Post subject: Re: Homemade tool to write data from file to disk image
PostPosted: Thu Mar 07, 2013 5:25 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: Homemade tool to write data from file to disk image
PostPosted: Thu Mar 07, 2013 6:29 pm 
Offline
Member
Member
User avatar

Joined: Sat Feb 16, 2013 11:19 am
Posts: 39
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 :)


Top
 Profile  
 
 Post subject: Re: Homemade tool to write data from file to disk image
PostPosted: Thu Mar 07, 2013 11:28 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
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.


Top
 Profile  
 
 Post subject: Re: Homemade tool to write data from file to disk image
PostPosted: Fri Mar 08, 2013 2:13 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
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:
# 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:
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

_________________
Undefined behavior since 2012


Top
 Profile  
 
 Post subject: Re: Homemade tool to write data from file to disk image
PostPosted: Fri Mar 22, 2013 1:10 pm 
Offline
Member
Member

Joined: Sat Oct 22, 2011 12:27 pm
Posts: 409
Antti wrote:
Code:
# 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.


Top
 Profile  
 
 Post subject: Re: Homemade tool to write data from file to disk image
PostPosted: Thu Mar 28, 2013 6:22 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1223
Location: Sweden
partcopy.exe is quite common amongst os-developers on windows.

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re: Homemade tool to write data from file to disk image
PostPosted: Fri Mar 29, 2013 4:48 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Homemade tool to write data from file to disk image
PostPosted: Fri Mar 29, 2013 6:17 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
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 ]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 117 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group