Page 1 of 1
DITO - Disk Image TOols
Posted: Tue Nov 05, 2013 4:54 am
by thomasloven
Announcing: Disk Image TOols - dito - version 0.1.0.
Need an empty disk image with two partitions of 100Mb and 75Mb respectively?
Need to format the first partition in the image as 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...
Re: DITO - Disk Image TOols
Posted: Tue Nov 05, 2013 8:34 am
by olivierf
Wow thanks!
Good tool and will try to use it soon and will give you feedback.
Re: DITO - Disk Image TOols
Posted: Tue Nov 05, 2013 8:36 am
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?
Re: DITO - Disk Image TOols
Posted: Tue Nov 05, 2013 9:20 am
by thomasloven
Added LICENSE.
I'll go with MIT. Do whatever you want, but please include my name somewhere...
Re: DITO - Disk Image TOols
Posted: Wed Nov 06, 2013 7:19 am
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'.
Re: DITO - Disk Image TOols
Posted: Thu Nov 07, 2013 2:36 am
by qw
This looks really cool. Much more verbose than mtools. Are you planning support for other file systems?
Re: DITO - Disk Image TOols
Posted: Thu Nov 07, 2013 2:58 am
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...
Re: DITO - Disk Image TOols
Posted: Thu Nov 07, 2013 3:07 am
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
Re: DITO - Disk Image TOols
Posted: Thu Nov 21, 2013 10:53 am
by thomasloven
I added support for FAT12.
What a mess that filesystem is! Seriously!
Re: DITO - Disk Image TOols
Posted: Thu Nov 21, 2013 4:05 pm
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
Re: DITO - Disk Image TOols
Posted: Thu Nov 21, 2013 7:42 pm
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.
Re: DITO - Disk Image TOols
Posted: Fri Dec 13, 2013 2:38 pm
by BMW
Can you add support for FAT16?
Re: DITO - Disk Image TOols
Posted: Sat Dec 14, 2013 1:53 am
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...
Re: DITO - Disk Image TOols
Posted: Tue Dec 17, 2013 4:30 am
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...