most hardware and most of the kernel has given up on cylinders
meaning anything, we generally work in logical block addresses now.
now that disksort is (almost) gone it is no longer used for anything
meaningful except in floppy disk drivers.

the #define b_cylinder b_resid alias has always grated on me, so
this removes it. the big fallout is in the fd drivers, so they now
keep track of how much of a buf theyve handled by using resid to
store a resid.

ive tested this on sys/dev/isa/fd.c, and compiled it on sparc64. a
compile on sparc would be appreciated, and any further hardware
tests.

this relies on the previous diff i sent out to remove disksort
because that previous diff removed a use of b_cylinder. it shouldnt
compile with that b_cylinder in there.

ok?

Index: arch/amd64/amd64/dkcsum.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/dkcsum.c,v
retrieving revision 1.19
diff -u -p -r1.19 dkcsum.c
--- arch/amd64/amd64/dkcsum.c   27 Jun 2011 01:14:24 -0000      1.19
+++ arch/amd64/amd64/dkcsum.c   20 Nov 2013 10:02:46 -0000
@@ -116,7 +116,6 @@ dkcsumattach(void)
                bp->b_error = 0; /* B_ERROR and b_error may have stale data. */
                CLR(bp->b_flags, B_READ | B_WRITE | B_DONE | B_ERROR);
                SET(bp->b_flags, B_BUSY | B_READ | B_RAW);
-               bp->b_cylinder = 0;
                (*bdsw->d_strategy)(bp);
                if ((error = biowait(bp))) {
                        /* XXX What to do here? */
Index: arch/i386/i386/dkcsum.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/dkcsum.c,v
retrieving revision 1.30
diff -u -p -r1.30 dkcsum.c
--- arch/i386/i386/dkcsum.c     27 Jun 2011 01:14:24 -0000      1.30
+++ arch/i386/i386/dkcsum.c     20 Nov 2013 10:02:46 -0000
@@ -116,7 +116,6 @@ dkcsumattach(void)
                bp->b_error = 0; /* B_ERROR and b_error may have stale data. */
                CLR(bp->b_flags, B_READ | B_WRITE | B_DONE | B_ERROR);
                SET(bp->b_flags, B_BUSY | B_READ | B_RAW);
-               bp->b_cylinder = 0;
                (*bdsw->d_strategy)(bp);
                if ((error = biowait(bp))) {
                        /* XXX What to do here? */
Index: arch/sparc/dev/fd.c
===================================================================
RCS file: /cvs/src/sys/arch/sparc/dev/fd.c,v
retrieving revision 1.87
diff -u -p -r1.87 fd.c
--- arch/sparc/dev/fd.c 18 Nov 2013 01:56:35 -0000      1.87
+++ arch/sparc/dev/fd.c 20 Nov 2013 10:02:46 -0000
@@ -705,6 +705,7 @@ fdstrategy(bp)
        if (bp->b_bcount == 0)
                goto done;
 
+       bp->b_resid = bp->b_count;
        sz = howmany(bp->b_bcount, DEV_BSIZE);
 
        if (bp->b_blkno + sz > (fd->sc_type->size * DEV_BSIZE) / FD_BSIZE(fd)) {
@@ -712,7 +713,6 @@ fdstrategy(bp)
                    - bp->b_blkno;
                if (sz == 0) {
                        /* If exactly at end of disk, return EOF. */
-                       bp->b_resid = bp->b_bcount;
                        goto done;
                }
                if (sz < 0) {
@@ -724,14 +724,11 @@ fdstrategy(bp)
                bp->b_bcount = sz << DEV_BSHIFT;
        }
 
-       bp->b_cylinder = (bp->b_blkno * DEV_BSIZE) /
-           (FD_BSIZE(fd) * fd->sc_type->seccyl);
-
 #ifdef FD_DEBUG
        if (fdc_debug > 1)
-           printf("fdstrategy: b_blkno %lld b_bcount %ld blkno %lld "
-               "cylin %ld\n", (long long)bp->b_blkno, bp->b_bcount,
-               (long long)fd->sc_blkno, bp->b_cylinder);
+           printf("fdstrategy: b_blkno %lld b_bcount %ld blkno %lld\n",
+               (long long)bp->b_blkno, bp->b_bcount,
+               (long long)fd->sc_blkno);
 #endif
 
        /* Queue transfer */
@@ -802,7 +799,6 @@ fdfinish(fd, bp)
                        TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
        }
 
-       bp->b_resid = fd->sc_bcount;
        biodone(bp);
        /* turn off motor 5s from now */
        timeout_add_sec(&fd->fd_motor_off_to, 5);
@@ -1262,11 +1258,10 @@ fdcstate(fdc)
 
        struct fd_softc *fd;
        struct buf *bp;
-       int read, head, sec, nblks;
+       int read, head, sec, nblks, cylin;
        struct fd_type *type;
        struct fd_formb *finfo = NULL;
 
-
        if (fdc->sc_istatus == FDC_ISTATUS_ERROR) {
                /* Prevent loop if the reset sequence produces errors */
                if (fdc->sc_state != RESETCOMPLETE &&
@@ -1295,6 +1290,9 @@ loop:
                goto loop;
        }
 
+       cylin = ((bp->b_blkno * DEV_BSIZE) + (bp->b_bcount - bp->b_resid)) /
+           (FD_BSIZE(fd) * fd->sc_type->seccyl);
+
        if (bp->b_flags & B_FORMAT)
                finfo = (struct fd_formb *)bp->b_data;
 
@@ -1336,12 +1334,12 @@ loop:
        doseek:
                if ((fdc->sc_flags & FDC_EIS) &&
                    (bp->b_flags & B_FORMAT) == 0) {
-                       fd->sc_cylin = bp->b_cylinder;
+                       fd->sc_cylin = cylin;
                        /* We use implied seek */
                        goto doio;
                }
 
-               if (fd->sc_cylin == bp->b_cylinder)
+               if (fd->sc_cylin == cylin)
                        goto doio;
 
                fd->sc_cylin = -1;
@@ -1363,7 +1361,7 @@ loop:
                /* seek function */
                FDC_WRFIFO(fdc, NE7CMD_SEEK);
                FDC_WRFIFO(fdc, fd->sc_drive); /* drive number */
-               FDC_WRFIFO(fdc, bp->b_cylinder * fd->sc_type->step);
+               FDC_WRFIFO(fdc, cylin * fd->sc_type->step);
 
                return (1);
 
@@ -1459,7 +1457,7 @@ loop:
 
                /* Make sure seek really happened. */
                if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 ||
-                   cyl != bp->b_cylinder * fd->sc_type->step) {
+                   cyl != cylin * fd->sc_type->step) {
 #ifdef FD_DEBUG
                        if (fdc_debug)
                                fdcstatus(fdc, "seek failed");
@@ -1467,7 +1465,7 @@ loop:
                        fdcretry(fdc);
                        goto loop;
                }
-               fd->sc_cylin = bp->b_cylinder;
+               fd->sc_cylin = cylin;
                goto doio;
 
        case IOTIMEDOUT:
@@ -1574,8 +1572,9 @@ loop:
                fd->sc_blkno += fd->sc_nblks;
                fd->sc_skip += fd->sc_nbytes;
                fd->sc_bcount -= fd->sc_nbytes;
+               bp->b_resid -= fd->sc_nbytes;
                if (finfo == NULL && fd->sc_bcount > 0) {
-                       bp->b_cylinder = fd->sc_blkno / fd->sc_type->seccyl;
+                       cylin = fd->sc_blkno / fd->sc_type->seccyl;
                        goto doseek;
                }
                fdfinish(fd, bp);
@@ -1723,6 +1722,7 @@ fdcretry(fdc)
        failsilent:
                bp->b_flags |= B_ERROR;
                bp->b_error = error;
+               bp->b_resid = bp->b_bcount;
                fdfinish(fd, bp);
        }
        fdc->sc_errors++;
Index: arch/sparc64/dev/fd.c
===================================================================
RCS file: /cvs/src/sys/arch/sparc64/dev/fd.c,v
retrieving revision 1.42
diff -u -p -r1.42 fd.c
--- arch/sparc64/dev/fd.c       2 Nov 2013 22:58:49 -0000       1.42
+++ arch/sparc64/dev/fd.c       20 Nov 2013 10:02:46 -0000
@@ -725,6 +725,7 @@ fdstrategy(bp)
        if (bp->b_bcount == 0)
                goto done;
 
+       bp->b_resid = bp->b_bcount;
        sz = howmany(bp->b_bcount, DEV_BSIZE);
 
        if (bp->b_blkno + sz > (fd->sc_type->size * DEV_BSIZE) / FD_BSIZE(fd)) {
@@ -732,7 +733,6 @@ fdstrategy(bp)
                     - bp->b_blkno;
                if (sz == 0) {
                        /* If exactly at end of disk, return EOF. */
-                       bp->b_resid = bp->b_bcount;
                        goto done;
                }
                if (sz < 0) {
@@ -744,14 +744,11 @@ fdstrategy(bp)
                bp->b_bcount = sz << DEV_BSHIFT;
        }
 
-       bp->b_cylinder = (bp->b_blkno * DEV_BSIZE) /
-           (FD_BSIZE(fd) * fd->sc_type->seccyl);
-
 #ifdef FD_DEBUG
        if (fdc_debug > 1)
-           printf("fdstrategy: b_blkno %lld b_bcount %d blkno %lld cylin %d\n",
+           printf("fdstrategy: b_blkno %lld b_bcount %d blkno %lld\n",
                    (long long)bp->b_blkno, bp->b_bcount,
-                   (long long)fd->sc_blkno, bp->b_cylinder);
+                   (long long)fd->sc_blkno);
 #endif
 
        /* Queue transfer */
@@ -822,7 +819,6 @@ fdfinish(fd, bp)
                        TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
        }
 
-       bp->b_resid = fd->sc_bcount;
        biodone(bp);
        /* turn off motor 5s from now */
        timeout_add_sec(&fd->sc_motoroff_to, 5);
@@ -1295,7 +1291,7 @@ fdcstate(fdc)
 
        struct fd_softc *fd;
        struct buf *bp;
-       int read, head, sec, nblks;
+       int read, head, sec, nblks, cylin;
        struct fd_type *type;
        struct fd_formb *finfo = NULL;
 
@@ -1330,6 +1326,9 @@ loop:
        if (bp->b_flags & B_FORMAT)
                finfo = (struct fd_formb *)bp->b_data;
 
+       cylin = ((bp->b_blkno * DEV_BSIZE) - (bp->b_bcount - bp->b_resid)) /
+           (FD_BSIZE(fd) * fd->sc_type->seccyl);
+
        switch (fdc->sc_state) {
        case DEVIDLE:
                fdc->sc_errors = 0;
@@ -1371,12 +1370,12 @@ loop:
        doseek:
                if ((fdc->sc_flags & FDC_EIS) &&
                    (bp->b_flags & B_FORMAT) == 0) {
-                       fd->sc_cylin = bp->b_cylinder;
+                       fd->sc_cylin = cylin;
                        /* We use implied seek */
                        goto doio;
                }
 
-               if (fd->sc_cylin == bp->b_cylinder)
+               if (fd->sc_cylin == cylin);
                        goto doio;
 
                fd->sc_cylin = -1;
@@ -1398,7 +1397,7 @@ loop:
                /* seek function */
                FDC_WRFIFO(fdc, NE7CMD_SEEK);
                FDC_WRFIFO(fdc, fd->sc_drive); /* drive number */
-               FDC_WRFIFO(fdc, bp->b_cylinder * fd->sc_type->step);
+               FDC_WRFIFO(fdc, cylin * fd->sc_type->step);
                return (1);
 
        case DODSKCHG:
@@ -1531,7 +1530,7 @@ loop:
 
                /* Make sure seek really happened. */
                if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 ||
-                   cyl != bp->b_cylinder * fd->sc_type->step) {
+                   cyl != cylin * fd->sc_type->step) {
 #ifdef FD_DEBUG
                        if (fdc_debug)
                                fdcstatus(fdc, "seek failed");
@@ -1539,7 +1538,7 @@ loop:
                        fdcretry(fdc);
                        goto loop;
                }
-               fd->sc_cylin = bp->b_cylinder;
+               fd->sc_cylin = cylin;
                goto doio;
 
        case IOTIMEDOUT:
@@ -1647,8 +1646,9 @@ loop:
                fd->sc_blkno += fd->sc_nblks;
                fd->sc_skip += fd->sc_nbytes;
                fd->sc_bcount -= fd->sc_nbytes;
+               bp->b_resid -= fd->sc_nbytes;
                if (finfo == NULL && fd->sc_bcount > 0) {
-                       bp->b_cylinder = fd->sc_blkno / fd->sc_type->seccyl;
+                       cylin = fd->sc_blkno / fd->sc_type->seccyl;
                        goto doseek;
                }
                fdfinish(fd, bp);
@@ -1796,6 +1796,7 @@ fdcretry(fdc)
        failsilent:
                bp->b_flags |= B_ERROR;
                bp->b_error = error;
+               bp->b_resid = bp->b_bcount;
                fdfinish(fd, bp);
        }
        fdc->sc_errors++;
Index: dev/isa/fd.c
===================================================================
RCS file: /cvs/src/sys/dev/isa/fd.c,v
retrieving revision 1.96
diff -u -p -r1.96 fd.c
--- dev/isa/fd.c        1 Nov 2013 17:36:19 -0000       1.96
+++ dev/isa/fd.c        20 Nov 2013 10:02:46 -0000
@@ -409,12 +409,12 @@ fdstrategy(struct buf *bp)
                bp->b_bcount = sz << DEV_BSHIFT;
        }
 
-       bp->b_cylinder = bp->b_blkno / (fd_bsize / DEV_BSIZE) / 
fd->sc_type->seccyl;
+       bp->b_resid = bp->b_bcount;
 
 #ifdef FD_DEBUG
-       printf("fdstrategy: b_blkno %lld b_bcount %d blkno %lld cylin %d "
-           "sz %d\n", (long long)bp->b_blkno, bp->b_bcount,
-           (long long)fd->sc_blkno, bp->b_cylinder, sz);
+       printf("fdstrategy: b_blkno %lld b_bcount %d blkno %lld sz %d\n",
+           (long long)bp->b_blkno, bp->b_bcount,
+           (long long)fd->sc_blkno, sz);
 #endif
 
        /* Queue I/O */
@@ -469,7 +469,6 @@ fdfinish(struct fd_softc *fd, struct buf
 
        splassert(IPL_BIO);
 
-       bp->b_resid = fd->sc_bcount;
        fd->sc_skip = 0;
        fd->sc_bp = bufq_dequeue(&fd->sc_bufq);
 
@@ -652,7 +651,7 @@ fdintr(struct fdc_softc *fdc)
        bus_space_tag_t iot = fdc->sc_iot;
        bus_space_handle_t ioh = fdc->sc_ioh;
        bus_space_handle_t ioh_ctl = fdc->sc_ioh_ctl;
-       int read, head, sec, i, nblks;
+       int read, head, sec, i, nblks, cylin;
        struct fd_type *type;
        struct fd_formb *finfo = NULL;
        int fd_bsize;
@@ -676,6 +675,9 @@ loop:
        if (bp->b_flags & B_FORMAT)
            finfo = (struct fd_formb *)bp->b_data;
 
+       cylin = ((bp->b_blkno * DEV_BSIZE) + (bp->b_bcount - bp->b_resid)) /
+           (fd_bsize * fd->sc_type->seccyl);
+
        switch (fdc->sc_state) {
        case DEVIDLE:
                fdc->sc_errors = 0;
@@ -708,7 +710,7 @@ loop:
                /* FALLTHROUGH */
        case DOSEEK:
        doseek:
-               if (fd->sc_cylin == bp->b_cylinder)
+               if (fd->sc_cylin == cylin)
                        goto doio;
 
                out_fdc(iot, ioh, NE7CMD_SPECIFY);/* specify command */
@@ -717,7 +719,7 @@ loop:
 
                out_fdc(iot, ioh, NE7CMD_SEEK); /* seek function */
                out_fdc(iot, ioh, fd->sc_drive);        /* drive number */
-               out_fdc(iot, ioh, bp->b_cylinder * fd->sc_type->step);
+               out_fdc(iot, ioh, cylin * fd->sc_type->step);
 
                fd->sc_cylin = -1;
                fdc->sc_state = SEEKWAIT;
@@ -805,14 +807,14 @@ loop:
                /* Make sure seek really happened. */
                out_fdc(iot, ioh, NE7CMD_SENSEI);
                if (fdcresult(fdc) != 2 || (st0 & 0xf8) != 0x20 ||
-                   cyl != bp->b_cylinder * fd->sc_type->step) {
+                   cyl != cylin * fd->sc_type->step) {
 #ifdef FD_DEBUG
                        fdcstatus(&fd->sc_dev, 2, "seek failed");
 #endif
                        fdretry(fd);
                        goto loop;
                }
-               fd->sc_cylin = bp->b_cylinder;
+               fd->sc_cylin = cylin;
                goto doio;
 
        case IOTIMEDOUT:
@@ -848,11 +850,13 @@ loop:
                        printf("\n");
                        fdc->sc_errors = 0;
                }
+
                fd->sc_blkno += fd->sc_nblks;
                fd->sc_skip += fd->sc_nbytes;
                fd->sc_bcount -= fd->sc_nbytes;
+               bp->b_resid -= fd->sc_nbytes;
                if (!finfo && fd->sc_bcount > 0) {
-                       bp->b_cylinder = fd->sc_blkno / fd->sc_type->seccyl;
+                       cylin = fd->sc_blkno / fd->sc_type->seccyl;
                        goto doseek;
                }
                fdfinish(fd, bp);
@@ -976,6 +980,7 @@ fdretry(struct fd_softc *fd)
 
                bp->b_flags |= B_ERROR;
                bp->b_error = EIO;
+               bp->b_resid = bp->b_bcount;
                fdfinish(fd, bp);
        }
        fdc->sc_errors++;
Index: isofs/cd9660/cd9660_vfsops.c
===================================================================
RCS file: /cvs/src/sys/isofs/cd9660/cd9660_vfsops.c,v
retrieving revision 1.64
diff -u -p -r1.64 cd9660_vfsops.c
--- isofs/cd9660/cd9660_vfsops.c        2 Jun 2013 01:07:39 -0000       1.64
+++ isofs/cd9660/cd9660_vfsops.c        20 Nov 2013 10:02:47 -0000
@@ -490,7 +490,6 @@ iso_disklabelspoof(dev, strat, lp)
                bp->b_bcount = ISO_DEFAULT_BLOCK_SIZE;
                CLR(bp->b_flags, B_READ | B_WRITE | B_DONE);
                SET(bp->b_flags, B_BUSY | B_READ | B_RAW);
-               bp->b_cylinder = bp->b_blkno / lp->d_secpercyl;
 
                /*printf("d_secsize %d iso_blknum %d b_blkno %d bcount %d\n",
                    lp->d_secsize, iso_blknum, bp->b_blkno, bp->b_bcount);*/
Index: kern/subr_hibernate.c
===================================================================
RCS file: /cvs/src/sys/kern/subr_hibernate.c,v
retrieving revision 1.80
diff -u -p -r1.80 subr_hibernate.c
--- kern/subr_hibernate.c       9 Nov 2013 06:54:00 -0000       1.80
+++ kern/subr_hibernate.c       20 Nov 2013 10:02:47 -0000
@@ -1059,7 +1059,6 @@ hibernate_block_io(union hibernate_info 
        CLR(bp->b_flags, B_READ | B_WRITE | B_DONE);
        SET(bp->b_flags, B_BUSY | (iswrite ? B_WRITE : B_READ) | B_RAW);
        bp->b_dev = hib->dev;
-       bp->b_cylinder = 0;
        (*bdsw->d_strategy)(bp);
 
        error = biowait(bp);
Index: sys/buf.h
===================================================================
RCS file: /cvs/src/sys/sys/buf.h,v
retrieving revision 1.90
diff -u -p -r1.90 buf.h
--- sys/buf.h   6 Nov 2013 07:46:31 -0000       1.90
+++ sys/buf.h   20 Nov 2013 10:02:47 -0000
@@ -187,12 +186,6 @@ struct buf {
        int     b_validend;             /* Offset of end of valid region. */
        struct  workhead b_dep;         /* List of filesystem dependencies. */
 };
-
-/*
- * For portability with historic industry practice, the cylinder number has
- * to be maintained in the `b_resid' field.
- */
-#define        b_cylinder b_resid              /* Cylinder number for 
disksort(). */
 
 /* Device driver compatibility definitions. */
 #define        b_active b_bcount               /* Driver queue head: drive 
active. */
Index: uvm/uvm_swap.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_swap.c,v
retrieving revision 1.121
diff -u -p -r1.121 uvm_swap.c
--- uvm/uvm_swap.c      6 Nov 2013 07:46:31 -0000       1.121
+++ uvm/uvm_swap.c      20 Nov 2013 10:02:47 -0000
@@ -1294,9 +1294,6 @@ sw_reg_strategy(struct swapdev *sdp, str
                /* patch it back to the vnx */
                task_set(&nbp->vb_task, sw_reg_iodone_internal, nbp, vnx);
 
-               /* XXX: In case the underlying bufq is disksort: */
-               nbp->vb_buf.b_cylinder = nbp->vb_buf.b_blkno;
-
                s = splbio();
                if (vnx->vx_error != 0) {
                        putvndbuf(nbp);

Reply via email to