PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/netbsd/src/external/cddl/osnet/dist/uts/common/sys/vtoc.h

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
C Header | 350 lines | 256 code | 37 blank | 57 comment | 19 complexity | d0302656ce0ee74dee445da186397665 MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*
  2. * CDDL HEADER START
  3. *
  4. * The contents of this file are subject to the terms of the
  5. * Common Development and Distribution License (the "License").
  6. * You may not use this file except in compliance with the License.
  7. *
  8. * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  9. * or http://www.opensolaris.org/os/licensing.
  10. * See the License for the specific language governing permissions
  11. * and limitations under the License.
  12. *
  13. * When distributing Covered Code, include this CDDL HEADER in each
  14. * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15. * If applicable, add the following below this CDDL HEADER, with the
  16. * fields enclosed by brackets "[]" replaced with your own identifying
  17. * information: Portions Copyright [yyyy] [name of copyright owner]
  18. *
  19. * CDDL HEADER END
  20. */
  21. /*
  22. * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
  23. * Use is subject to license terms.
  24. */
  25. /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  26. /* All Rights Reserved */
  27. #ifndef _SYS_VTOC_H
  28. #define _SYS_VTOC_H
  29. #include <sys/dklabel.h>
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /*
  34. * Note: the VTOC is not implemented fully, nor in the manner
  35. * that AT&T implements it. AT&T puts the vtoc structure
  36. * into a sector, usually the second sector (pdsector is first).
  37. *
  38. * Sun incorporates the tag, flag, version, and volume vtoc fields into
  39. * its Disk Label, which already has some vtoc-equivalent fields.
  40. * Upon reading the vtoc with read_vtoc(), the following exceptions
  41. * occur:
  42. * v_bootinfo [all] returned as zero
  43. * v_sanity returned as VTOC_SANE
  44. * if Disk Label was sane
  45. * v_sectorsz returned as 512
  46. * v_reserved [all] retunred as zero
  47. * timestamp [all] returned as zero
  48. *
  49. * See dklabel.h, read_vtoc(), and write_vtoc().
  50. */
  51. #define V_NUMPAR NDKMAP /* The number of partitions */
  52. /* (from dkio.h) */
  53. #define VTOC_SANE 0x600DDEEE /* Indicates a sane VTOC */
  54. #define V_VERSION 0x01 /* layout version number */
  55. #define V_EXTVERSION V_VERSION /* extvtoc layout version number */
  56. /*
  57. * Partition identification tags
  58. */
  59. #define V_UNASSIGNED 0x00 /* unassigned partition */
  60. #define V_BOOT 0x01 /* Boot partition */
  61. #define V_ROOT 0x02 /* Root filesystem */
  62. #define V_SWAP 0x03 /* Swap filesystem */
  63. #define V_USR 0x04 /* Usr filesystem */
  64. #define V_BACKUP 0x05 /* full disk */
  65. #define V_STAND 0x06 /* Stand partition */
  66. #define V_VAR 0x07 /* Var partition */
  67. #define V_HOME 0x08 /* Home partition */
  68. #define V_ALTSCTR 0x09 /* Alternate sector partition */
  69. #define V_CACHE 0x0a /* Cache (cachefs) partition */
  70. #define V_RESERVED 0x0b /* SMI reserved data */
  71. /*
  72. * Partition permission flags
  73. */
  74. #define V_UNMNT 0x01 /* Unmountable partition */
  75. #define V_RONLY 0x10 /* Read only */
  76. /*
  77. * error codes for reading & writing vtoc
  78. */
  79. #define VT_ERROR (-2) /* errno supplies specific error */
  80. #define VT_EIO (-3) /* I/O error accessing vtoc */
  81. #define VT_EINVAL (-4) /* illegal value in vtoc or request */
  82. #define VT_ENOTSUP (-5) /* VTOC op. not supported */
  83. #define VT_ENOSPC (-6) /* requested space not found */
  84. #define VT_EOVERFLOW (-7) /* VTOC op. data struct limited */
  85. struct partition {
  86. ushort_t p_tag; /* ID tag of partition */
  87. ushort_t p_flag; /* permission flags */
  88. daddr_t p_start; /* start sector no of partition */
  89. long p_size; /* # of blocks in partition */
  90. };
  91. struct vtoc {
  92. unsigned long v_bootinfo[3]; /* info needed by mboot (unsupported) */
  93. unsigned long v_sanity; /* to verify vtoc sanity */
  94. unsigned long v_version; /* layout version */
  95. char v_volume[LEN_DKL_VVOL]; /* volume name */
  96. ushort_t v_sectorsz; /* sector size in bytes */
  97. ushort_t v_nparts; /* number of partitions */
  98. unsigned long v_reserved[10]; /* free space */
  99. struct partition v_part[V_NUMPAR]; /* partition headers */
  100. time_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported) */
  101. char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
  102. };
  103. struct extpartition {
  104. ushort_t p_tag; /* ID tag of partition */
  105. ushort_t p_flag; /* permission flags */
  106. ushort_t p_pad[2];
  107. diskaddr_t p_start; /* start sector no of partition */
  108. diskaddr_t p_size; /* # of blocks in partition */
  109. };
  110. struct extvtoc {
  111. uint64_t v_bootinfo[3]; /* info needed by mboot (unsupported) */
  112. uint64_t v_sanity; /* to verify vtoc sanity */
  113. uint64_t v_version; /* layout version */
  114. char v_volume[LEN_DKL_VVOL]; /* volume name */
  115. ushort_t v_sectorsz; /* sector size in bytes */
  116. ushort_t v_nparts; /* number of partitions */
  117. ushort_t pad[2];
  118. uint64_t v_reserved[10];
  119. struct extpartition v_part[V_NUMPAR]; /* partition headers */
  120. uint64_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported) */
  121. char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
  122. };
  123. #ifdef _KERNEL
  124. #define extvtoctovtoc(extv, v) \
  125. { \
  126. int i; \
  127. v.v_bootinfo[0] = (unsigned long)extv.v_bootinfo[0]; \
  128. v.v_bootinfo[1] = (unsigned long)extv.v_bootinfo[1]; \
  129. v.v_bootinfo[2] = (unsigned long)extv.v_bootinfo[2]; \
  130. v.v_sanity = (unsigned long)extv.v_sanity; \
  131. v.v_version = (unsigned long)extv.v_version; \
  132. bcopy(extv.v_volume, v.v_volume, LEN_DKL_VVOL); \
  133. v.v_sectorsz = extv.v_sectorsz; \
  134. v.v_nparts = extv.v_nparts; \
  135. for (i = 0; i < 10; i++) \
  136. v.v_reserved[i] = (unsigned long)extv.v_reserved[i]; \
  137. for (i = 0; i < V_NUMPAR; i++) { \
  138. v.v_part[i].p_tag = extv.v_part[i].p_tag; \
  139. v.v_part[i].p_flag = extv.v_part[i].p_flag; \
  140. v.v_part[i].p_start = (daddr_t)extv.v_part[i].p_start; \
  141. v.v_part[i].p_size = (long)extv.v_part[i].p_size; \
  142. v.timestamp[i] = (time_t)extv.timestamp[i]; \
  143. } \
  144. bcopy(extv.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII); \
  145. }
  146. #define vtoctoextvtoc(v, extv) \
  147. { \
  148. int i; \
  149. extv.v_bootinfo[0] = (uint64_t)v.v_bootinfo[0]; \
  150. extv.v_bootinfo[1] = (uint64_t)v.v_bootinfo[1]; \
  151. extv.v_bootinfo[2] = (uint64_t)v.v_bootinfo[2]; \
  152. extv.v_sanity = (uint64_t)v.v_sanity; \
  153. extv.v_version = (uint64_t)v.v_version; \
  154. bcopy(v.v_volume, extv.v_volume, LEN_DKL_VVOL); \
  155. extv.v_sectorsz = v.v_sectorsz; \
  156. extv.v_nparts = v.v_nparts; \
  157. for (i = 0; i < 10; i++) \
  158. extv.v_reserved[i] = (uint64_t)v.v_reserved[i]; \
  159. for (i = 0; i < V_NUMPAR; i++) { \
  160. extv.v_part[i].p_tag = v.v_part[i].p_tag; \
  161. extv.v_part[i].p_flag = v.v_part[i].p_flag; \
  162. extv.v_part[i].p_start = \
  163. (diskaddr_t)(unsigned long)v.v_part[i].p_start; \
  164. extv.v_part[i].p_size = \
  165. (diskaddr_t)(unsigned long)v.v_part[i].p_size; \
  166. extv.timestamp[i] = (uint64_t)v.timestamp[i]; \
  167. } \
  168. bcopy(v.v_asciilabel, extv.v_asciilabel, LEN_DKL_ASCII); \
  169. }
  170. #endif /* _KERNEL */
  171. #if defined(_SYSCALL32)
  172. struct partition32 {
  173. uint16_t p_tag; /* ID tag of partition */
  174. uint16_t p_flag; /* permission flags */
  175. daddr32_t p_start; /* start sector no of partition */
  176. int32_t p_size; /* # of blocks in partition */
  177. };
  178. struct vtoc32 {
  179. uint32_t v_bootinfo[3]; /* info needed by mboot (unsupported) */
  180. uint32_t v_sanity; /* to verify vtoc sanity */
  181. uint32_t v_version; /* layout version */
  182. char v_volume[LEN_DKL_VVOL]; /* volume name */
  183. uint16_t v_sectorsz; /* sector size in bytes */
  184. uint16_t v_nparts; /* number of partitions */
  185. uint32_t v_reserved[10]; /* free space */
  186. struct partition32 v_part[V_NUMPAR]; /* partition headers */
  187. time32_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported) */
  188. char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
  189. };
  190. #define vtoc32tovtoc(v32, v) \
  191. { \
  192. int i; \
  193. v.v_bootinfo[0] = v32.v_bootinfo[0]; \
  194. v.v_bootinfo[1] = v32.v_bootinfo[1]; \
  195. v.v_bootinfo[2] = v32.v_bootinfo[2]; \
  196. v.v_sanity = v32.v_sanity; \
  197. v.v_version = v32.v_version; \
  198. bcopy(v32.v_volume, v.v_volume, LEN_DKL_VVOL); \
  199. v.v_sectorsz = v32.v_sectorsz; \
  200. v.v_nparts = v32.v_nparts; \
  201. v.v_version = v32.v_version; \
  202. for (i = 0; i < 10; i++) \
  203. v.v_reserved[i] = v32.v_reserved[i]; \
  204. for (i = 0; i < V_NUMPAR; i++) { \
  205. v.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag; \
  206. v.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag; \
  207. v.v_part[i].p_start = (unsigned)v32.v_part[i].p_start; \
  208. v.v_part[i].p_size = (unsigned)v32.v_part[i].p_size; \
  209. } \
  210. for (i = 0; i < V_NUMPAR; i++) \
  211. v.timestamp[i] = (time_t)v32.timestamp[i]; \
  212. bcopy(v32.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII); \
  213. }
  214. #define vtoc32toextvtoc(v32, extv) \
  215. { \
  216. int i; \
  217. extv.v_bootinfo[0] = v32.v_bootinfo[0]; \
  218. extv.v_bootinfo[1] = v32.v_bootinfo[1]; \
  219. extv.v_bootinfo[2] = v32.v_bootinfo[2]; \
  220. extv.v_sanity = v32.v_sanity; \
  221. extv.v_version = v32.v_version; \
  222. bcopy(v32.v_volume, extv.v_volume, LEN_DKL_VVOL); \
  223. extv.v_sectorsz = v32.v_sectorsz; \
  224. extv.v_nparts = v32.v_nparts; \
  225. extv.v_version = v32.v_version; \
  226. for (i = 0; i < 10; i++) \
  227. extv.v_reserved[i] = v32.v_reserved[i]; \
  228. for (i = 0; i < V_NUMPAR; i++) { \
  229. extv.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag; \
  230. extv.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag; \
  231. extv.v_part[i].p_start = (diskaddr_t)v32.v_part[i].p_start; \
  232. extv.v_part[i].p_size = (diskaddr_t)v32.v_part[i].p_size; \
  233. extv.timestamp[i] = (time_t)v32.timestamp[i]; \
  234. } \
  235. bcopy(v32.v_asciilabel, extv.v_asciilabel, LEN_DKL_ASCII); \
  236. }
  237. #define vtoctovtoc32(v, v32) \
  238. { \
  239. int i; \
  240. v32.v_bootinfo[0] = v.v_bootinfo[0]; \
  241. v32.v_bootinfo[1] = v.v_bootinfo[1]; \
  242. v32.v_bootinfo[2] = v.v_bootinfo[2]; \
  243. v32.v_sanity = v.v_sanity; \
  244. v32.v_version = v.v_version; \
  245. bcopy(v.v_volume, v32.v_volume, LEN_DKL_VVOL); \
  246. v32.v_sectorsz = v.v_sectorsz; \
  247. v32.v_nparts = v.v_nparts; \
  248. v32.v_version = v.v_version; \
  249. for (i = 0; i < 10; i++) \
  250. v32.v_reserved[i] = v.v_reserved[i]; \
  251. for (i = 0; i < V_NUMPAR; i++) { \
  252. v32.v_part[i].p_tag = (ushort_t)v.v_part[i].p_tag; \
  253. v32.v_part[i].p_flag = (ushort_t)v.v_part[i].p_flag; \
  254. v32.v_part[i].p_start = (unsigned)v.v_part[i].p_start; \
  255. v32.v_part[i].p_size = (unsigned)v.v_part[i].p_size; \
  256. } \
  257. for (i = 0; i < V_NUMPAR; i++) { \
  258. if (v.timestamp[i] > TIME32_MAX) \
  259. v32.timestamp[i] = TIME32_MAX; \
  260. else \
  261. v32.timestamp[i] = (time32_t)v.timestamp[i]; \
  262. } \
  263. bcopy(v.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII); \
  264. }
  265. #define extvtoctovtoc32(extv, v32) \
  266. { \
  267. int i; \
  268. v32.v_bootinfo[0] = extv.v_bootinfo[0]; \
  269. v32.v_bootinfo[1] = extv.v_bootinfo[1]; \
  270. v32.v_bootinfo[2] = extv.v_bootinfo[2]; \
  271. v32.v_sanity = extv.v_sanity; \
  272. v32.v_version = extv.v_version; \
  273. bcopy(extv.v_volume, v32.v_volume, LEN_DKL_VVOL); \
  274. v32.v_sectorsz = extv.v_sectorsz; \
  275. v32.v_nparts = extv.v_nparts; \
  276. v32.v_version = extv.v_version; \
  277. for (i = 0; i < 10; i++) \
  278. v32.v_reserved[i] = extv.v_reserved[i]; \
  279. for (i = 0; i < V_NUMPAR; i++) { \
  280. v32.v_part[i].p_tag = (ushort_t)extv.v_part[i].p_tag; \
  281. v32.v_part[i].p_flag = (ushort_t)extv.v_part[i].p_flag; \
  282. v32.v_part[i].p_start = (unsigned)extv.v_part[i].p_start; \
  283. v32.v_part[i].p_size = (unsigned)extv.v_part[i].p_size; \
  284. } \
  285. for (i = 0; i < V_NUMPAR; i++) { \
  286. if (extv.timestamp[i] > TIME32_MAX) \
  287. v32.timestamp[i] = TIME32_MAX; \
  288. else \
  289. v32.timestamp[i] = (time32_t)extv.timestamp[i]; \
  290. } \
  291. bcopy(extv.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII); \
  292. }
  293. #endif /* _SYSCALL32 */
  294. /*
  295. * These defines are the mode parameter for the checksum routines.
  296. */
  297. #define CK_CHECKSUM 0 /* check checksum */
  298. #define CK_MAKESUM 1 /* generate checksum */
  299. #if defined(__STDC__)
  300. extern int read_vtoc(int, struct vtoc *);
  301. extern int write_vtoc(int, struct vtoc *);
  302. extern int read_extvtoc(int, struct extvtoc *);
  303. extern int write_extvtoc(int, struct extvtoc *);
  304. #else
  305. extern int read_vtoc();
  306. extern int write_vtoc();
  307. extern int read_extvtoc();
  308. extern int write_extvtoc();
  309. #endif /* __STDC__ */
  310. #ifdef __cplusplus
  311. }
  312. #endif
  313. #endif /* _SYS_VTOC_H */