Răsfoiți Sursa

Cache mounted filesystems

Johannes Zellner 1 lună în urmă
părinte
comite
3dccf64aa7
11 a modificat fișierele cu 26 adăugiri și 60 ștergeri
  1. 1 1
      Makefile
  2. 0 1
      cat.c
  3. 2 0
      kernel.c
  4. 0 2
      ls.c
  5. 0 1
      mkdir.c
  6. 0 1
      rm.c
  7. 0 1
      rmdir.c
  8. 0 1
      run.c
  9. 0 1
      save.c
  10. 23 50
      storage.c
  11. 0 1
      terminal.c

+ 1 - 1
Makefile

@@ -131,7 +131,7 @@ ata.o: ata.c ata.h pci.h timer.h
 fatdetect.o: fatdetect.c fatdetect.h fat.h blkdev.h
 	$(CC) $(CFLAGS) -o $@ $<
 
-storage.o: storage.c blkdev.h fatdetect.h disk.h io.h
+storage.o: storage.c blkdev.h vfs.h io.h
 	$(CC) $(CFLAGS) -o $@ $<
 
 fatformat.o: fatformat.c fatformat.h blkdev.h

+ 0 - 1
cat.c

@@ -21,7 +21,6 @@ void program_cat_main(const char *filename)
 		return;
 	}
 
-	vfs_mount_all();
 	if (vfs_resolve(filename, &fs, &fs_path) != 0) {
 		if (vfs_device_known(filename))
 			io_putstr("cat: no filesystem on device\n");

+ 2 - 0
kernel.c

@@ -9,6 +9,7 @@
 #include "serial.h"
 #include "version.h"
 #include "vga.h"
+#include "vfs.h"
 
 static inline void outb(unsigned short port, unsigned char v)
 {
@@ -139,5 +140,6 @@ void kernel_main(void)
 	process_init();
 	vga_shadow_init();
 	vga_fb_flush();
+	vfs_mount_all();
 	wm_run();
 }

+ 0 - 2
ls.c

@@ -45,8 +45,6 @@ void program_ls_main(const char *path)
 	unsigned int dir_cluster;
 	int r;
 
-	vfs_mount_all();
-
 	if (!path || !path[0] || (path[0] == '/' && path[1] == '\0')) {
 		vfs_list_root();
 		return;

+ 0 - 1
mkdir.c

@@ -17,7 +17,6 @@ void program_mkdir_main(const char *arg)
 		return;
 	}
 
-	vfs_mount_all();
 	if (vfs_resolve(arg, &fs, &fs_path) != 0) {
 		io_putstr("mkdir: read-only filesystem\n");
 		return;

+ 0 - 1
rm.c

@@ -17,7 +17,6 @@ void program_rm_main(const char *arg)
 		return;
 	}
 
-	vfs_mount_all();
 	if (vfs_resolve(arg, &fs, &fs_path) != 0) {
 		io_putstr("rm: read-only filesystem\n");
 		return;

+ 0 - 1
rmdir.c

@@ -17,7 +17,6 @@ void program_rmdir_main(const char *arg)
 		return;
 	}
 
-	vfs_mount_all();
 	if (vfs_resolve(arg, &fs, &fs_path) != 0) {
 		io_putstr("rmdir: read-only filesystem\n");
 		return;

+ 0 - 1
run.c

@@ -26,7 +26,6 @@ void program_run_main(const char *filename)
 		return;
 	}
 
-	vfs_mount_all();
 	if (vfs_resolve(filename, &fs, &fs_path) != 0) {
 		io_putstr("run: unknown device or invalid path\n");
 		return;

+ 0 - 1
save.c

@@ -48,7 +48,6 @@ void program_save_main(const char *arg)
 	while (text[text_len])
 		text_len++;
 
-	vfs_mount_all();
 	if (vfs_resolve(fn, &fs, &fs_path) != 0) {
 		io_putstr("save: read-only filesystem\n");
 		return;

+ 23 - 50
storage.c

@@ -1,8 +1,8 @@
-/* storage command: probe floppy + IDE devices and report FAT filesystems. */
+/* storage command: refresh the filesystem cache and report devices + mounts. */
 
 #include "blkdev.h"
-#include "fatdetect.h"
 #include "io.h"
+#include "vfs.h"
 
 static void put_dec(unsigned int n)
 {
@@ -71,28 +71,30 @@ static void report_fs(const char *name, const fat_fs_t *fs)
 	io_putchar('\n');
 }
 
-static void part_name(char *out, const char *base, unsigned int idx)
+/* Does mount `mount_name` belong to block device `dev_name`?
+ * True for an exact match ("floppy0") or a partition ("ide0p1" for "ide0"). */
+static int mount_belongs_to(const char *mount_name, const char *dev_name)
 {
 	unsigned int i = 0;
-	while (base[i] && i < 14) {
-		out[i] = base[i];
+	while (dev_name[i] && mount_name[i] == dev_name[i])
 		i++;
-	}
-	out[i++] = 'p';
-	out[i++] = (char)('0' + idx + 1);
-	out[i] = '\0';
+	if (dev_name[i] == '\0' && mount_name[i] == '\0')
+		return 1;
+	if (dev_name[i] == '\0' && mount_name[i] == 'p')
+		return 1;
+	return 0;
 }
 
 void program_storage_main(void)
 {
-	static unsigned char buf[512];
-	unsigned int i;
+	unsigned int i, j;
 
-	blk_scan();
+	/* Refresh the filesystem cache (re-probes all devices). */
+	vfs_mount_all();
 
 	for (i = 0; i < blk_dev_count; i++) {
 		blk_dev_t *d = &blk_devs[i];
-		fat_fs_t fs;
+		int found = 0;
 
 		if (d->kind == BLK_IDE && !d->present) {
 			io_putstr(d->name);
@@ -100,45 +102,16 @@ void program_storage_main(void)
 			continue;
 		}
 
-		if (blk_read(d, 0, buf, 1) != 0) {
-			io_putstr(d->name);
-			io_putstr(": not present / unreadable\n");
-			continue;
-		}
-
-		if (d->kind == BLK_FLOPPY) {
-			if (fat_mount(d, 0, &fs) == 0)
-				report_fs(d->name, &fs);
-			else {
-				io_putstr(d->name);
-				io_putstr(": no valid FAT filesystem\n");
-			}
-		} else {
-			mbr_part_t parts[4];
-			int n = mbr_parse(buf, parts);
-			int found = 0;
-			int j;
-
-			for (j = 0; j < n; j++) {
-				char pname[16];
-				if (!parts[j].is_fat || parts[j].start_lba == 0 ||
-				    parts[j].sectors == 0)
-					continue;
-				if (fat_mount(d, parts[j].start_lba, &fs) == 0) {
-					part_name(pname, d->name, parts[j].index);
-					report_fs(pname, &fs);
-					found = 1;
-				}
+		for (j = 0; j < vfs_mount_count; j++) {
+			if (mount_belongs_to(vfs_mounts[j].name, d->name)) {
+				report_fs(vfs_mounts[j].name, &vfs_mounts[j].fs);
+				found = 1;
 			}
+		}
 
-			if (!found) {
-				if (fat_mount(d, 0, &fs) == 0)
-					report_fs(d->name, &fs);
-				else {
-					io_putstr(d->name);
-					io_putstr(": no valid FAT filesystem\n");
-				}
-			}
+		if (!found) {
+			io_putstr(d->name);
+			io_putstr(": no valid FAT filesystem\n");
 		}
 	}
 }

+ 0 - 1
terminal.c

@@ -665,7 +665,6 @@ static void term_cd(struct term *t, const char *arg)
 		return;
 	}
 
-	vfs_mount_all();
 	if (vfs_resolve(abs, &fs, &fs_path) != 0) {
 		io_putstr("cd: no such directory\n");
 		return;