diff --git a/Device/BlockDevice.cpp b/Device/BlockDevice.cpp index 79f6e86..9418d89 100644 --- a/Device/BlockDevice.cpp +++ b/Device/BlockDevice.cpp @@ -27,6 +27,30 @@ using ProFUSE::Exception; using ProFUSE::POSIXException; +unsigned BlockDevice::ImageType(MappedFile *f, unsigned defv) +{ +#undef __METHOD__ +#define __METHOD__ "BlockDevice::ImageType" + + + if (UniversalDiskImage::Validate(f, std::nothrow)) + return '2IMG'; + + if (DiskCopy42Image::Validate(f, std::nothrow)) + return 'DC42'; + + if (SDKImage::Validate(f, std::nothrow)) + return 'SDK_'; + + if (ProDOSOrderDiskImage::Validate(f, std::nothrow)) + return 'PO__'; + + if (DOSOrderDiskImage::Validate(f, std::nothrow)) + return 'DO__'; + + return defv; + +} unsigned BlockDevice::ImageType(const char *type, unsigned defv) { @@ -96,27 +120,20 @@ BlockDevicePointer BlockDevice::Open(const char *name, File::FileFlags flags, un { throw POSIXException(__METHOD__ ": stat error", errno); } + + // /dev/xxx ignore the type. + if (S_ISBLK(st.st_mode)) + return RawDevice::Open(name, flags); + + MappedFile file(name, flags); + if (!imageType) { - // /dev/xxxx - if (S_ISBLK(st.st_mode)) - return RawDevice::Open(name, flags); - - - imageType = ImageType(name, 'PO__'); + imageType = ImageType(&file, 'PO__'); } - if (imageType == 'SDK_') - { - // opened by path name. - return SDKImage::Open(name); - } - // TODO -- if no image type, guess based on file size? - - MappedFile file(name, flags); - - + switch (imageType) { case '2IMG': @@ -133,6 +150,10 @@ BlockDevicePointer BlockDevice::Open(const char *name, File::FileFlags flags, un case 'DVX_': return DavexDiskImage::Open(&file); + + case 'SDK_': + return SDKImage::Open(name); + } diff --git a/Device/BlockDevice.h b/Device/BlockDevice.h index c047912..4b31e71 100644 --- a/Device/BlockDevice.h +++ b/Device/BlockDevice.h @@ -12,6 +12,8 @@ #include +class MappedFile; + namespace Device { class BlockDevice : public ENABLE_SHARED_FROM_THIS(BlockDevice) { @@ -20,7 +22,9 @@ public: // static methods. static unsigned ImageType(const char *type, unsigned defv = 0); - + static unsigned ImageType(MappedFile *, unsigned defv = 0); + + static BlockDevicePointer Open(const char *name, File::FileFlags flags, unsigned imageType = 0); static BlockDevicePointer Create(const char *fname, const char *vname, unsigned blocks, unsigned imageType = 0); diff --git a/main.cpp b/main.cpp index 137d0d3..62dff80 100644 --- a/main.cpp +++ b/main.cpp @@ -128,6 +128,7 @@ static void usage() " --format=format specify the disk image format. Valid values are:\n" " dc42 DiskCopy 4.2 Image\n" " davex Davex Disk Image\n" + " sdk ShrinkIt Disk Image\n" " 2img Universal Disk Image\n" " do DOS Order Disk Image\n" " po ProDOS Order Disk Image (default)\n"