Use <sys/endian.h> instead of geom_enc.c for endianess-agnostification.
This commit is contained in:
parent
dc4a64903a
commit
f186970d51
@ -78,9 +78,9 @@ struct g_apple_softc {
|
||||
static void
|
||||
g_dec_drvrdesc(u_char *ptr, struct g_apple_softc *sc)
|
||||
{
|
||||
sc->dd_bsiz = g_dec_be2(ptr + 2);
|
||||
sc->dd_blkcnt = g_dec_be4(ptr + 4);
|
||||
sc->dd_drvrcnt = g_dec_be4(ptr + 16);
|
||||
sc->dd_bsiz = be16dec(ptr + 2);
|
||||
sc->dd_blkcnt = be32dec(ptr + 4);
|
||||
sc->dd_drvrcnt = be32dec(ptr + 16);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -88,9 +88,9 @@ g_dec_apple_partition(u_char *ptr, struct apm_partition *d)
|
||||
{
|
||||
d->am_sig[0] = ptr[0];
|
||||
d->am_sig[1] = ptr[1];
|
||||
d->am_mapcnt = g_dec_be4(ptr + 4);
|
||||
d->am_start = g_dec_be4(ptr + 8);
|
||||
d->am_partcnt = g_dec_be4(ptr + 12);
|
||||
d->am_mapcnt = be32dec(ptr + 4);
|
||||
d->am_start = be32dec(ptr + 8);
|
||||
d->am_partcnt = be32dec(ptr + 12);
|
||||
memcpy(d->am_name, ptr + 16, 32);
|
||||
memcpy(d->am_type, ptr + 48, 32);
|
||||
}
|
||||
|
@ -40,6 +40,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/endian.h>
|
||||
#ifndef _KERNEL
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -90,12 +91,12 @@ struct g_bsd_softc {
|
||||
static void
|
||||
g_bsd_ledec_partition(u_char *ptr, struct partition *d)
|
||||
{
|
||||
d->p_size = g_dec_le4(ptr + 0);
|
||||
d->p_offset = g_dec_le4(ptr + 4);
|
||||
d->p_fsize = g_dec_le4(ptr + 8);
|
||||
d->p_size = le32dec(ptr + 0);
|
||||
d->p_offset = le32dec(ptr + 4);
|
||||
d->p_fsize = le32dec(ptr + 8);
|
||||
d->p_fstype = ptr[12];
|
||||
d->p_frag = ptr[13];
|
||||
d->p_cpg = g_dec_le2(ptr + 14);
|
||||
d->p_cpg = le16dec(ptr + 14);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -103,42 +104,42 @@ g_bsd_ledec_disklabel(u_char *ptr, struct disklabel *d)
|
||||
{
|
||||
int i;
|
||||
|
||||
d->d_magic = g_dec_le4(ptr + 0);
|
||||
d->d_type = g_dec_le2(ptr + 4);
|
||||
d->d_subtype = g_dec_le2(ptr + 6);
|
||||
d->d_magic = le32dec(ptr + 0);
|
||||
d->d_type = le16dec(ptr + 4);
|
||||
d->d_subtype = le16dec(ptr + 6);
|
||||
bcopy(ptr + 8, d->d_typename, 16);
|
||||
bcopy(ptr + 24, d->d_packname, 16);
|
||||
d->d_secsize = g_dec_le4(ptr + 40);
|
||||
d->d_nsectors = g_dec_le4(ptr + 44);
|
||||
d->d_ntracks = g_dec_le4(ptr + 48);
|
||||
d->d_ncylinders = g_dec_le4(ptr + 52);
|
||||
d->d_secpercyl = g_dec_le4(ptr + 56);
|
||||
d->d_secperunit = g_dec_le4(ptr + 60);
|
||||
d->d_sparespertrack = g_dec_le2(ptr + 64);
|
||||
d->d_sparespercyl = g_dec_le2(ptr + 66);
|
||||
d->d_acylinders = g_dec_le4(ptr + 68);
|
||||
d->d_rpm = g_dec_le2(ptr + 72);
|
||||
d->d_interleave = g_dec_le2(ptr + 74);
|
||||
d->d_trackskew = g_dec_le2(ptr + 76);
|
||||
d->d_cylskew = g_dec_le2(ptr + 78);
|
||||
d->d_headswitch = g_dec_le4(ptr + 80);
|
||||
d->d_trkseek = g_dec_le4(ptr + 84);
|
||||
d->d_flags = g_dec_le4(ptr + 88);
|
||||
d->d_drivedata[0] = g_dec_le4(ptr + 92);
|
||||
d->d_drivedata[1] = g_dec_le4(ptr + 96);
|
||||
d->d_drivedata[2] = g_dec_le4(ptr + 100);
|
||||
d->d_drivedata[3] = g_dec_le4(ptr + 104);
|
||||
d->d_drivedata[4] = g_dec_le4(ptr + 108);
|
||||
d->d_spare[0] = g_dec_le4(ptr + 112);
|
||||
d->d_spare[1] = g_dec_le4(ptr + 116);
|
||||
d->d_spare[2] = g_dec_le4(ptr + 120);
|
||||
d->d_spare[3] = g_dec_le4(ptr + 124);
|
||||
d->d_spare[4] = g_dec_le4(ptr + 128);
|
||||
d->d_magic2 = g_dec_le4(ptr + 132);
|
||||
d->d_checksum = g_dec_le2(ptr + 136);
|
||||
d->d_npartitions = g_dec_le2(ptr + 138);
|
||||
d->d_bbsize = g_dec_le4(ptr + 140);
|
||||
d->d_sbsize = g_dec_le4(ptr + 144);
|
||||
d->d_secsize = le32dec(ptr + 40);
|
||||
d->d_nsectors = le32dec(ptr + 44);
|
||||
d->d_ntracks = le32dec(ptr + 48);
|
||||
d->d_ncylinders = le32dec(ptr + 52);
|
||||
d->d_secpercyl = le32dec(ptr + 56);
|
||||
d->d_secperunit = le32dec(ptr + 60);
|
||||
d->d_sparespertrack = le16dec(ptr + 64);
|
||||
d->d_sparespercyl = le16dec(ptr + 66);
|
||||
d->d_acylinders = le32dec(ptr + 68);
|
||||
d->d_rpm = le16dec(ptr + 72);
|
||||
d->d_interleave = le16dec(ptr + 74);
|
||||
d->d_trackskew = le16dec(ptr + 76);
|
||||
d->d_cylskew = le16dec(ptr + 78);
|
||||
d->d_headswitch = le32dec(ptr + 80);
|
||||
d->d_trkseek = le32dec(ptr + 84);
|
||||
d->d_flags = le32dec(ptr + 88);
|
||||
d->d_drivedata[0] = le32dec(ptr + 92);
|
||||
d->d_drivedata[1] = le32dec(ptr + 96);
|
||||
d->d_drivedata[2] = le32dec(ptr + 100);
|
||||
d->d_drivedata[3] = le32dec(ptr + 104);
|
||||
d->d_drivedata[4] = le32dec(ptr + 108);
|
||||
d->d_spare[0] = le32dec(ptr + 112);
|
||||
d->d_spare[1] = le32dec(ptr + 116);
|
||||
d->d_spare[2] = le32dec(ptr + 120);
|
||||
d->d_spare[3] = le32dec(ptr + 124);
|
||||
d->d_spare[4] = le32dec(ptr + 128);
|
||||
d->d_magic2 = le32dec(ptr + 132);
|
||||
d->d_checksum = le16dec(ptr + 136);
|
||||
d->d_npartitions = le16dec(ptr + 138);
|
||||
d->d_bbsize = le32dec(ptr + 140);
|
||||
d->d_sbsize = le32dec(ptr + 144);
|
||||
for (i = 0; i < MAXPARTITIONS; i++)
|
||||
g_bsd_ledec_partition(ptr + 148 + 16 * i, &d->d_partitions[i]);
|
||||
}
|
||||
@ -146,12 +147,12 @@ g_bsd_ledec_disklabel(u_char *ptr, struct disklabel *d)
|
||||
static void
|
||||
g_bsd_leenc_partition(u_char *ptr, struct partition *d)
|
||||
{
|
||||
g_enc_le4(ptr + 0, d->p_size);
|
||||
g_enc_le4(ptr + 4, d->p_offset);
|
||||
g_enc_le4(ptr + 8, d->p_fsize);
|
||||
le32enc(ptr + 0, d->p_size);
|
||||
le32enc(ptr + 4, d->p_offset);
|
||||
le32enc(ptr + 8, d->p_fsize);
|
||||
ptr[12] = d->p_fstype;
|
||||
ptr[13] = d->p_frag;
|
||||
g_enc_le2(ptr + 14, d->p_cpg);
|
||||
le16enc(ptr + 14, d->p_cpg);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -159,42 +160,42 @@ g_bsd_leenc_disklabel(u_char *ptr, struct disklabel *d)
|
||||
{
|
||||
int i;
|
||||
|
||||
g_enc_le4(ptr + 0, d->d_magic);
|
||||
g_enc_le2(ptr + 4, d->d_type);
|
||||
g_enc_le2(ptr + 6, d->d_subtype);
|
||||
le32enc(ptr + 0, d->d_magic);
|
||||
le16enc(ptr + 4, d->d_type);
|
||||
le16enc(ptr + 6, d->d_subtype);
|
||||
bcopy(d->d_typename, ptr + 8, 16);
|
||||
bcopy(d->d_packname, ptr + 24, 16);
|
||||
g_enc_le4(ptr + 40, d->d_secsize);
|
||||
g_enc_le4(ptr + 44, d->d_nsectors);
|
||||
g_enc_le4(ptr + 48, d->d_ntracks);
|
||||
g_enc_le4(ptr + 52, d->d_ncylinders);
|
||||
g_enc_le4(ptr + 56, d->d_secpercyl);
|
||||
g_enc_le4(ptr + 60, d->d_secperunit);
|
||||
g_enc_le2(ptr + 64, d->d_sparespertrack);
|
||||
g_enc_le2(ptr + 66, d->d_sparespercyl);
|
||||
g_enc_le4(ptr + 68, d->d_acylinders);
|
||||
g_enc_le2(ptr + 72, d->d_rpm);
|
||||
g_enc_le2(ptr + 74, d->d_interleave);
|
||||
g_enc_le2(ptr + 76, d->d_trackskew);
|
||||
g_enc_le2(ptr + 78, d->d_cylskew);
|
||||
g_enc_le4(ptr + 80, d->d_headswitch);
|
||||
g_enc_le4(ptr + 84, d->d_trkseek);
|
||||
g_enc_le4(ptr + 88, d->d_flags);
|
||||
g_enc_le4(ptr + 92, d->d_drivedata[0]);
|
||||
g_enc_le4(ptr + 96, d->d_drivedata[1]);
|
||||
g_enc_le4(ptr + 100, d->d_drivedata[2]);
|
||||
g_enc_le4(ptr + 104, d->d_drivedata[3]);
|
||||
g_enc_le4(ptr + 108, d->d_drivedata[4]);
|
||||
g_enc_le4(ptr + 112, d->d_spare[0]);
|
||||
g_enc_le4(ptr + 116, d->d_spare[1]);
|
||||
g_enc_le4(ptr + 120, d->d_spare[2]);
|
||||
g_enc_le4(ptr + 124, d->d_spare[3]);
|
||||
g_enc_le4(ptr + 128, d->d_spare[4]);
|
||||
g_enc_le4(ptr + 132, d->d_magic2);
|
||||
g_enc_le2(ptr + 136, d->d_checksum);
|
||||
g_enc_le2(ptr + 138, d->d_npartitions);
|
||||
g_enc_le4(ptr + 140, d->d_bbsize);
|
||||
g_enc_le4(ptr + 144, d->d_sbsize);
|
||||
le32enc(ptr + 40, d->d_secsize);
|
||||
le32enc(ptr + 44, d->d_nsectors);
|
||||
le32enc(ptr + 48, d->d_ntracks);
|
||||
le32enc(ptr + 52, d->d_ncylinders);
|
||||
le32enc(ptr + 56, d->d_secpercyl);
|
||||
le32enc(ptr + 60, d->d_secperunit);
|
||||
le16enc(ptr + 64, d->d_sparespertrack);
|
||||
le16enc(ptr + 66, d->d_sparespercyl);
|
||||
le32enc(ptr + 68, d->d_acylinders);
|
||||
le16enc(ptr + 72, d->d_rpm);
|
||||
le16enc(ptr + 74, d->d_interleave);
|
||||
le16enc(ptr + 76, d->d_trackskew);
|
||||
le16enc(ptr + 78, d->d_cylskew);
|
||||
le32enc(ptr + 80, d->d_headswitch);
|
||||
le32enc(ptr + 84, d->d_trkseek);
|
||||
le32enc(ptr + 88, d->d_flags);
|
||||
le32enc(ptr + 92, d->d_drivedata[0]);
|
||||
le32enc(ptr + 96, d->d_drivedata[1]);
|
||||
le32enc(ptr + 100, d->d_drivedata[2]);
|
||||
le32enc(ptr + 104, d->d_drivedata[3]);
|
||||
le32enc(ptr + 108, d->d_drivedata[4]);
|
||||
le32enc(ptr + 112, d->d_spare[0]);
|
||||
le32enc(ptr + 116, d->d_spare[1]);
|
||||
le32enc(ptr + 120, d->d_spare[2]);
|
||||
le32enc(ptr + 124, d->d_spare[3]);
|
||||
le32enc(ptr + 128, d->d_spare[4]);
|
||||
le32enc(ptr + 132, d->d_magic2);
|
||||
le16enc(ptr + 136, d->d_checksum);
|
||||
le16enc(ptr + 138, d->d_npartitions);
|
||||
le32enc(ptr + 140, d->d_bbsize);
|
||||
le32enc(ptr + 144, d->d_sbsize);
|
||||
for (i = 0; i < MAXPARTITIONS; i++)
|
||||
g_bsd_leenc_partition(ptr + 148 + 16 * i, &d->d_partitions[i]);
|
||||
}
|
||||
@ -411,7 +412,7 @@ g_bsd_lesum(struct disklabel *dl, u_char *p)
|
||||
pe = p + 148 + 16 * dl->d_npartitions;
|
||||
sum = 0;
|
||||
while (p < pe) {
|
||||
sum ^= g_dec_le2(p);
|
||||
sum ^= le16dec(p);
|
||||
p += 2;
|
||||
}
|
||||
return (sum);
|
||||
@ -540,8 +541,8 @@ g_bsd_ioctl(void *arg, int flag)
|
||||
if (ms->labeloffset == ALPHA_LABEL_OFFSET) {
|
||||
sum = 0;
|
||||
for (i = 0; i < 63; i++)
|
||||
sum += g_dec_le8(buf + i * 8);
|
||||
g_enc_le8(buf + 504, sum);
|
||||
sum += le64dec(buf + i * 8);
|
||||
le64enc(buf + 504, sum);
|
||||
}
|
||||
error = g_write_data(cp, ms->labeloffset - secoff, buf, secsize);
|
||||
g_free(buf);
|
||||
@ -594,8 +595,8 @@ g_bsd_diocbsdbb(dev_t dev, u_long cmd __unused, caddr_t data, int fflag __unused
|
||||
if (ms->labeloffset == ALPHA_LABEL_OFFSET) {
|
||||
sum = 0;
|
||||
for (i = 0; i < 63; i++)
|
||||
sum += g_dec_le8(buf + i * 8);
|
||||
g_enc_le8(buf + 504, sum);
|
||||
sum += le64dec(buf + i * 8);
|
||||
le64enc(buf + 504, sum);
|
||||
}
|
||||
error = g_write_data(cp, 0, buf, BBSIZE);
|
||||
g_topology_unlock();
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/endian.h>
|
||||
#ifndef _KERNEL
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -93,8 +94,8 @@ g_dec_dos_partition(u_char *ptr, struct dos_partition *d)
|
||||
d->dp_ehd = ptr[5];
|
||||
d->dp_esect = ptr[6];
|
||||
d->dp_ecyl = ptr[7];
|
||||
d->dp_start = g_dec_le4(ptr + 8);
|
||||
d->dp_size = g_dec_le4(ptr + 12);
|
||||
d->dp_start = le32dec(ptr + 8);
|
||||
d->dp_size = le32dec(ptr + 12);
|
||||
}
|
||||
|
||||
struct g_mbr_softc {
|
||||
|
@ -65,13 +65,13 @@ g_dec_pc98_partition(u_char *ptr, struct pc98_partition *d)
|
||||
d->dp_dum2 = ptr[3];
|
||||
d->dp_ipl_sct = ptr[4];
|
||||
d->dp_ipl_head = ptr[5];
|
||||
d->dp_ipl_cyl = g_dec_le2(ptr + 6);
|
||||
d->dp_ipl_cyl = le16dec(ptr + 6);
|
||||
d->dp_ssect = ptr[8];
|
||||
d->dp_shd = ptr[9];
|
||||
d->dp_scyl = g_dec_le2(ptr + 10);
|
||||
d->dp_scyl = le16dec(ptr + 10);
|
||||
d->dp_esect = ptr[12];
|
||||
d->dp_ehd = ptr[13];
|
||||
d->dp_ecyl = g_dec_le2(ptr + 14);
|
||||
d->dp_ecyl = le16dec(ptr + 14);
|
||||
for (u = 0; u < sizeof(d->dp_name); u++)
|
||||
d->dp_name[u] = ptr[16 + u];
|
||||
}
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/endian.h>
|
||||
#ifndef _KERNEL
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -73,21 +74,21 @@ g_sunlabel_modify(struct g_geom *gp, struct g_sunlabel_softc *ms, u_char *sec0)
|
||||
u_int u, v, csize;
|
||||
|
||||
/* The second last short is a magic number */
|
||||
if (g_dec_be2(sec0 + 508) != 0xdabe)
|
||||
if (be16dec(sec0 + 508) != 0xdabe)
|
||||
return (EBUSY);
|
||||
|
||||
/* The shortword parity of the entire thing must be even */
|
||||
u = 0;
|
||||
for (i = 0; i < 512; i += 2)
|
||||
u ^= g_dec_be2(sec0 + i);
|
||||
u ^= be16dec(sec0 + i);
|
||||
if (u != 0)
|
||||
return(EBUSY);
|
||||
|
||||
csize = g_dec_be2(sec0 + 436) * g_dec_be2(sec0 + 438);
|
||||
csize = be16dec(sec0 + 436) * be16dec(sec0 + 438);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
v = g_dec_be4(sec0 + 444 + i * 8);
|
||||
u = g_dec_be4(sec0 + 448 + i * 8);
|
||||
v = be32dec(sec0 + 444 + i * 8);
|
||||
u = be32dec(sec0 + 448 + i * 8);
|
||||
g_topology_lock();
|
||||
error = g_slice_config(gp, i, G_SLICE_CONFIG_CHECK,
|
||||
((off_t)v * csize) << 9ULL,
|
||||
@ -99,8 +100,8 @@ g_sunlabel_modify(struct g_geom *gp, struct g_sunlabel_softc *ms, u_char *sec0)
|
||||
return (error);
|
||||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
v = g_dec_be4(sec0 + 444 + i * 8);
|
||||
u = g_dec_be4(sec0 + 448 + i * 8);
|
||||
v = be32dec(sec0 + 444 + i * 8);
|
||||
u = be32dec(sec0 + 448 + i * 8);
|
||||
g_topology_lock();
|
||||
g_slice_config(gp, i, G_SLICE_CONFIG_SET,
|
||||
((off_t)v * csize) << 9ULL,
|
||||
@ -109,9 +110,9 @@ g_sunlabel_modify(struct g_geom *gp, struct g_sunlabel_softc *ms, u_char *sec0)
|
||||
"%s%c", gp->name, 'a' + i);
|
||||
g_topology_unlock();
|
||||
}
|
||||
ms->nalt = g_dec_be2(sec0 + 434);
|
||||
ms->nheads = g_dec_be2(sec0 + 436);
|
||||
ms->nsects = g_dec_be2(sec0 + 438);
|
||||
ms->nalt = be16dec(sec0 + 434);
|
||||
ms->nheads = be16dec(sec0 + 436);
|
||||
ms->nsects = be16dec(sec0 + 438);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -183,24 +184,24 @@ g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags)
|
||||
g_hexdump(buf, 128);
|
||||
for (i = 0; i < 8; i++) {
|
||||
printf("part %d %u %u\n", i,
|
||||
g_dec_be4(buf + 444 + i * 8),
|
||||
g_dec_be4(buf + 448 + i * 8));
|
||||
be32dec(buf + 444 + i * 8),
|
||||
be32dec(buf + 448 + i * 8));
|
||||
}
|
||||
printf("v_version = %d\n", g_dec_be4(buf + 128));
|
||||
printf("v_nparts = %d\n", g_dec_be2(buf + 140));
|
||||
printf("v_version = %d\n", be32dec(buf + 128));
|
||||
printf("v_nparts = %d\n", be16dec(buf + 140));
|
||||
for (i = 0; i < 8; i++) {
|
||||
printf("v_part[%d] = %d %d\n",
|
||||
i, g_dec_be2(buf + 142 + i * 4),
|
||||
g_dec_be2(buf + 144 + i * 4));
|
||||
i, be16dec(buf + 142 + i * 4),
|
||||
be16dec(buf + 144 + i * 4));
|
||||
}
|
||||
printf("v_sanity %x\n", g_dec_be4(buf + 186));
|
||||
printf("v_version = %d\n", g_dec_be4(buf + 128));
|
||||
printf("v_rpm %d\n", g_dec_be2(buf + 420));
|
||||
printf("v_totalcyl %d\n", g_dec_be2(buf + 422));
|
||||
printf("v_cyl %d\n", g_dec_be2(buf + 432));
|
||||
printf("v_alt %d\n", g_dec_be2(buf + 434));
|
||||
printf("v_head %d\n", g_dec_be2(buf + 436));
|
||||
printf("v_sec %d\n", g_dec_be2(buf + 438));
|
||||
printf("v_sanity %x\n", be32dec(buf + 186));
|
||||
printf("v_version = %d\n", be32dec(buf + 128));
|
||||
printf("v_rpm %d\n", be16dec(buf + 420));
|
||||
printf("v_totalcyl %d\n", be16dec(buf + 422));
|
||||
printf("v_cyl %d\n", be16dec(buf + 432));
|
||||
printf("v_alt %d\n", be16dec(buf + 434));
|
||||
printf("v_head %d\n", be16dec(buf + 436));
|
||||
printf("v_sec %d\n", be16dec(buf + 438));
|
||||
}
|
||||
|
||||
g_sunlabel_modify(gp, ms, buf);
|
||||
|
Loading…
Reference in New Issue
Block a user