4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #ident "%Z%%M% %I% %E% SMI"
36 /* from ufs_dsort.c 2.12 89/07/24 SMI" */
38 * Seek sort for disks. We depend on the driver
39 * which calls us using b_resid as the current cylinder number.
41 * The argument dp structure holds a b_actf activity chain pointer
42 * on which we keep two queues, sorted in ascending cylinder order.
43 * The first queue holds those requests which are positioned after
44 * the current cylinder (in the first request); the second holds
45 * requests which came in after their cylinder number was passed.
46 * Thus we implement a one way scan, retracting after reaching the
47 * end of the drive to the first request on the second queue,
48 * at which time it becomes the first queue.
50 * A one-way scan is natural because of the way UNIX read-ahead
51 * blocks are allocated.
54 #include <sys/types.h>
55 #include <sys/param.h>
56 #include <sys/systm.h>
59 #define b_cylin b_resid
63 register struct diskhd
*dp
;
64 register struct buf
*bp
;
66 register struct buf
*ap
;
69 * If nothing on the activity queue, then
70 * we become the only thing.
80 * If we lie after the first (currently active)
81 * request, then we must locate the second request list
82 * and add ourselves to it.
84 if (bp
->b_cylin
< ap
->b_cylin
) {
87 * Check for an ``inversion'' in the
88 * normally ascending cylinder numbers,
89 * indicating the start of the second request list.
91 if (ap
->av_forw
->b_cylin
< ap
->b_cylin
) {
93 * Search the second request list
94 * for the first request at a larger
95 * cylinder number. We go before that;
96 * if there is no such request, we go at end.
99 if (bp
->b_cylin
< ap
->av_forw
->b_cylin
)
102 } while (ap
->av_forw
);
103 goto insert
; /* after last */
108 * No inversions... we will go after the last, and
109 * be the first request in the second request list.
114 * Request is at/after the current request...
115 * sort in the first request list.
117 while (ap
->av_forw
) {
119 * We want to go after the current request
120 * if there is an inversion after it (i.e. it is
121 * the end of the first request list), or if
122 * the next request is a larger cylinder than our request.
124 if (ap
->av_forw
->b_cylin
< ap
->b_cylin
||
125 bp
->b_cylin
< ap
->av_forw
->b_cylin
)
130 * Neither a second list nor a larger
131 * request... we go at the end of the first list,
132 * which is the same as the end of the whole schebang.
135 bp
->av_forw
= ap
->av_forw
;
137 if (ap
== dp
->b_actl
)