3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <partition.h>
33 static unsigned char tolower (char c
)
35 return ((c
>= 'A' && c
<= 'Z') ? c
+ 32: c
);
38 bool fs_list_add (char *name
, fs_handler_t
*handler
)
40 unsigned name_len
= strlen (name
);
42 if (!name_len
|| !handler
)
45 /* alloc and init context */
46 fs_t
*fs
= (fs_t
*) kmalloc (sizeof (fs_t
));
51 memset (fs
, 0, sizeof (fs_t
));
53 fs
->name
= (char *) kmalloc (sizeof (char) * FS_NAME_LEN
+ 1);
60 memset (fs
->name
, 0, FS_NAME_LEN
);
61 memcpy (fs
->name
, name
, name_len
);
62 fs
->name
[name_len
] = '\0';
64 fs
->handler
= handler
;
68 fs
->prev
= fs_list
.prev
;
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
);
114 if (!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
;
149 #ifdef CONFIG_DRV_ISOFS
150 fs_list_add ("isofs", &isofs_handler
);
153 #ifdef CONFIG_DRV_ZEXFS
154 fs_list_add ("zexfs", &zexfs_handler
);
157 #ifdef CONFIG_DRV_EXT2
158 fs_list_add ("ext2", &ext2_handler
);
161 #ifdef CONFIG_DRV_FAT16
162 fs_list_add ("fat16", &fat16_handler
);
165 #ifdef CONFIG_DRV_FAT12
166 fs_list_add ("fat12", &fat_handler
);
169 fs_list_add ("znfs", &znfs_handler
);