From add79a6e1b3a1af1305f02d51eb3aa148f580caa Mon Sep 17 00:00:00 2001 From: srs5694 Date: Tue, 26 Jan 2010 15:59:58 -0500 Subject: New files to support I/O restructuring and (currently broken) Windows version. --- diskio.h | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 diskio.h (limited to 'diskio.h') diff --git a/diskio.h b/diskio.h new file mode 100644 index 0000000..2435cc5 --- /dev/null +++ b/diskio.h @@ -0,0 +1,85 @@ +// +// C++ Interface: diskio +// +// Description: Class to handle low-level disk I/O for GPT fdisk +// +// +// Author: Rod Smith , (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// +// This program is copyright (c) 2009 by Roderick W. Smith. It is distributed +// under the terms of the GNU GPL version 2, as detailed in the COPYING file. + +#ifndef __DISKIO_H +#define __DISKIO_H + +#include +#include +#include +#ifdef MINGW +#include +#include +#else +#include +#endif + +#if defined (__FreeBSD__) || defined (__APPLE__) +#define fstat64 fstat +#define stat64 stat +#endif + +#include "support.h" +#include "parttypes.h" + +using namespace std; + +// Below constant corresponds to an 800GB disk -- a somewhat arbitrary +// cutoff +#define SMALLEST_ADVANCED_FORMAT UINT64_C(1677721600) + +/*************************************** + * * + * DiskIO class and related structures * + * * + ***************************************/ + +class DiskIO { + protected: + string userFilename; + string realFilename; + int isOpen; + int openForWrite; + uint8_t *sectorData; +#ifdef MINGW + HANDLE fd; +#else + int fd; +#endif + public: + DiskIO(void); +// DiskIO(const DiskIO & orig); + ~DiskIO(void); + +// DiskIO & operator=(const DiskIO & orig); + void MakeRealName(void); + int OpenForRead(string filename); + int OpenForRead(void); + int OpenForWrite(string filename); + int OpenForWrite(void); + void Close(); + int Seek(uint64_t sector); + int Read(void* buffer, int numBytes); + int Write(void* buffer, int numBytes); + void DiskSync(void); // resync disk caches to use new partitions + int GetBlockSize(void); + int FindAlignment(void); + int FindAlignment(string filename); + int IsOpen(void) {return isOpen;} + int IsOpenForWrite(void) {return openForWrite;} + + uint64_t DiskSize(int* err); +}; // struct GPTPart + +#endif -- cgit v1.2.1