Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / core / fs.c
blob6f321f0d731d375f39f7230b811bd1b96d7dff58
1 /*
2 * ZeX/OS
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/>.
22 #include <build.h>
23 #include <system.h>
24 #include <string.h>
25 #include <partition.h>
26 #include <dev.h>
27 #include <fs.h>
28 #include <cache.h>
29 #include <config.h>
31 fs_t fs_list;
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)
43 return 0;
45 /* alloc and init context */
46 fs_t *fs = (fs_t *) kmalloc (sizeof (fs_t));
48 if (!fs)
49 return 0;
51 memset (fs, 0, sizeof (fs_t));
53 fs->name = (char *) kmalloc (sizeof (char) * FS_NAME_LEN + 1);
55 if (!fs->name) {
56 kfree (fs);
57 return 0;
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;
66 /* add into list */
67 fs->next = &fs_list;
68 fs->prev = fs_list.prev;
69 fs->prev->next = fs;
70 fs->next->prev = fs;
72 return 1;
75 bool fs_list_del (fs_t *fs)
77 if (fs) {
78 fs->next->prev = fs->prev;
79 fs->prev->next = fs->next;
81 //kfree (fs);
82 return 1;
85 return 0;
88 fs_t *fs_supported (char *name)
90 fs_t *fs;
91 for (fs = fs_list.next; fs != &fs_list; fs = fs->next) {
92 if (!strncmp (fs->name, name, strlen (fs->name)))
93 return fs;
96 return 0;
99 extern partition_t partition_list;
100 fs_t *fs_detect (partition_t *p)
102 if (!p)
103 return 0;
105 fs_t *fs;
107 char block[512];
109 dev_t *dev = (dev_t *) dev_findbypartition (p);
111 if (!dev)
112 return 0;
114 if (!dev->handler (DEV_ACT_READ, p, block, "", 63))
115 return 0;
117 char fstype[11];
119 int c;
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);
130 return fs;
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);
140 #endif
141 unsigned int init_fs ()
143 fs_list.next = &fs_list;
144 fs_list.prev = &fs_list;
146 init_cache ();
148 #ifdef ARCH_i386
149 #ifdef CONFIG_DRV_ISOFS
150 fs_list_add ("isofs", &isofs_handler);
151 #endif
153 #ifdef CONFIG_DRV_ZEXFS
154 fs_list_add ("zexfs", &zexfs_handler);
155 #endif
157 #ifdef CONFIG_DRV_EXT2
158 fs_list_add ("ext2", &ext2_handler);
159 #endif
161 #ifdef CONFIG_DRV_FAT16
162 fs_list_add ("fat16", &fat16_handler);
163 #endif
165 #ifdef CONFIG_DRV_FAT12
166 fs_list_add ("fat12", &fat_handler);
167 #endif
169 fs_list_add ("znfs", &znfs_handler);
170 #endif
171 return 1;