xref: /third_party/gptfdisk/diskio.h (revision cf200d32)
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#ifdef __sun__
29#include <sys/dkio.h>
30#endif
31
32#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
33#define fstat64 fstat
34#define stat64 stat
35#endif
36
37#include "support.h"
38//#include "parttypes.h"
39
40/***************************************
41 *                                     *
42 * DiskIO class and related structures *
43 *                                     *
44 ***************************************/
45
46class DiskIO {
47   protected:
48      std::string userFilename;
49      std::string realFilename;
50      std::string modelName;
51      int isOpen;
52      int openForWrite;
53#ifdef _WIN32
54      HANDLE fd;
55#else
56      int fd;
57#endif
58   public:
59      DiskIO(void);
60      ~DiskIO(void);
61
62      void MakeRealName(void);
63      int OpenForRead(const std::string & filename);
64      int OpenForRead(void);
65      int OpenForWrite(const std::string & filename);
66      int OpenForWrite(void);
67      void Close();
68      int Seek(uint64_t sector);
69      int Read(void* buffer, int numBytes);
70      int Write(void* buffer, int numBytes);
71      int DiskSync(void); // resync disk caches to use new partitions
72      int GetBlockSize(void);
73      int GetPhysBlockSize(void);
74      std::string GetModel(void) {return modelName;}
75      uint32_t GetNumHeads(void);
76      uint32_t GetNumSecsPerTrack(void);
77      int IsOpen(void) {return isOpen;}
78      int IsOpenForWrite(void) {return openForWrite;}
79      std::string GetName(void) const {return realFilename;}
80
81      uint64_t DiskSize(int* err);
82}; // class DiskIO
83
84#endif
85