git-svn-id: https://profuse.googlecode.com/svn/branches/v2@233 aa027e90-d47c-11dd-86d7-074df07e0730

This commit is contained in:
ksherlock 2010-05-19 23:48:33 +00:00
parent ec9ac20528
commit fc7c205fe0
2 changed files with 63 additions and 29 deletions

View File

@ -19,7 +19,6 @@
#include <Pascal/File.h> #include <Pascal/File.h>
#include <Pascal/Date.h> #include <Pascal/Date.h>
#include <Device/BlockDevice.h> #include <Device/BlockDevice.h>
#include <Device/DiskCopy42Image.h>
@ -184,7 +183,7 @@ int action_cat(unsigned argc, char **argv, Pascal::VolumeEntry *volume)
if (argc < 2) if (argc < 2)
{ {
std::fprintf(stderr, "apfm cat: Please specify one or more files."); std::fprintf(stderr, "apfm cat: Please specify one or more files.\n");
return 1; return 1;
} }
@ -227,21 +226,28 @@ int action_cat(unsigned argc, char **argv, Pascal::VolumeEntry *volume)
int action_cp(int argc, char **argv, Pascal::VolumeEntry *volume) int action_cp(int argc, char **argv, Pascal::VolumeEntry *volume)
{ {
// cp src dest
// first character of ':' indicates pascal file, otherwise, is native file?
return 0; return 0;
} }
int action_mv(int argc, char **argv, Pascal::VolumeEntry *volume) int action_mv(int argc, char **argv, Pascal::VolumeEntry *volume)
{ {
// mv src dest
// first character of ':' indicates pascal file, otherwise is native file?
return 0; return 0;
} }
int action_rm(int argc, char **argv, Pascal::VolumeEntry *volume) int action_rm(int argc, char **argv, Pascal::VolumeEntry *volume)
{ {
// mv rm file [file ....]
// needs ':' as f
return 0; return 0;
} }
int action_krunch(int argc, char **argv, Pascal::VolumeEntry *volume) int action_krunch(int argc, char **argv, Pascal::VolumeEntry *volume)
{ {
// compress file to remove gaps.
return 0; return 0;
} }
@ -300,7 +306,7 @@ int main(int argc, char **argv)
switch(c) switch(c)
{ {
case 'f': case 'f':
fmt = Device::DiskImage::ImageType(optarg); fmt = Device::BlockDevice::ImageType(optarg);
if (!fmt) if (!fmt)
{ {
std::fprintf(stderr, "Error: Invalid file format: ``%s''.\n", std::fprintf(stderr, "Error: Invalid file format: ``%s''.\n",
@ -337,7 +343,7 @@ int main(int argc, char **argv)
try { try {
device.reset( Device::DiskImage::Open(file, true, fmt) ); device.reset( Device::BlockDevice::Open(file, true, fmt) );

View File

@ -1,10 +1,10 @@
#include "../BlockDevice.h" #include <Device/BlockDevice.h>
#include "../Exception.h" #include <Device/RawDevice.h>
#include "../MappedFile.h"
#include "../DiskCopy42Image.h"
#include "File.h"
#include <ProFUSE/Exception.h>
#include <Pascal/File.h>
#include <memory> #include <memory>
#include <cstdio> #include <cstdio>
@ -12,14 +12,26 @@
#include <cerrno> #include <cerrno>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h>
using namespace Pascal; using namespace Pascal;
using namespace Device;
#define NEWFS_VERSION "0.1" #define NEWFS_VERSION "0.1"
bool yes_or_no()
{
int ch, first;
(void)fflush(stderr);
first = ch = getchar();
while (ch != '\n' && ch != EOF)
ch = getchar();
return (first == 'y' || first == 'Y');
}
/* /*
* \d+ by block * \d+ by block
* \d+[Kk] by kilobyte * \d+[Kk] by kilobyte
@ -149,7 +161,7 @@ int main(int argc, char **argv)
case 'f': case 'f':
{ {
format = ProFUSE::DiskImage::ImageType(optarg); format = Device::BlockDevice::ImageType(optarg);
if (format == 0) if (format == 0)
{ {
std::fprintf(stderr, "Error: `%s' is not a supported disk image format.\n", optarg); std::fprintf(stderr, "Error: `%s' is not a supported disk image format.\n", optarg);
@ -181,40 +193,56 @@ int main(int argc, char **argv)
volumeName = "PASCAL"; volumeName = "PASCAL";
} }
if (format == 0) format = ProFUSE::DiskImage::ImageType(fname, 'PO__');
try try
{ {
std::auto_ptr<ProFUSE::BlockDevice> device;
std::auto_ptr<Pascal::VolumeEntry> volume;
// TODO -- check for raw device. struct stat st;
bool rawDevice;
std::auto_ptr<BlockDevice> device;
std::auto_ptr<VolumeEntry> volume;
switch(format) // Check for block device. if so, verify.
// if file exists, verify before overwrite.
std::memset(&st, 0, sizeof(st));
if (::stat(fname, &st) == 0)
{ {
case 'DC42': if (S_ISBLK(st.st_mode))
device.reset(ProFUSE::DiskCopy42Image::Create(fname, blocks, volumeName.c_str())); {
break; fprintf(stderr, "`%s' is a raw device. Are you sure you want to initialize it? ", fname);
if (!yes_or_no()) return -1;
device.reset( RawDevice::Open(fname, false) );
blocks = device->blocks();
rawDevice = true;
}
case 'PO__': else
device.reset(ProFUSE::ProDOSOrderDiskImage::Create(fname, blocks)); {
break; // file exists, verify we want to destroy it.
fprintf(stderr, "`%s' already exists. Are you sure you want to overwrite it? ", fname);
if (!yes_or_no()) return -1;
}
case 'DO__': }
device.reset(ProFUSE::DOSOrderDiskImage::Create(fname, blocks));
break;
if (!rawDevice)
default: device.reset( BlockDevice::Create(fname, volumeName.c_str(), blocks, format));
if (!device.get())
{
std::fprintf(stderr, "Error: Unsupported diskimage format.\n"); std::fprintf(stderr, "Error: Unsupported diskimage format.\n");
return -1; return -1;
} }
volume.reset( volume.reset(
new Pascal::VolumeEntry(volumeName.c_str(), device.get()) new VolumeEntry(volumeName.c_str(), device.get())
); );
device.release(); device.release();