Skip to content

Commit 3816c17

Browse files
committed
Add vinum volume/raid support
1 parent 18f600f commit 3816c17

21 files changed

+1626
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ tests/data/dm/* filter=lfs diff=lfs merge=lfs -text
22
tests/data/md/* filter=lfs diff=lfs merge=lfs -text
33
tests/data/ddf/* filter=lfs diff=lfs merge=lfs -text
44
tests/data/lvm/* filter=lfs diff=lfs merge=lfs -text
5+
tests/data/vinum/* filter=lfs diff=lfs merge=lfs -text

dissect/volume/vinum/c_vinum.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from dissect.cstruct import cstruct
2+
3+
# Structures are copied from:
4+
# https://github.com/freebsd/freebsd-src/blob/f21a6a6a8fc59393173d9a537ed8cebbdbd6343c/sys/geom/vinum/geom_vinum_var.h
5+
6+
vinum_def = """
7+
8+
struct timeval {
9+
uint64 sec;
10+
uint64 usec;
11+
};
12+
13+
typedef uint64 off_t;
14+
15+
/*
16+
* Slice header
17+
*
18+
* Vinum drives start with this structure:
19+
*
20+
*\ Sector
21+
* |--------------------------------------|
22+
* | PDP-11 memorial boot block | 0
23+
* |--------------------------------------|
24+
* | Disk label, maybe | 1
25+
* |--------------------------------------|
26+
* | Slice definition (vinum_hdr) | 8
27+
* |--------------------------------------|
28+
* | |
29+
* | Configuration info, first copy | 9
30+
* | |
31+
* |--------------------------------------|
32+
* | |
33+
* | Configuration info, second copy | 9 + size of config
34+
* | |
35+
* |--------------------------------------|
36+
*/
37+
38+
/* Sizes and offsets of our information. */
39+
#define GV_HDR_OFFSET 4096 /* Offset of vinum header. */
40+
#define GV_HDR_LEN 512 /* Size of vinum header. */
41+
#define GV_CFG_OFFSET 4608 /* Offset of first config copy. */
42+
#define GV_CFG_LEN 65536 /* Size of config copy. */
43+
44+
/* This is where the actual data starts. */
45+
#define GV_DATA_START (GV_CFG_LEN * 2 + GV_CFG_OFFSET)
46+
/* #define GV_DATA_START (GV_CFG_LEN * 2 + GV_HDR_LEN) */
47+
48+
#define GV_MAXDRIVENAME 32 /* Maximum length of a device name. */
49+
50+
/*
51+
* hostname is 256 bytes long, but we don't need to shlep multiple copies in
52+
* vinum. We use the host name just to identify this system, and 32 bytes
53+
* should be ample for that purpose.
54+
*/
55+
56+
#define GV_HOSTNAME_LEN 32
57+
struct gv_label {
58+
char sysname[GV_HOSTNAME_LEN]; /* System name at creation time. */
59+
char name[GV_MAXDRIVENAME]; /* Our name of the drive. */
60+
struct timeval date_of_birth; /* The time it was created ... */
61+
struct timeval last_update; /* ... and the time of last update. */
62+
off_t drive_size; /* Total size incl. headers. */
63+
};
64+
65+
#define GV_OLD_MAGIC 0x494E2056494E4F00LL
66+
#define GV_OLD_NOMAGIC 0x4E4F2056494E4F00LL
67+
#define GV_MAGIC 0x56494E554D2D3100LL
68+
#define GV_NOMAGIC 0x56494E554D2D2D00LL
69+
70+
/* The 'header' of each valid vinum drive. */
71+
struct gv_hdr {
72+
uint64_t magic;
73+
uint64_t config_length;
74+
struct gv_label label;
75+
} header;
76+
""" # noqa W605
77+
78+
c_vinum = cstruct(endian=">").load(vinum_def)
79+
80+
# Not really needed as this size is hardcoded in the various GV_*_OFFSET and related values
81+
SECTOR_SIZE = 512
82+
83+
MAGIC_ACTIVE = {c_vinum.GV_OLD_MAGIC, c_vinum.GV_MAGIC}
84+
MAGIC_INACTIVE = {c_vinum.GV_OLD_NOMAGIC, c_vinum.GV_NOMAGIC}

0 commit comments

Comments
 (0)