resetting manifest requested domain to floor
[platform/upstream/gptfdisk.git] / diskio.h
1 //
2 // C++ Interface: diskio
3 //
4 // Description: Class to handle low-level disk I/O for GPT fdisk
5 //
6 //
7 // Author: Rod Smith <rodsmith@rodsbooks.com>, (C) 2009
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 // This program is copyright (c) 2009 by Roderick W. Smith. It is distributed
13 // under the terms of the GNU GPL version 2, as detailed in the COPYING file.
14
15 #ifndef __DISKIO_H
16 #define __DISKIO_H
17
18 #include <string>
19 #include <stdint.h>
20 #include <sys/types.h>
21 #ifdef _WIN32
22 #include <windows.h>
23 #include <winioctl.h>
24 #else
25 #include <sys/ioctl.h>
26 #endif
27
28 #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
29 #define fstat64 fstat
30 #define stat64 stat
31 #endif
32
33 #include "support.h"
34 //#include "parttypes.h"
35
36 using namespace std;
37
38 /***************************************
39  *                                     *
40  * DiskIO class and related structures *
41  *                                     *
42  ***************************************/
43
44 class DiskIO {
45    protected:
46       string userFilename;
47       string realFilename;
48       int isOpen;
49       int openForWrite;
50 #ifdef _WIN32
51       HANDLE fd;
52 #else
53       int fd;
54 #endif
55    public:
56       DiskIO(void);
57       ~DiskIO(void);
58
59       void MakeRealName(void);
60       int OpenForRead(const string & filename);
61       int OpenForRead(void);
62       int OpenForWrite(const string & filename);
63       int OpenForWrite(void);
64       void Close();
65       int Seek(uint64_t sector);
66       int Read(void* buffer, int numBytes);
67       int Write(void* buffer, int numBytes);
68       int DiskSync(void); // resync disk caches to use new partitions
69       int GetBlockSize(void);
70       uint32_t GetNumHeads(void);
71       uint32_t GetNumSecsPerTrack(void);
72       int IsOpen(void) {return isOpen;}
73       int IsOpenForWrite(void) {return openForWrite;}
74       string GetName(void) const {return realFilename;}
75
76       uint64_t DiskSize(int* err);
77 }; // class DiskIO
78
79 #endif