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