summaryrefslogtreecommitdiff
path: root/src/drive.h
blob: e943ef1df8bc41f1e42d6c630ab26715ad109607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* 
 * AUTHOR
 * Stef Walter
 *
 * LICENSE
 * This software is in the public domain.
 *
 * The software is provided "as is", without warranty of any kind,
 * express or implied, including but not limited to the warranties
 * of merchantability, fitness for a particular purpose, and
 * noninfringement. In no event shall the author(s) be liable for any
 * claim, damages, or other liability, whether in an action of
 * contract, tort, or otherwise, arising from, out of, or in connection
 * with the software or the use or other dealings in the software.
 * 
 * SUPPORT
 * Send bug reports to: <stef@memberwebs.com>
 */

#ifndef __DRIVE_H__20010822
#define __DRIVE_H__20010822

#include "usuals.h"

#define kSectorSize     0x200

#ifdef _WIN32
  #define kInvalidSector  0xFFFFFFFFFFFFFFFF
#else
  #define kInvalidSector  0xFFFFFFFFFFFFFFFFLL
#endif


struct _ntfsx_mftmap;
struct _drivelocks;

typedef struct _partitioninfo
{
	uint64 first;          /* The first sector (in sectors) */
	uint64 end;            /* The end sector (in sectors) */
	uint64 mft;            /* Offset into the MFT (in sectors) */
	byte cluster;          /* Cluster size (in sectors) */
	int device;            /* A handle to an open device */

	/* Some other context stuff about the drive */
	struct _drivelocks* locks;
	struct _ntfsx_mftmap* mftmap;
} 
partitioninfo;

#pragma pack(1)

#define kPartition_Invalid      0
#define kPartition_Extended     5
#define kPartition_ExtendedLBA 15


/* Partition table entry */
typedef struct _drive_partentry
{
	byte active;		    /* partition bootable flag */
	byte starthead;		  /* starting head */
	byte startsector;	  /* starting sector and 2 MS bits of cylinder */
	byte startcylinder;	/* starting cylinder (low 8 bits) */
	byte system;		    /* partition type */
	byte endhead;	    	/* ending head */
	byte endsector;	  	/* ending sector and 2 MS bits of cylinder */
	byte endcylinder; 	/* ending cylinder (low 8 bits) */
	uint32 startsec;	  /* absolute starting sector */
	uint32 endsec;		  /* absolute ending sector */
}
drive_partentry;

#define kMBR_Sig        0xAA55

/* Master Boot Record */
typedef struct _drive_mbr
{
	byte fill[0x1be];			          /* boot code */
	drive_partentry partitions[4];	/* partition table */
	uint16 sig;				              /* 55AAh boot signature */
}
drive_mbr;

#pragma pack()

#define CLUSTER_TO_SECTOR(info, clus) (((clus) * (info).cluster) + (info).first)
#define SECTOR_TO_BYTES(sec) ((sec) * kSectorSize)
#define CLUSTER_SIZE(info) ((info).cluster * kSectorSize)

#ifdef _WIN32
  /* driveName should be MAX_PATH chars long */
  void makeDriveName(char* driveName, int i);
#endif

#endif /* __DRIVE_H__ */