1 /* libbdev - asynchronous call structure management */
3 #include <minix/drivers.h>
4 #include <minix/bdev.h>
11 static bdev_call_t
*calls
[NR_CALLS
];
13 bdev_call_t
*bdev_call_alloc(int count
)
15 /* Allocate a call structure.
20 for (id
= 0; id
< NR_CALLS
; id
++)
21 if (calls
[id
] == NULL
)
27 call
= malloc(sizeof(bdev_call_t
) +
28 sizeof(call
->gvec
[0]) * (count
- 1) +
29 sizeof(call
->vec
[0]) * count
);
35 call
->vec
= (iovec_t
*) &call
->gvec
[count
];
42 void bdev_call_free(bdev_call_t
*call
)
44 /* Free a call structure.
47 assert(calls
[call
->id
] == call
);
49 calls
[call
->id
] = NULL
;
54 bdev_call_t
*bdev_call_get(bdev_id_t id
)
56 /* Retrieve a call structure by request number.
59 if (id
< 0 || id
>= NR_CALLS
)
65 bdev_call_t
*bdev_call_find(dev_t dev
)
67 /* Find the first asynchronous request for the given device, if any.
71 for (id
= 0; id
< NR_CALLS
; id
++)
72 if (calls
[id
] != NULL
&& calls
[id
]->dev
== dev
)
78 bdev_call_t
*bdev_call_iter_maj(dev_t dev
, bdev_call_t
*call
,
81 /* Iterate over all asynchronous requests for a major device. This function
82 * must be safe even if the returned call structure is freed.
89 /* If this is the first invocation, find the first match. Otherwise, take the
90 * call we found to be next in the last invocation, which may be NULL.
93 for (id
= 0; id
< NR_CALLS
; id
++)
94 if (calls
[id
] != NULL
&& major(calls
[id
]->dev
) == major
)
102 if ((call
= *next
) == NULL
)
106 /* Look for the next match, if any. */
109 for (id
= call
->id
+ 1; id
< NR_CALLS
; id
++) {
110 if (calls
[id
] != NULL
&& major(calls
[id
]->dev
) == major
) {