source: trunk/minix/commands/i386/mtools-3.9.7/streamcache.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.2 KB
Line 
1/*
2 * streamcache.c
3 * Managing a cache of open disks
4 */
5
6#include "sysincludes.h"
7#include "msdos.h"
8#include "mtools.h"
9#include "vfat.h"
10#include "fs.h"
11#include "mainloop.h"
12#include "plain_io.h"
13#include "file.h"
14
15static int is_initialized = 0;
16static Stream_t *fss[256]; /* open drives */
17
18static void finish_sc(void)
19{
20 int i;
21
22 for(i=0; i<256; i++){
23 if(fss[i] && fss[i]->refs != 1 )
24 fprintf(stderr,"Streamcache allocation problem:%c %d\n",
25 i, fss[i]->refs);
26 FREE(&(fss[i]));
27 }
28}
29
30static void init_streamcache(void)
31{
32 int i;
33
34 if(is_initialized)
35 return;
36 is_initialized = 1;
37 for(i=0; i<256; i++)
38 fss[i]=0;
39 atexit(finish_sc);
40}
41
42Stream_t *open_root_dir(char *drive, int flags)
43{
44 Stream_t *Fs;
45 int i, k;
46
47 init_streamcache();
48
49 k = -1;
50 for(i=0; i<256; i++) {
51 if (fss[i] == NULL || strcmp(getDrive(fss[i]), drive) == 0) {
52 k = i;
53 break;
54 }
55 }
56
57 if(k == -1) {
58 fprintf(stderr, "Cannot initialize '%s:', out of table space\n",
59 drive);
60 return NULL;
61 }
62
63 /* open the drive */
64 if(fss[k])
65 Fs = fss[k];
66 else {
67 Fs = fs_init(drive, flags);
68 if (!Fs){
69 fprintf(stderr, "Cannot initialize '%s:'\n", drive);
70 return NULL;
71 }
72
73 fss[k] = Fs;
74 }
75
76 return OpenRoot(Fs);
77}
Note: See TracBrowser for help on using the repository browser.