mirror of
https://github.com/ksherlock/profuse.git
synced 2025-01-20 10:30:01 +00:00
Implement better image type inspection.
git-svn-id: https://profuse.googlecode.com/svn/branches/profuse_interim@378 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
77e5994908
commit
1a0bdd875c
@ -27,6 +27,30 @@ using ProFUSE::Exception;
|
|||||||
using ProFUSE::POSIXException;
|
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)
|
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);
|
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)
|
if (!imageType)
|
||||||
{
|
{
|
||||||
// /dev/xxxx
|
imageType = ImageType(&file, 'PO__');
|
||||||
if (S_ISBLK(st.st_mode))
|
|
||||||
return RawDevice::Open(name, flags);
|
|
||||||
|
|
||||||
|
|
||||||
imageType = ImageType(name, '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)
|
switch (imageType)
|
||||||
{
|
{
|
||||||
case '2IMG':
|
case '2IMG':
|
||||||
@ -133,6 +150,10 @@ BlockDevicePointer BlockDevice::Open(const char *name, File::FileFlags flags, un
|
|||||||
|
|
||||||
case 'DVX_':
|
case 'DVX_':
|
||||||
return DavexDiskImage::Open(&file);
|
return DavexDiskImage::Open(&file);
|
||||||
|
|
||||||
|
case 'SDK_':
|
||||||
|
return SDKImage::Open(name);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <File/File.h>
|
#include <File/File.h>
|
||||||
|
|
||||||
|
class MappedFile;
|
||||||
|
|
||||||
namespace Device {
|
namespace Device {
|
||||||
|
|
||||||
class BlockDevice : public ENABLE_SHARED_FROM_THIS(BlockDevice) {
|
class BlockDevice : public ENABLE_SHARED_FROM_THIS(BlockDevice) {
|
||||||
@ -20,7 +22,9 @@ public:
|
|||||||
|
|
||||||
// static methods.
|
// static methods.
|
||||||
static unsigned ImageType(const char *type, unsigned defv = 0);
|
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 Open(const char *name, File::FileFlags flags, unsigned imageType = 0);
|
||||||
static BlockDevicePointer Create(const char *fname, const char *vname, unsigned blocks, unsigned imageType = 0);
|
static BlockDevicePointer Create(const char *fname, const char *vname, unsigned blocks, unsigned imageType = 0);
|
||||||
|
|
||||||
|
1
main.cpp
1
main.cpp
@ -128,6 +128,7 @@ static void usage()
|
|||||||
" --format=format specify the disk image format. Valid values are:\n"
|
" --format=format specify the disk image format. Valid values are:\n"
|
||||||
" dc42 DiskCopy 4.2 Image\n"
|
" dc42 DiskCopy 4.2 Image\n"
|
||||||
" davex Davex Disk Image\n"
|
" davex Davex Disk Image\n"
|
||||||
|
" sdk ShrinkIt Disk Image\n"
|
||||||
" 2img Universal Disk Image\n"
|
" 2img Universal Disk Image\n"
|
||||||
" do DOS Order Disk Image\n"
|
" do DOS Order Disk Image\n"
|
||||||
" po ProDOS Order Disk Image (default)\n"
|
" po ProDOS Order Disk Image (default)\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user