24 |
#include <pupa/types.h> |
#include <pupa/types.h> |
25 |
#include <pupa/machine/partition.h> |
#include <pupa/machine/partition.h> |
26 |
#include <pupa/misc.h> |
#include <pupa/misc.h> |
27 |
|
#include <pupa/machine/time.h> |
28 |
|
|
29 |
|
#define PUPA_CACHE_TIMEOUT 2 |
30 |
|
|
31 |
|
/* The last time the disk was used. */ |
32 |
|
static unsigned long pupa_last_time = 0; |
33 |
|
|
34 |
|
|
35 |
/* Disk cache. */ |
/* Disk cache. */ |
36 |
struct pupa_disk_cache |
struct pupa_disk_cache |
201 |
pupa_disk_t disk; |
pupa_disk_t disk; |
202 |
pupa_disk_dev_t dev; |
pupa_disk_dev_t dev; |
203 |
char *raw = (char *) name; |
char *raw = (char *) name; |
204 |
|
unsigned long current_time; |
205 |
|
|
206 |
disk = (pupa_disk_t) pupa_malloc (sizeof (*disk)); |
disk = (pupa_disk_t) pupa_malloc (sizeof (*disk)); |
207 |
if (! disk) |
if (! disk) |
255 |
if (p) |
if (p) |
256 |
disk->partition = pupa_partition_probe (disk, p + 1); |
disk->partition = pupa_partition_probe (disk, p + 1); |
257 |
|
|
258 |
|
/* The cache will be invalidated about 2 seconds after a device was |
259 |
|
closed. */ |
260 |
|
current_time = pupa_get_rtc (); |
261 |
|
|
262 |
|
if (current_time > pupa_last_time + PUPA_CACHE_TIMEOUT * PUPA_TICKS_PER_SECOND) |
263 |
|
pupa_disk_cache_invalidate_all (); |
264 |
|
|
265 |
|
pupa_last_time = current_time; |
266 |
|
|
267 |
fail: |
fail: |
268 |
|
|
269 |
if (raw && raw != name) |
if (raw && raw != name) |
284 |
if (disk->dev && disk->dev->close) |
if (disk->dev && disk->dev->close) |
285 |
(disk->dev->close) (disk); |
(disk->dev->close) (disk); |
286 |
|
|
287 |
|
/* Reset the timer. */ |
288 |
|
pupa_last_time = pupa_get_rtc (); |
289 |
|
|
290 |
pupa_free (disk->partition); |
pupa_free (disk->partition); |
291 |
pupa_free ((void *) disk->name); |
pupa_free ((void *) disk->name); |
292 |
pupa_free (disk); |
pupa_free (disk); |