mirror of
https://github.com/ksherlock/profuse.git
synced 2025-01-10 07:30:09 +00:00
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@233 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
ec9ac20528
commit
fc7c205fe0
14
apfm.cpp
14
apfm.cpp
@ -19,7 +19,6 @@
|
||||
#include <Pascal/File.h>
|
||||
#include <Pascal/Date.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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -227,21 +226,28 @@ int action_cat(unsigned 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int action_rm(int argc, char **argv, Pascal::VolumeEntry *volume)
|
||||
{
|
||||
// mv rm file [file ....]
|
||||
// needs ':' as f
|
||||
return 0;
|
||||
}
|
||||
|
||||
int action_krunch(int argc, char **argv, Pascal::VolumeEntry *volume)
|
||||
{
|
||||
// compress file to remove gaps.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -300,7 +306,7 @@ int main(int argc, char **argv)
|
||||
switch(c)
|
||||
{
|
||||
case 'f':
|
||||
fmt = Device::DiskImage::ImageType(optarg);
|
||||
fmt = Device::BlockDevice::ImageType(optarg);
|
||||
if (!fmt)
|
||||
{
|
||||
std::fprintf(stderr, "Error: Invalid file format: ``%s''.\n",
|
||||
@ -337,7 +343,7 @@ int main(int argc, char **argv)
|
||||
try {
|
||||
|
||||
|
||||
device.reset( Device::DiskImage::Open(file, true, fmt) );
|
||||
device.reset( Device::BlockDevice::Open(file, true, fmt) );
|
||||
|
||||
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "../BlockDevice.h"
|
||||
#include "../Exception.h"
|
||||
#include "../MappedFile.h"
|
||||
#include "../DiskCopy42Image.h"
|
||||
#include <Device/BlockDevice.h>
|
||||
#include <Device/RawDevice.h>
|
||||
|
||||
#include "File.h"
|
||||
|
||||
#include <ProFUSE/Exception.h>
|
||||
|
||||
#include <Pascal/File.h>
|
||||
|
||||
#include <memory>
|
||||
#include <cstdio>
|
||||
@ -12,14 +12,26 @@
|
||||
#include <cerrno>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace Pascal;
|
||||
using namespace Device;
|
||||
|
||||
#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+[Kk] by kilobyte
|
||||
@ -149,7 +161,7 @@ int main(int argc, char **argv)
|
||||
|
||||
case 'f':
|
||||
{
|
||||
format = ProFUSE::DiskImage::ImageType(optarg);
|
||||
format = Device::BlockDevice::ImageType(optarg);
|
||||
if (format == 0)
|
||||
{
|
||||
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";
|
||||
}
|
||||
|
||||
if (format == 0) format = ProFUSE::DiskImage::ImageType(fname, 'PO__');
|
||||
|
||||
|
||||
|
||||
|
||||
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':
|
||||
device.reset(ProFUSE::DiskCopy42Image::Create(fname, blocks, volumeName.c_str()));
|
||||
break;
|
||||
if (S_ISBLK(st.st_mode))
|
||||
{
|
||||
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__':
|
||||
device.reset(ProFUSE::ProDOSOrderDiskImage::Create(fname, blocks));
|
||||
break;
|
||||
else
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
if (!rawDevice)
|
||||
device.reset( BlockDevice::Create(fname, volumeName.c_str(), blocks, format));
|
||||
|
||||
if (!device.get())
|
||||
{
|
||||
std::fprintf(stderr, "Error: Unsupported diskimage format.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
volume.reset(
|
||||
new Pascal::VolumeEntry(volumeName.c_str(), device.get())
|
||||
new VolumeEntry(volumeName.c_str(), device.get())
|
||||
);
|
||||
device.release();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user