3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <partition.h>
31 static unsigned char tolower (char c
)
33 return ((c
>= 'A' && c
<= 'Z') ? c
+ 32: c
);
36 bool fs_list_add (char *name
, fs_handler_t
*handler
)
38 unsigned name_len
= strlen (name
);
40 if (!name_len
|| !handler
)
43 /* alloc and init context */
44 fs_t
*fs
= (fs_t
*) kmalloc (sizeof (fs_t
));
49 memset (fs
, 0, sizeof (fs_t
));
51 fs
->name
= (char *) kmalloc (sizeof (char) * FS_NAME_LEN
+ 1);
58 memset (fs
->name
, 0, FS_NAME_LEN
);
59 memcpy (fs
->name
, name
, name_len
);
60 fs
->name
[name_len
] = '\0';
62 fs
->handler
= handler
;
66 fs
->prev
= fs_list
.prev
;
70 handler (FS_ACT_INIT
, (char *) NULL
, NULL
, NULL
);
75 bool fs_list_del (fs_t
*fs
)
78 fs
->next
->prev
= fs
->prev
;
79 fs
->prev
->next
= fs
->next
;
88 fs_t
*fs_supported (char *name
)
91 for (fs
= fs_list
.next
; fs
!= &fs_list
; fs
= fs
->next
) {
92 if (!strncmp (fs
->name
, name
, strlen (fs
->name
)))
99 extern partition_t partition_list
;
100 fs_t
*fs_detect (partition_t
*p
)
109 dev_t
*dev
= (dev_t
*) dev_findbypartition (p
);
115 dev
->handler (DEV_ACT_READ
, p
, block
, "", 63);
120 for (c
= 54; c
< 64; c
++)
121 fstype
[c
-54] = block
[c
];
123 memset (block
, 0, sizeof (block
));
125 for (c
= 0; c
< 10; c
++)
126 block
[c
] = tolower (fstype
[c
]);
128 fs
= fs_supported (block
);
133 extern bool fat_handler (unsigned act
, char *block
, unsigned n
, unsigned long l
);
134 extern bool fat16_handler (unsigned act
, char *block
, unsigned n
, unsigned long l
);
135 extern bool zexfs_handler (unsigned act
, char *block
, unsigned n
, unsigned long l
);
136 extern bool isofs_handler (unsigned act
, char *block
, unsigned n
, unsigned long l
);
137 extern bool znfs_handler (unsigned act
, char *block
, unsigned n
, unsigned long l
);
138 #ifdef CONFIG_DRV_EXT2
139 extern bool ext2_handler (unsigned act
, char *block
, unsigned n
, unsigned long l
);
141 unsigned int init_fs ()
143 fs_list
.next
= &fs_list
;
144 fs_list
.prev
= &fs_list
;
146 file_cache
= (unsigned char *) 0x350000; // file_cache store address
150 #ifdef CONFIG_DRV_ISOFS
151 fs_list_add ("isofs", &isofs_handler
);
154 #ifdef CONFIG_DRV_ZEXFS
155 fs_list_add ("zexfs", &zexfs_handler
);
158 #ifdef CONFIG_DRV_EXT2
159 fs_list_add ("ext2", &ext2_handler
);
162 #ifdef CONFIG_DRV_FAT16
163 fs_list_add ("fat16", &fat16_handler
);
166 #ifdef CONFIG_DRV_FAT12
167 fs_list_add ("fat12", &fat_handler
);
170 fs_list_add ("znfs", &znfs_handler
);