DITO - Disk Image TOols

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
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

DITO - Disk Image TOols

Post by thomasloven »

Announcing: Disk Image TOols - dito - version 0.1.0.

Need an empty disk image with two partitions of 100Mb and 75Mb respectively?

Code: Select all

$ dito-generate disk.img 100M 75M
Need to format the first partition in the image as ext2?

Code: Select all

$ dito-format disk.img:1 ext2
Need to prepare it for installing grub?

Code: Select all

$ dito-mkdir ext2:disk.img:1:/boot
$ dito-mkdir ext2:disk.img:1:/boot/grub
$ dito-cp grub-files/stage1 ext2:disk.img:1:/boot/grub/stage1
$ dito-cp grub-files/stage2 ext2:disk.img:1:/boot/stage2
Think you may have messed that up?

Code: Select all

$ dito-ls ext2:disk.img:1/boot/grub
$ dito-ls ext2:disk.img:1/boot
Know for certain that you messed that up?

Code: Select all

$ dito-rm ext2:disk.img:1:/boot/stage2
$ dito-cp grub-files/stage2 ext2:disk.img:1:/boot/grub/stage2
Ran your os from the disk image and saved some important data to a log file?

Code: Select all

$ dito-cp ext2:disk.img:1:/data/important.log - | less
Wish it really was this simple?
It is. https://github.com/thomasloven/dito

On a serious note.
I grew tired of my computer freezing up randomly when I tried to use osx-fuse. So I wrote a couple of tools to handle disk images in general and ext2 partitions in particular. A great learning experience.

Perhaps they can be helpful for someone else too, so I'm putting them out here.

Update: dito now supports FAT12.


Edit: It should compile on osx and linux now. I've tried it on my mac and on a raspberry pi (raspbian). Might work under cygwin as well. Will try it some day.

Edit2: It does compile under cygwin, but doesn't work...
Last edited by thomasloven on Thu Nov 21, 2013 10:52 am, edited 2 times in total.
olivierf
Posts: 5
Joined: Thu Mar 28, 2013 7:23 am
Location: Montreal - Canada

Re: DITO - Disk Image TOols

Post by olivierf »

Wow thanks!

Good tool and will try to use it soon and will give you feedback.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: DITO - Disk Image TOols

Post by Brynet-Inc »

I've always prefered utilities like mtools for handling foreign filesystems, it keeps the implementation strictly in userland and avoids and nasty kernel interfaces like FUSE.

I haven't looked at your implementation, but it seems you haven't chosen a license.. what are your terms for redistribution, modification?
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

Re: DITO - Disk Image TOols

Post by thomasloven »

Added LICENSE.
I'll go with MIT. Do whatever you want, but please include my name somewhere...
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: DITO - Disk Image TOols

Post by sortie »

Oh hey, cool. I'll take a longer look at this later.

I had a quick look at your Makefile, though, and encountered a few pet peeves of mine.

Code: Select all

install -d $(DESTDIR)/$(PREFIX)/lib/
Assuming the prefix was the empty string, the libraries should be installed into /lib. The prefix doesn't need to (and shouldn't) end in a slash because whatever it prefixes is already bound to have a leading slash. The same deal applies with the DESTDIR variable, as it is effectively another prefix. If the PREFIX variable is set, then it would always start with a slash (as it is an absolute) path. The same applies to DESTDIR. This means the slash between DESTDIR and PREFIX here is not only redundant in all cases, it's actually dangerous, as since PREFIX always must have a leading slash, then assuming PREFIX is /usr/local by default, then the libraries would be installed into //usr/local/lib - notice the leading double-slash, which POSIX allows to mean something else entirely than the root directory (think what \\ means on Windows). So you need to remove that redundant slash as it breaks the 'prefix' abstraction, which is *not* 'a path component that may involve slash characters'.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: DITO - Disk Image TOols

Post by qw »

This looks really cool. Much more verbose than mtools. Are you planning support for other file systems?
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

Re: DITO - Disk Image TOols

Post by thomasloven »

Sortie: Thanks. I never knew about the leading-double-slash-weirdness of POSIX. Interesting... It's fixed now.

Hobbes: Eventually. I should be able to at least get FAT and perhaps SFS to work...
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: DITO - Disk Image TOols

Post by Combuster »

Well, I have built just this tool in the past, but then keyed for SFS. You can leech some ideas from it if you want - Sourcecode in signature ;)
"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 ]
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

Re: DITO - Disk Image TOols

Post by thomasloven »

I added support for FAT12.

What a mess that filesystem is! Seriously!
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: DITO - Disk Image TOols

Post by Nable »

Sorry, at the moment I'm not in the state to provide patches but here are some small things that I want to mention.
Too much zeroes (remove last two) in initializers:

Code: Select all

src/fat.c:591:13: warning: excess elements in struct initializer
      0,0,0,0,0
            ^
src/fat.c:601:13: warning: excess elements in struct initializer
      0,0,0,0,0
            ^
src/fat.c:611:13: warning: excess elements in struct initializer
      0,0,0,0,0
            ^
3 warnings generated.
Sizes of some types are a piece of nightmare:

Code: Select all

bin/generate.c:62:43: warning: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Wformat]
  printf(" Image file created with CHS: %ld %ld %ld\n", im->cylinders, im->heads, im->sectors);
                                        ~~^             ~~~~~~~~~~~~~
                                        %zd
bin/generate.c:62:47: warning: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Wformat]
  printf(" Image file created with CHS: %ld %ld %ld\n", im->cylinders, im->heads, im->sectors);
                                            ~~^                        ~~~~~~~~~
                                            %zd
bin/generate.c:62:51: warning: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Wformat]
  printf(" Image file created with CHS: %ld %ld %ld\n", im->cylinders, im->heads, im->sectors);
                                                ~~^                               ~~~~~~~~~~~
                                                %zd
I'm still (several years ago I also had similar problem) not sure what to use as a cross-platform printf specifier for size_t. In this example nothing is broken just because `long' is also 32-bit on my system. Btw, isn't uint32_t enough here?

Prototypes for some functions are missing in `fat.h':

Code: Select all

tests/fat_tests.c:15:13: warning: implicit declaration of function 'fat_bits' is invalid in C99 [-Wimplicit-function-declaration]
  mu_assert(fat_bits(fs) == 12, "Wrong FAT type (Not 12)");
            ^
tests/minunit.h:17:39: note: expanded from macro 'mu_assert'
#define mu_assert(test, message) if(!(test)) { log_err(message); return message; }
                                      ^
tests/fat_tests.c:24:36: warning: implicit declaration of function 'fat_read_fat' is invalid in C99 [-Wimplicit-function-declaration]
  printf("  Fat table value %x\n", fat_read_fat(fs, 0));
                                   ^
tests/fat_tests.c:87:3: warning: implicit declaration of function 'fat_write_fat' is invalid in C99 [-Wimplicit-function-declaration]
  fat_write_fat(fs, 14, 0x12);
  ^
tests/fat_tests.c:104:37: warning: implicit declaration of function 'fat_make_shortname' is invalid in C99 [-Wimplicit-function-declaration]
  printf("longfilename.txt : %s\n", fat_make_shortname("longfilename.txt"));
                                    ^
tests/fat_tests.c:104:31: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
  printf("longfilename.txt : %s\n", fat_make_shortname("longfilename.txt"));
                             ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                             %d
tests/fat_tests.c:105:29: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
  printf("longfilename.c : %s\n", fat_make_shortname("longfilename.c"));
                           ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           %d
tests/fat_tests.c:106:23: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
  printf("name.txt : %s\n", fat_make_shortname("name.txt"));
                     ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     %d
tests/fat_tests.c:107:21: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
  printf("name.c : %s\n", fat_make_shortname("name.c"));
                   ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   %d
tests/fat_tests.c:115:3: warning: implicit declaration of function 'fat_write_longname' is invalid in C99 [-Wimplicit-function-declaration]
  fat_write_longname(de, "File with very long filename.ext");
  ^
tests/fat_tests.c:116:34: warning: implicit declaration of function 'fat_read_longname' is invalid in C99 [-Wimplicit-function-declaration]
  printf(" Filename read: %s\n", fat_read_longname(de));
                                 ^
tests/fat_tests.c:116:28: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
  printf(" Filename read: %s\n", fat_read_longname(de));
                          ~^     ~~~~~~~~~~~~~~~~~~~~~
                          %d
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: DITO - Disk Image TOols

Post by sortie »

Check the standards, the C99 standard specifier for size_t is "%zu". If you don't know the appropriate specifier for a datatype, cast it to uintmax_t and print it as such: printf("%ju\n", (uintmax_t) mysteriously_typed_value); Be mindful, if you really want to be "cross-platform" and support MSVC, then you are just doing yourself a disfavor as this platform is known to be downright silly. If you only target Unix systems, %zu and %ju are very safe.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: DITO - Disk Image TOols

Post by BMW »

Can you add support for FAT16?
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: DITO - Disk Image TOols

Post by zhiayang »

BMW wrote:Can you add support for FAT16?
Or FAT32, for that matter?

It's a great tool, but seeing as you /can't actually/ mount ext2 partitions in OS X...
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

Re: DITO - Disk Image TOols

Post by thomasloven »

I'll probably try to implement FAT16 and 32 eventually, but don't hold your breath...
requimrar wrote: It's a great tool, but seeing as you /can't actually/ mount ext2 partitions in OS X...
That's the point. If I could mount ext2 partitions in OSX, I wouldn't have needed to make this tool...
Post Reply