geom_sunlabel_enc.c (113813) | geom_sunlabel_enc.c (113818) |
---|---|
1/*- 2 * Copyright (c) 2003 Jake Burkholder 3 * Copyright (c) 2003 Poul-Henning Kamp 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * | 1/*- 2 * Copyright (c) 2003 Jake Burkholder 3 * Copyright (c) 2003 Poul-Henning Kamp 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/sys/geom/geom_sunlabel_enc.c 113813 2003-04-21 18:41:12Z phk $ | 27 * $FreeBSD: head/sys/geom/geom_sunlabel_enc.c 113818 2003-04-21 19:42:36Z phk $ |
28 * 29 * Functions to encode or decode struct sun_disklabel into a bytestream 30 * of correct endianess and packing. 31 * 32 * NB! This file must be usable both in kernel and userland. 33 * 34 */ 35 --- 11 unchanged lines hidden (view full) --- 47#define SL_NCYLINDERS 0x1b0 48#define SL_ACYLINDERS 0x1b2 49#define SL_NTRACKS 0x1b4 50#define SL_NSECTORS 0x1b6 51#define SL_PART 0x1bc 52#define SL_MAGIC 0x1fc 53#define SL_CKSUM 0x1fe 54 | 28 * 29 * Functions to encode or decode struct sun_disklabel into a bytestream 30 * of correct endianess and packing. 31 * 32 * NB! This file must be usable both in kernel and userland. 33 * 34 */ 35 --- 11 unchanged lines hidden (view full) --- 47#define SL_NCYLINDERS 0x1b0 48#define SL_ACYLINDERS 0x1b2 49#define SL_NTRACKS 0x1b4 50#define SL_NSECTORS 0x1b6 51#define SL_PART 0x1bc 52#define SL_MAGIC 0x1fc 53#define SL_CKSUM 0x1fe 54 |
55#define SL_LENGTH 0x200 56 57#define SL_NPART 0x8 58 | |
59#define SDKP_CYLOFFSET 0 60#define SDKP_NSECTORS 0x4 61#define SDKP_SIZEOF 0x8 62 63/* 64 * Decode the relevant fields of a sun disk label, and return zero if the 65 * magic and checksum works out OK. 66 */ --- 10 unchanged lines hidden (view full) --- 77 sl->sl_rpm = be16dec(p + SL_RPM); 78 sl->sl_pcylinders = be16dec(p + SL_PCYLINDERS); 79 sl->sl_sparespercyl = be16dec(p + SL_SPARESPERCYL); 80 sl->sl_interleave = be16dec(p + SL_INTERLEAVE); 81 sl->sl_ncylinders = be16dec(p + SL_NCYLINDERS); 82 sl->sl_acylinders = be16dec(p + SL_ACYLINDERS); 83 sl->sl_ntracks = be16dec(p + SL_NTRACKS); 84 sl->sl_nsectors = be16dec(p + SL_NSECTORS); | 55#define SDKP_CYLOFFSET 0 56#define SDKP_NSECTORS 0x4 57#define SDKP_SIZEOF 0x8 58 59/* 60 * Decode the relevant fields of a sun disk label, and return zero if the 61 * magic and checksum works out OK. 62 */ --- 10 unchanged lines hidden (view full) --- 73 sl->sl_rpm = be16dec(p + SL_RPM); 74 sl->sl_pcylinders = be16dec(p + SL_PCYLINDERS); 75 sl->sl_sparespercyl = be16dec(p + SL_SPARESPERCYL); 76 sl->sl_interleave = be16dec(p + SL_INTERLEAVE); 77 sl->sl_ncylinders = be16dec(p + SL_NCYLINDERS); 78 sl->sl_acylinders = be16dec(p + SL_ACYLINDERS); 79 sl->sl_ntracks = be16dec(p + SL_NTRACKS); 80 sl->sl_nsectors = be16dec(p + SL_NSECTORS); |
85 for (i = 0; i < SL_NPART; i++) { | 81 for (i = 0; i < SUN_NPART; i++) { |
86 sl->sl_part[i].sdkp_cyloffset = be32dec(p + SL_PART + 87 (i * SDKP_SIZEOF) + SDKP_CYLOFFSET); 88 sl->sl_part[i].sdkp_nsectors = be32dec(p + SL_PART + 89 (i * SDKP_SIZEOF) + SDKP_NSECTORS); 90 } 91 sl->sl_magic = be16dec(p + SL_MAGIC); | 82 sl->sl_part[i].sdkp_cyloffset = be32dec(p + SL_PART + 83 (i * SDKP_SIZEOF) + SDKP_CYLOFFSET); 84 sl->sl_part[i].sdkp_nsectors = be32dec(p + SL_PART + 85 (i * SDKP_SIZEOF) + SDKP_NSECTORS); 86 } 87 sl->sl_magic = be16dec(p + SL_MAGIC); |
92 for (i = u = 0; i < SL_LENGTH; i += 2) | 88 for (i = u = 0; i < SUN_SIZE; i += 2) |
93 u ^= be16dec(p + i); 94 if (u == 0 && sl->sl_magic == SUN_DKMAGIC) 95 return (0); 96 else 97 return (EINVAL); 98} 99 100/* --- 12 unchanged lines hidden (view full) --- 113 be16enc(p + SL_RPM, sl->sl_rpm); 114 be16enc(p + SL_PCYLINDERS, sl->sl_pcylinders); 115 be16enc(p + SL_SPARESPERCYL, sl->sl_sparespercyl); 116 be16enc(p + SL_INTERLEAVE, sl->sl_interleave); 117 be16enc(p + SL_NCYLINDERS, sl->sl_ncylinders); 118 be16enc(p + SL_ACYLINDERS, sl->sl_acylinders); 119 be16enc(p + SL_NTRACKS, sl->sl_ntracks); 120 be16enc(p + SL_NSECTORS, sl->sl_nsectors); | 89 u ^= be16dec(p + i); 90 if (u == 0 && sl->sl_magic == SUN_DKMAGIC) 91 return (0); 92 else 93 return (EINVAL); 94} 95 96/* --- 12 unchanged lines hidden (view full) --- 109 be16enc(p + SL_RPM, sl->sl_rpm); 110 be16enc(p + SL_PCYLINDERS, sl->sl_pcylinders); 111 be16enc(p + SL_SPARESPERCYL, sl->sl_sparespercyl); 112 be16enc(p + SL_INTERLEAVE, sl->sl_interleave); 113 be16enc(p + SL_NCYLINDERS, sl->sl_ncylinders); 114 be16enc(p + SL_ACYLINDERS, sl->sl_acylinders); 115 be16enc(p + SL_NTRACKS, sl->sl_ntracks); 116 be16enc(p + SL_NSECTORS, sl->sl_nsectors); |
121 for (i = 0; i < SL_NPART; i++) { | 117 for (i = 0; i < SUN_NPART; i++) { |
122 be32enc(p + SL_PART + (i * SDKP_SIZEOF) + SDKP_CYLOFFSET, 123 sl->sl_part[i].sdkp_cyloffset); 124 be32enc(p + SL_PART + (i * SDKP_SIZEOF) + SDKP_NSECTORS, 125 sl->sl_part[i].sdkp_nsectors); 126 } 127 be16enc(p + SL_MAGIC, sl->sl_magic); | 118 be32enc(p + SL_PART + (i * SDKP_SIZEOF) + SDKP_CYLOFFSET, 119 sl->sl_part[i].sdkp_cyloffset); 120 be32enc(p + SL_PART + (i * SDKP_SIZEOF) + SDKP_NSECTORS, 121 sl->sl_part[i].sdkp_nsectors); 122 } 123 be16enc(p + SL_MAGIC, sl->sl_magic); |
128 for (i = u = 0; i < SL_LENGTH; i += 2) | 124 for (i = u = 0; i < SUN_SIZE; i += 2) |
129 u ^= be16dec(p + i); 130 be16enc(p + SL_CKSUM, u); 131} | 125 u ^= be16dec(p + i); 126 be16enc(p + SL_CKSUM, u); 127} |