/[pupa]/pupa/kern/disk.c
ViewVC logotype

Diff of /pupa/kern/disk.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by marco_g, Wed Oct 29 18:44:29 2003 UTC revision 1.4 by marco_g, Wed Nov 12 20:33:51 2003 UTC
# Line 24  Line 24 
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
# Line 194  pupa_disk_open (const char *name) Line 201  pupa_disk_open (const char *name)
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)
# Line 247  pupa_disk_open (const char *name) Line 255  pupa_disk_open (const char *name)
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)
# Line 267  pupa_disk_close (pupa_disk_t disk) Line 284  pupa_disk_close (pupa_disk_t disk)
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);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26