geom_sunlabel_enc.c (139778) | geom_sunlabel_enc.c (144328) |
---|---|
1/*- 2 * Copyright (c) 2003 Jake Burkholder 3 * Copyright (c) 2003 Poul-Henning Kamp | 1/*- 2 * Copyright (c) 2003 Jake Burkholder 3 * Copyright (c) 2003 Poul-Henning Kamp |
4 * Copyright (c) 2004 Joerg Wunsch | 4 * Copyright (c) 2004,2005 Joerg Wunsch |
5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright --- 14 unchanged lines hidden (view full) --- 27 */ 28/* Functions to encode or decode struct sun_disklabel into a bytestream 29 * of correct endianess and packing. 30 * 31 * NB! This file must be usable both in kernel and userland. 32 */ 33 34#include <sys/cdefs.h> | 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright --- 14 unchanged lines hidden (view full) --- 27 */ 28/* Functions to encode or decode struct sun_disklabel into a bytestream 29 * of correct endianess and packing. 30 * 31 * NB! This file must be usable both in kernel and userland. 32 */ 33 34#include <sys/cdefs.h> |
35__FBSDID("$FreeBSD: head/sys/geom/geom_sunlabel_enc.c 139778 2005-01-06 18:27:30Z imp $"); | 35__FBSDID("$FreeBSD: head/sys/geom/geom_sunlabel_enc.c 144328 2005-03-30 09:33:10Z joerg $"); |
36 37#include <sys/types.h> 38#include <sys/endian.h> 39#include <sys/errno.h> 40#include <sys/sun_disklabel.h> | 36 37#include <sys/types.h> 38#include <sys/endian.h> 39#include <sys/errno.h> 40#include <sys/sun_disklabel.h> |
41#ifdef _KERNEL 42#include <sys/systm.h> 43#else 44#include <string.h> 45#endif |
|
41 42#define SL_TEXT 0x0 43#define SL_TEXT_SIZEOF 0x80 44#define SL_VTOC_VERS 0x80 | 46 47#define SL_TEXT 0x0 48#define SL_TEXT_SIZEOF 0x80 49#define SL_VTOC_VERS 0x80 |
50#define SL_VTOC_VOLNAME 0x84 |
|
45#define SL_VTOC_NPART 0x8c 46#define SL_VTOC_MAP 0x8e 47#define SL_VTOC_SANITY 0xbc 48#define SL_RPM 0x1a4 49#define SL_PCYLINDERS 0x1a6 50#define SL_SPARESPERCYL 0x1a8 51#define SL_INTERLEAVE 0x1ae 52#define SL_NCYLINDERS 0x1b0 --- 47 unchanged lines hidden (view full) --- 100 npart = be16dec(p + SL_VTOC_NPART); 101 if (vtocsane == SUN_VTOC_SANE && npart == SUN_NPART) { 102 /* 103 * Seems we've got SVR4-compatible VTOC information 104 * as well, decode it. 105 */ 106 sl->sl_vtoc_sane = vtocsane; 107 sl->sl_vtoc_vers = be32dec(p + SL_VTOC_VERS); | 51#define SL_VTOC_NPART 0x8c 52#define SL_VTOC_MAP 0x8e 53#define SL_VTOC_SANITY 0xbc 54#define SL_RPM 0x1a4 55#define SL_PCYLINDERS 0x1a6 56#define SL_SPARESPERCYL 0x1a8 57#define SL_INTERLEAVE 0x1ae 58#define SL_NCYLINDERS 0x1b0 --- 47 unchanged lines hidden (view full) --- 106 npart = be16dec(p + SL_VTOC_NPART); 107 if (vtocsane == SUN_VTOC_SANE && npart == SUN_NPART) { 108 /* 109 * Seems we've got SVR4-compatible VTOC information 110 * as well, decode it. 111 */ 112 sl->sl_vtoc_sane = vtocsane; 113 sl->sl_vtoc_vers = be32dec(p + SL_VTOC_VERS); |
114 memcpy(sl->sl_vtoc_volname, p + SL_VTOC_VOLNAME, 115 SUN_VOLNAME_LEN); |
|
108 sl->sl_vtoc_nparts = SUN_NPART; 109 for (i = 0; i < SUN_NPART; i++) { 110 sl->sl_vtoc_map[i].svtoc_tag = be16dec(p + 111 SL_VTOC_MAP + (i * SVTOC_SIZEOF) + SVTOC_TAG); 112 sl->sl_vtoc_map[i].svtoc_flag = be16dec(p + 113 SL_VTOC_MAP + (i * SVTOC_SIZEOF) + SVTOC_FLAG); 114 } 115 } --- 35 unchanged lines hidden (view full) --- 151 be16enc(p + SL_MAGIC, sl->sl_magic); 152 if (sl->sl_vtoc_sane == SUN_VTOC_SANE 153 && sl->sl_vtoc_nparts == SUN_NPART) { 154 /* 155 * Write SVR4-compatible VTOC elements. 156 */ 157 be32enc(p + SL_VTOC_VERS, sl->sl_vtoc_vers); 158 be32enc(p + SL_VTOC_SANITY, SUN_VTOC_SANE); | 116 sl->sl_vtoc_nparts = SUN_NPART; 117 for (i = 0; i < SUN_NPART; i++) { 118 sl->sl_vtoc_map[i].svtoc_tag = be16dec(p + 119 SL_VTOC_MAP + (i * SVTOC_SIZEOF) + SVTOC_TAG); 120 sl->sl_vtoc_map[i].svtoc_flag = be16dec(p + 121 SL_VTOC_MAP + (i * SVTOC_SIZEOF) + SVTOC_FLAG); 122 } 123 } --- 35 unchanged lines hidden (view full) --- 159 be16enc(p + SL_MAGIC, sl->sl_magic); 160 if (sl->sl_vtoc_sane == SUN_VTOC_SANE 161 && sl->sl_vtoc_nparts == SUN_NPART) { 162 /* 163 * Write SVR4-compatible VTOC elements. 164 */ 165 be32enc(p + SL_VTOC_VERS, sl->sl_vtoc_vers); 166 be32enc(p + SL_VTOC_SANITY, SUN_VTOC_SANE); |
167 memcpy(p + SL_VTOC_VOLNAME, sl->sl_vtoc_volname, 168 SUN_VOLNAME_LEN); |
|
159 be16enc(p + SL_VTOC_NPART, SUN_NPART); 160 for (i = 0; i < SUN_NPART; i++) { 161 be16enc(p + SL_VTOC_MAP + (i * SVTOC_SIZEOF) 162 + SVTOC_TAG, 163 sl->sl_vtoc_map[i].svtoc_tag); 164 be16enc(p + SL_VTOC_MAP + (i * SVTOC_SIZEOF) 165 + SVTOC_FLAG, 166 sl->sl_vtoc_map[i].svtoc_flag); 167 } 168 } 169 for (i = u = 0; i < SUN_SIZE; i += 2) 170 u ^= be16dec(p + i); 171 be16enc(p + SL_CKSUM, u); 172} | 169 be16enc(p + SL_VTOC_NPART, SUN_NPART); 170 for (i = 0; i < SUN_NPART; i++) { 171 be16enc(p + SL_VTOC_MAP + (i * SVTOC_SIZEOF) 172 + SVTOC_TAG, 173 sl->sl_vtoc_map[i].svtoc_tag); 174 be16enc(p + SL_VTOC_MAP + (i * SVTOC_SIZEOF) 175 + SVTOC_FLAG, 176 sl->sl_vtoc_map[i].svtoc_flag); 177 } 178 } 179 for (i = u = 0; i < SUN_SIZE; i += 2) 180 u ^= be16dec(p + i); 181 be16enc(p + SL_CKSUM, u); 182} |