| 1 | /* $OpenBSD: softraidvar.h,v 1.176 2022/12/19 15:27:06 kn Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Copyright (c) 2006 Marco Peereboom <marco@peereboom.us> | 
|---|
| 4 | * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> | 
|---|
| 5 | * | 
|---|
| 6 | * Permission to use, copy, modify, and distribute this software for any | 
|---|
| 7 | * purpose with or without fee is hereby granted, provided that the above | 
|---|
| 8 | * copyright notice and this permission notice appear in all copies. | 
|---|
| 9 | * | 
|---|
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 
|---|
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 
|---|
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 
|---|
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
|---|
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 
|---|
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 
|---|
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
|---|
| 17 | */ | 
|---|
| 18 |  | 
|---|
| 19 | /** @addtogroup hr | 
|---|
| 20 | * @{ | 
|---|
| 21 | */ | 
|---|
| 22 | /** | 
|---|
| 23 | * @file | 
|---|
| 24 | */ | 
|---|
| 25 |  | 
|---|
| 26 | #ifndef _HR_METADATA_FOREIGN_SOFTRAID_H | 
|---|
| 27 | #define _HR_METADATA_FOREIGN_SOFTRAID_H | 
|---|
| 28 |  | 
|---|
| 29 | /* HelenOS specific includes, retypes */ | 
|---|
| 30 |  | 
|---|
| 31 | #include <crypto.h> | 
|---|
| 32 |  | 
|---|
| 33 | typedef uint8_t u_int8_t; | 
|---|
| 34 | typedef uint16_t u_int16_t; | 
|---|
| 35 | typedef uint32_t u_int32_t; | 
|---|
| 36 | typedef uint64_t u_int64_t; | 
|---|
| 37 |  | 
|---|
| 38 | /* copied from <sys/param.h> */ | 
|---|
| 39 | #define _DEV_BSHIFT     9               /* log2(DEV_BSIZE) */ | 
|---|
| 40 | #define DEV_BSIZE       (1 << _DEV_BSHIFT) | 
|---|
| 41 |  | 
|---|
| 42 | /* here continues stripped down and slightly modified softraidvat.h */ | 
|---|
| 43 |  | 
|---|
| 44 | #define MD5_DIGEST_LENGTH 16 | 
|---|
| 45 |  | 
|---|
| 46 | #define SR_META_VERSION         6       /* bump when sr_metadata changes */ | 
|---|
| 47 | #define SR_META_SIZE            64      /* save space at chunk beginning */ | 
|---|
| 48 | #define SR_META_OFFSET          16      /* skip 8192 bytes at chunk beginning */ | 
|---|
| 49 |  | 
|---|
| 50 | #define SR_BOOT_OFFSET          (SR_META_OFFSET + SR_META_SIZE) | 
|---|
| 51 | #define SR_BOOT_LOADER_SIZE     320 /* Size of boot loader storage. */ | 
|---|
| 52 | #define SR_BOOT_LOADER_OFFSET   SR_BOOT_OFFSET | 
|---|
| 53 | #define SR_BOOT_BLOCKS_SIZE     128 /* Size of boot block storage. */ | 
|---|
| 54 | #define SR_BOOT_BLOCKS_OFFSET   (SR_BOOT_LOADER_OFFSET + SR_BOOT_LOADER_SIZE) | 
|---|
| 55 | #define SR_BOOT_SIZE            (SR_BOOT_LOADER_SIZE + SR_BOOT_BLOCKS_SIZE) | 
|---|
| 56 |  | 
|---|
| 57 | #define SR_HEADER_SIZE          (SR_META_SIZE + SR_BOOT_SIZE) | 
|---|
| 58 | #define SR_DATA_OFFSET          (SR_META_OFFSET + SR_HEADER_SIZE) | 
|---|
| 59 |  | 
|---|
| 60 | #define SR_UUID_MAX             16 | 
|---|
| 61 | struct sr_uuid { | 
|---|
| 62 | u_int8_t                sui_id[SR_UUID_MAX]; | 
|---|
| 63 | } __attribute__((packed)); | 
|---|
| 64 |  | 
|---|
| 65 | struct sr_metadata { | 
|---|
| 66 | struct sr_meta_invariant { | 
|---|
| 67 | /* do not change order of ssd_magic, ssd_version */ | 
|---|
| 68 | u_int64_t       ssd_magic;      /* magic id */ | 
|---|
| 69 | #define SR_MAGIC                0x4d4152436372616dLLU | 
|---|
| 70 | u_int32_t       ssd_version;    /* meta data version */ | 
|---|
| 71 | u_int32_t       ssd_vol_flags;  /* volume specific flags. */ | 
|---|
| 72 | struct sr_uuid  ssd_uuid;       /* unique identifier */ | 
|---|
| 73 |  | 
|---|
| 74 | /* chunks */ | 
|---|
| 75 | u_int32_t       ssd_chunk_no;   /* number of chunks */ | 
|---|
| 76 | u_int32_t       ssd_chunk_id;   /* chunk identifier */ | 
|---|
| 77 |  | 
|---|
| 78 | /* optional */ | 
|---|
| 79 | u_int32_t       ssd_opt_no;     /* nr of optional md elements */ | 
|---|
| 80 | u_int32_t       ssd_secsize; | 
|---|
| 81 |  | 
|---|
| 82 | /* volume metadata */ | 
|---|
| 83 | u_int32_t       ssd_volid;      /* volume id */ | 
|---|
| 84 | u_int32_t       ssd_level;      /* raid level */ | 
|---|
| 85 | int64_t         ssd_size;       /* virt disk size in blocks */ | 
|---|
| 86 | char            ssd_vendor[8];  /* scsi vendor */ | 
|---|
| 87 | char            ssd_product[16];/* scsi product */ | 
|---|
| 88 | char            ssd_revision[4];/* scsi revision */ | 
|---|
| 89 | /* optional volume members */ | 
|---|
| 90 | u_int32_t       ssd_strip_size; /* strip size */ | 
|---|
| 91 | } _sdd_invariant; | 
|---|
| 92 | #define ssdi                    _sdd_invariant | 
|---|
| 93 | /* MD5 of invariant metadata */ | 
|---|
| 94 | u_int8_t                ssd_checksum[MD5_DIGEST_LENGTH]; | 
|---|
| 95 | char                    ssd_devname[32];/* /dev/XXXXX */ | 
|---|
| 96 | u_int32_t               ssd_meta_flags; | 
|---|
| 97 | #define SR_META_DIRTY           0x1 | 
|---|
| 98 | u_int32_t               ssd_data_blkno; | 
|---|
| 99 | u_int64_t               ssd_ondisk;     /* on disk version counter */ | 
|---|
| 100 | int64_t                 ssd_rebuild;    /* last block of rebuild */ | 
|---|
| 101 | } __attribute__((packed)); | 
|---|
| 102 |  | 
|---|
| 103 | struct sr_meta_chunk { | 
|---|
| 104 | struct sr_meta_chunk_invariant { | 
|---|
| 105 | u_int32_t       scm_volid;      /* vd we belong to */ | 
|---|
| 106 | u_int32_t       scm_chunk_id;   /* chunk id */ | 
|---|
| 107 | char            scm_devname[32];/* /dev/XXXXX */ | 
|---|
| 108 | int64_t         scm_size;       /* size of partition in blocks */ | 
|---|
| 109 | int64_t         scm_coerced_size; /* coerced sz of part in blk */ | 
|---|
| 110 | struct sr_uuid  scm_uuid;       /* unique identifier */ | 
|---|
| 111 | } _scm_invariant; | 
|---|
| 112 | #define scmi                    _scm_invariant | 
|---|
| 113 | /* MD5 of invariant chunk metadata */ | 
|---|
| 114 | u_int8_t                scm_checksum[MD5_DIGEST_LENGTH]; | 
|---|
| 115 | u_int32_t               scm_status;     /* use bio bioc_disk status */ | 
|---|
| 116 | } __attribute__((packed)); | 
|---|
| 117 |  | 
|---|
| 118 | struct sr_meta_opt_hdr { | 
|---|
| 119 | u_int32_t       som_type;       /* optional metadata type. */ | 
|---|
| 120 | u_int32_t       som_length;     /* optional metadata length. */ | 
|---|
| 121 | u_int8_t        som_checksum[MD5_DIGEST_LENGTH]; | 
|---|
| 122 | } __attribute__((packed)); | 
|---|
| 123 |  | 
|---|
| 124 | #define SR_MD_RAID0             0 | 
|---|
| 125 | #define SR_MD_RAID1             1 | 
|---|
| 126 | #define SR_MD_RAID5             2 | 
|---|
| 127 | #define SR_MD_CACHE             3 | 
|---|
| 128 | #define SR_MD_CRYPTO            4 | 
|---|
| 129 | /* AOE was 5 and 6. */ | 
|---|
| 130 | /* SR_MD_RAID4 was 7. */ | 
|---|
| 131 | #define SR_MD_RAID6             8 | 
|---|
| 132 | #define SR_MD_CONCAT            9 | 
|---|
| 133 | #define SR_MD_RAID1C            10 | 
|---|
| 134 |  | 
|---|
| 135 | /* functions to export from softraid.c to hr_softraid.c */ | 
|---|
| 136 | void     sr_checksum_print(const u_int8_t *); | 
|---|
| 137 | char    *sr_uuid_format(const struct sr_uuid *); | 
|---|
| 138 | void     sr_uuid_print(const struct sr_uuid *, int); | 
|---|
| 139 | void     sr_meta_print(const struct sr_metadata *); | 
|---|
| 140 |  | 
|---|
| 141 | #endif | 
|---|
| 142 |  | 
|---|
| 143 | /** @} | 
|---|
| 144 | */ | 
|---|