From fc7c205fe00c3719d672503c636326f10a450c0a Mon Sep 17 00:00:00 2001 From: ksherlock Date: Wed, 19 May 2010 23:48:33 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@233 aa027e90-d47c-11dd-86d7-074df07e0730 --- apfm.cpp | 14 ++++++--- newfs_pascal.cpp | 78 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/apfm.cpp b/apfm.cpp index dbefc63..656e768 100644 --- a/apfm.cpp +++ b/apfm.cpp @@ -19,7 +19,6 @@ #include #include #include -#include @@ -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) ); diff --git a/newfs_pascal.cpp b/newfs_pascal.cpp index 838a1c6..9a434aa 100644 --- a/newfs_pascal.cpp +++ b/newfs_pascal.cpp @@ -1,10 +1,10 @@ -#include "../BlockDevice.h" -#include "../Exception.h" -#include "../MappedFile.h" -#include "../DiskCopy42Image.h" +#include +#include -#include "File.h" +#include + +#include #include #include @@ -12,14 +12,26 @@ #include #include - +#include 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 device; - std::auto_ptr volume; - // TODO -- check for raw device. + struct stat st; + bool rawDevice; + std::auto_ptr device; + std::auto_ptr 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();