4 * Mini "VFS" by Marcus Sundberg
6 * 2002-07-28 - rjones@nexus-tech.net - ported to ppcboot v1.1.6
7 * 2003-03-10 - kharris@nexus-tech.net - ported to uboot
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #include <linux/stat.h>
33 #include <linux/time.h>
35 /* Supported filesystems */
36 static const struct filesystem filesystems[] = {
37 { file_fat_detectfs, file_fat_ls, file_fat_read, "FAT" },
39 #define NUM_FILESYS (sizeof(filesystems)/sizeof(struct filesystem))
41 /* The filesystem which was last detected */
42 static int current_filesystem = FSTYPE_NONE;
44 /* The current working directory */
46 char file_cwd[CWD_LEN+1] = "/";
49 file_getfsname(int idx)
51 if (idx < 0 || idx >= NUM_FILESYS) return NULL;
53 return filesystems[idx].name;
58 pathcpy(char *dest, const char *src)
60 char *origdest = dest;
63 if (dest-file_cwd >= CWD_LEN) {
69 if (dest-- != origdest && ISDIRDELIM(*dest)) {
75 if (ISDIRDELIM(*src)) {
76 while (ISDIRDELIM(*src)) src++;
85 file_cd(const char *path)
87 if (ISDIRDELIM(*path)) {
88 while (ISDIRDELIM(*path)) path++;
89 strncpy(file_cwd+1, path, CWD_LEN-1);
91 const char *origpath = path;
92 char *tmpstr = file_cwd;
95 while (*tmpstr != '\0') tmpstr++;
98 } while (ISDIRDELIM(*tmpstr));
100 while (*path == '.') {
102 while (*path == '.') {
106 if (*path != '\0' && !ISDIRDELIM(*path)) {
111 while (ISDIRDELIM(*path)) path++;
116 /* Strip off path component */
117 while (!ISDIRDELIM(*tmpstr)) {
120 if (tmpstr == file_cwd) {
121 /* Incremented again right after the loop. */
125 /* Skip delimiters */
126 while (ISDIRDELIM(*tmpstr)) tmpstr--;
130 if (tmpstr == file_cwd) {
138 pathcpy(tmpstr+1, path);
150 current_filesystem = FSTYPE_NONE;
152 for (i = 0; i < NUM_FILESYS; i++) {
153 if (filesystems[i].detect() == 0) {
154 strcpy(file_cwd, "/");
155 current_filesystem = i;
160 return current_filesystem;
165 file_ls(const char *dir)
170 if (current_filesystem == FSTYPE_NONE) {
171 printf("Can't list files without a filesystem!\n");
175 if (ISDIRDELIM(*dir)) {
178 sprintf(fullpath, "%s/%s", file_cwd, dir);
181 return filesystems[current_filesystem].ls(arg);
186 file_read(const char *filename, void *buffer, unsigned long maxsize)
191 if (current_filesystem == FSTYPE_NONE) {
192 printf("Can't load file without a filesystem!\n");
196 if (ISDIRDELIM(*filename)) {
199 sprintf(fullpath, "%s/%s", file_cwd, filename);
203 return filesystems[current_filesystem].read(arg, buffer, maxsize);