-
Notifications
You must be signed in to change notification settings - Fork 4
/
sector0.h
71 lines (55 loc) · 1.35 KB
/
sector0.h
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
#pragma once
#include <assert.h>
#include "common.h"
// https://3dbrew.org/wiki/NCSD#NCSD_header
#define SECTOR_SIZE 0x200
#define NCSD_PARTITIONS 8
#ifdef _MSC_VER
#pragma pack(push, 1)
#define PACKED
#elif defined __GNUC__
#define PACKED __attribute__ ((__packed__))
#endif
typedef struct {
u32 offset;
u32 length;
} PACKED ncsd_partition_t;
typedef struct {
u8 signature[0x100];
u32 magic;
u32 size;
u64 media_id;
u8 fs_types[NCSD_PARTITIONS];
u8 crypt_types[NCSD_PARTITIONS];
ncsd_partition_t partitions[NCSD_PARTITIONS];
} PACKED ncsd_header_t;
typedef struct {
u8 head;
u8 sector;
u8 cylinder;
} PACKED chs_t;
typedef struct {
u8 status;
chs_t chs_first;
u8 type;
chs_t chs_last;
u32 offset;
u32 length;
} PACKED mbr_partition_t;
#define MBR_PARTITIONS 4
// or 446 in decimal, all zero on DSi in all my samples
#define MBR_BOOTSTRAP_SIZE 0x1be
typedef struct {
u8 bootstrap[MBR_BOOTSTRAP_SIZE];
mbr_partition_t partitions[MBR_PARTITIONS];
u8 boot_signature_0;
u8 boot_signature_1;
} PACKED mbr_t;
#ifdef _MSC_VER
#pragma pack(pop)
#endif
#undef PACKED
static_assert(sizeof(ncsd_header_t) == 0x160, "sizeof(ncsd_header_t) should equal 0x160");
static_assert(sizeof(mbr_t) == SECTOR_SIZE, "sizeof(mbr_t) should equal 0x200");
int parse_ncsd(const u8 sector0[SECTOR_SIZE]);
int parse_mbr(const u8 sector0[SECTOR_SIZE], int is3DS, int verbose);