+ struct seek_bkt *sbp;
+
+ sbp = rb_entry(n, struct seek_bkt, rb_node);
+ if ((sofar + sbp->nseeks) >= target) {
+ *rvp = sbp->sectors;
+ return 1;
+ }
+
+ if (n->rb_left && __median(n->rb_left, sofar, target, rvp))
+ return 1;
+
+ if (n->rb_right && __median(n->rb_right, sofar, target, rvp))
+ return 1;
+
+ return 0;
+
+}
+
+static void __mode(struct rb_node *n, struct mode *mp)
+{
+ struct seek_bkt *sbp;
+
+ if (n->rb_left)
+ __mode(n->rb_left, mp);
+ if (n->rb_right)
+ __mode(n->rb_right, mp);
+
+ sbp = rb_entry(n, struct seek_bkt, rb_node);
+ if (mp->modes == NULL) {
+ mp->modes = malloc(sizeof(long long));
+ mp->nmds = 0;
+ } else if (sbp->nseeks > mp->most_seeks)
+ mp->nmds = 0;
+ else if (sbp->nseeks == mp->most_seeks)
+ mp->modes = realloc(mp->modes, (mp->nmds + 1) *
+ sizeof(long long));
+ else
+ return;
+
+ mp->most_seeks = sbp->nseeks;
+ mp->modes[mp->nmds++] = sbp->sectors;