Warning, cross-references for /kernel/fs/fsys.c need to be fixed.
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include"fs/filesys.h"
0019 #include"kernel.h"
0020 #include"util/screen.h"
0021 #include"util/printf.h"
0022
0023 static int vfs_root_type = VFS_FSYS_NONE;
0024
0025 typedef struct { char *name; int type; } vfs_table_t;
0026 static vfs_table_t vfs_table[] = {
0027 { "hd", VFS_FSYS_EZEXT2 },
0028 { "cd", VFS_FSYS_EZISO },
0029 { "tftp", VFS_FSYS_EZTFTP },
0030 { "usb", VFS_FSYS_EZUSB },
0031 };
0032 #define NUM_VFS (sizeof (vfs_table) / sizeof (vfs_table_t))
0033
0034 void
0035 vfs_set_root (int type, ata_info * drive_info)
0036 {
0037 vfs_root_type = type;
0038 }
0039
0040 static int
0041 parse_pathname (char *pathname, char **filepart)
0042 {
0043 if (pathname[0] == '(') {
0044 int i;
0045 for (i=0; i<NUM_VFS; i++) {
0046 char *name = vfs_table[i].name;
0047 char *vfs = pathname + 1;
0048 for (; *vfs && *vfs != ')' && *name; vfs++, name++) {
0049 if (*vfs != *name)
0050 break;
0051 }
0052 if (*name == '\0' && *vfs == ')') {
0053 *filepart = vfs + 1;
0054 return vfs_table[i].type;
0055 }
0056 }
0057 return -1;
0058 } else {
0059 *filepart = pathname;
0060 return vfs_root_type;
0061 }
0062 }
0063
0064
0065 int
0066 vfs_dir (char *pathname)
0067 {
0068 char *filepart;
0069 int type = parse_pathname (pathname, &filepart);
0070 if (type == -1) return -1;
0071 switch (type) {
0072 case VFS_FSYS_EZEXT2:
0073 return ext2fs_dir (filepart);
0074 case VFS_FSYS_EZISO:
0075 return eziso_dir (filepart);
0076 case VFS_FSYS_EZUSB:
0077 return vfat_dir (filepart);
0078 case VFS_FSYS_EZTFTP:
0079 return eztftp_dir (filepart);
0080 default:
0081 print ("Unknown vfs_type");
0082 return -1;
0083 }
0084 }
0085
0086
0087 int
0088 vfs_read (char *pathname, char *buf, int len)
0089 {
0090 char *filepart;
0091 int type = parse_pathname (pathname, &filepart);
0092 if (type == -1) return -1;
0093 switch (type) {
0094 case VFS_FSYS_EZEXT2:
0095 return ext2fs_read (buf, len);
0096 case VFS_FSYS_EZISO:
0097 return eziso_read (buf, len);
0098 case VFS_FSYS_EZUSB:
0099 return vfat_read (buf, len);
0100 case VFS_FSYS_EZTFTP:
0101 return eztftp_read (buf, len);
0102 default:
0103 print ("Unknown vfs_type");
0104 return -1;
0105 }
0106 }
0107
0108
0109
0110 bool
0111 vfs_init (void)
0112 {
0113 extern u32 root_type, boot_device;
0114 int i;
0115 switch (root_type) {
0116 case VFS_FSYS_EZEXT2:
0117 if (boot_device == 0x8000FFFF && pata_drives[0].ata_type == ATA_TYPE_PATA) {
0118 printf ("ROOT: HARD DISK DRIVE: EXT2\n");
0119
0120 if (!ext2fs_mount ())
0121 panic ("Filesystem mount failed");
0122 vfs_set_root (VFS_FSYS_EZEXT2, &pata_drives[0]);
0123 } else {
0124 printf ("ROOT: unable to find ext2 drive\n");
0125 }
0126 break;
0127 case VFS_FSYS_EZUSB:
0128 default:
0129 printf ("ROOT: USB MASS STORAGE: VFAT\n");
0130 vfat_mount ();
0131 vfs_set_root (VFS_FSYS_EZUSB, NULL);
0132 break;
0133 case VFS_FSYS_EZISO:
0134 for (i = 0; i < 4; i++) {
0135 if (pata_drives[i].ata_type == ATA_TYPE_PATAPI) {
0136 printf ("ROOT: CD-ROM: ISO-9660\n");
0137 if (!eziso_mount (pata_drives[i].ata_bus, pata_drives[i].ata_drive))
0138 panic ("Filesystem mount failed");
0139 vfs_set_root (VFS_FSYS_EZISO, &pata_drives[i]);
0140 break;
0141 }
0142 }
0143 if (i == 4)
0144 printf ("Unable to detect CD-ROM drive.\n");
0145 break;
0146 case VFS_FSYS_EZTFTP:
0147 printf ("ROOT: TFTP\n");
0148 if (!eztftp_mount ("en0"))
0149 panic ("TFTP mount failed");
0150 vfs_set_root (VFS_FSYS_EZTFTP, NULL);
0151 break;
0152 }
0153 return TRUE;
0154 }
0155
0156 #include "module/header.h"
0157
0158 static const struct module_ops mod_ops = {
0159 .init = vfs_init
0160 };
0161
0162 DEF_MODULE (vfs, "virtual filesystem switch", &mod_ops, {"storage___ata|usbenumeration|netsetup"});
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173