diff options
Diffstat (limited to 'sys/geom/geom_bsd.c')
-rw-r--r-- | sys/geom/geom_bsd.c | 163 |
1 files changed, 82 insertions, 81 deletions
diff --git a/sys/geom/geom_bsd.c b/sys/geom/geom_bsd.c index f9e7df8..7565366 100644 --- a/sys/geom/geom_bsd.c +++ b/sys/geom/geom_bsd.c @@ -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(); |