Deleted Added
full compact
geom_sunlabel_enc.c (116196) geom_sunlabel_enc.c (129963)
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 * 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:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright

--- 14 unchanged lines hidden (view full) ---

26 *
27 * Functions to encode or decode struct sun_disklabel into a bytestream
28 * of correct endianess and packing.
29 *
30 * NB! This file must be usable both in kernel and userland.
31 */
32
33#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>
34__FBSDID("$FreeBSD: head/sys/geom/geom_sunlabel_enc.c 116196 2003-06-11 06:49:16Z obrien $");
35__FBSDID("$FreeBSD: head/sys/geom/geom_sunlabel_enc.c 129963 2004-06-01 20:18:25Z joerg $");
35
36#include <sys/types.h>
37#include <sys/endian.h>
38#include <sys/errno.h>
39#include <sys/sun_disklabel.h>
40
41#define SL_TEXT 0x0
42#define SL_TEXT_SIZEOF 0x80
36
37#include <sys/types.h>
38#include <sys/endian.h>
39#include <sys/errno.h>
40#include <sys/sun_disklabel.h>
41
42#define SL_TEXT 0x0
43#define SL_TEXT_SIZEOF 0x80
44#define SL_VTOC_VERS 0x80
45#define SL_VTOC_NPART 0x8c
46#define SL_VTOC_MAP 0x8e
47#define SL_VTOC_SANITY 0xbc
43#define SL_RPM 0x1a4
44#define SL_PCYLINDERS 0x1a6
45#define SL_SPARESPERCYL 0x1a8
46#define SL_INTERLEAVE 0x1ae
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 SDKP_CYLOFFSET 0
56#define SDKP_NSECTORS 0x4
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
53#define SL_ACYLINDERS 0x1b2
54#define SL_NTRACKS 0x1b4
55#define SL_NSECTORS 0x1b6
56#define SL_PART 0x1bc
57#define SL_MAGIC 0x1fc
58#define SL_CKSUM 0x1fe
59
60#define SDKP_CYLOFFSET 0
61#define SDKP_NSECTORS 0x4
57#define SDKP_SIZEOF 0x8
62#define SDKP_SIZEOF 0x8 /* size of a partition entry */
58
63
64#define SVTOC_TAG 0
65#define SVTOC_FLAG 0x2
66#define SVTOC_SIZEOF 0x4 /* size of a VTOC tag/flag entry */
67
59/*
60 * Decode the relevant fields of a sun disk label, and return zero if the
61 * magic and checksum works out OK.
62 */
63int
64sunlabel_dec(void const *pp, struct sun_disklabel *sl)
65{
66 const uint8_t *p;
67 size_t i;
68 u_int u;
68/*
69 * Decode the relevant fields of a sun disk label, and return zero if the
70 * magic and checksum works out OK.
71 */
72int
73sunlabel_dec(void const *pp, struct sun_disklabel *sl)
74{
75 const uint8_t *p;
76 size_t i;
77 u_int u;
78 uint32_t vtocsane;
79 uint16_t npart;
69
70 p = pp;
71 for (i = 0; i < sizeof(sl->sl_text); i++)
72 sl->sl_text[i] = p[SL_TEXT + i];
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);
81 for (i = 0; i < SUN_NPART; i++) {
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);
80
81 p = pp;
82 for (i = 0; i < sizeof(sl->sl_text); i++)
83 sl->sl_text[i] = p[SL_TEXT + i];
84 sl->sl_rpm = be16dec(p + SL_RPM);
85 sl->sl_pcylinders = be16dec(p + SL_PCYLINDERS);
86 sl->sl_sparespercyl = be16dec(p + SL_SPARESPERCYL);
87 sl->sl_interleave = be16dec(p + SL_INTERLEAVE);
88 sl->sl_ncylinders = be16dec(p + SL_NCYLINDERS);
89 sl->sl_acylinders = be16dec(p + SL_ACYLINDERS);
90 sl->sl_ntracks = be16dec(p + SL_NTRACKS);
91 sl->sl_nsectors = be16dec(p + SL_NSECTORS);
92 for (i = 0; i < SUN_NPART; i++) {
93 sl->sl_part[i].sdkp_cyloffset = be32dec(p + SL_PART +
94 (i * SDKP_SIZEOF) + SDKP_CYLOFFSET);
95 sl->sl_part[i].sdkp_nsectors = be32dec(p + SL_PART +
96 (i * SDKP_SIZEOF) + SDKP_NSECTORS);
97 }
98 sl->sl_magic = be16dec(p + SL_MAGIC);
99 vtocsane = be32dec(p + SL_VTOC_SANITY);
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);
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 }
88 for (i = u = 0; i < SUN_SIZE; i += 2)
89 u ^= be16dec(p + i);
90 if (u == 0 && sl->sl_magic == SUN_DKMAGIC)
91 return (0);
92 else
93 return (EINVAL);
94}
95

--- 20 unchanged lines hidden (view full) ---

116 be16enc(p + SL_NSECTORS, sl->sl_nsectors);
117 for (i = 0; i < SUN_NPART; i++) {
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);
116 for (i = u = 0; i < SUN_SIZE; i += 2)
117 u ^= be16dec(p + i);
118 if (u == 0 && sl->sl_magic == SUN_DKMAGIC)
119 return (0);
120 else
121 return (EINVAL);
122}
123

--- 20 unchanged lines hidden (view full) ---

144 be16enc(p + SL_NSECTORS, sl->sl_nsectors);
145 for (i = 0; i < SUN_NPART; i++) {
146 be32enc(p + SL_PART + (i * SDKP_SIZEOF) + SDKP_CYLOFFSET,
147 sl->sl_part[i].sdkp_cyloffset);
148 be32enc(p + SL_PART + (i * SDKP_SIZEOF) + SDKP_NSECTORS,
149 sl->sl_part[i].sdkp_nsectors);
150 }
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);
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 }
124 for (i = u = 0; i < SUN_SIZE; i += 2)
125 u ^= be16dec(p + i);
126 be16enc(p + SL_CKSUM, u);
127}
169 for (i = u = 0; i < SUN_SIZE; i += 2)
170 u ^= be16dec(p + i);
171 be16enc(p + SL_CKSUM, u);
172}