[syslinux] [PATCH 04/12] core: add data structure to hold fs_info for all disks/partition

Andre Ericson de.ericson at gmail.com
Mon Aug 20 01:16:46 PDT 2012


A new data structure is implemented to hold filesystem information for
all accessed disk/partitions.

Signed-off-by: Andre Ericson <de.ericson at gmail.com>
Signed-off-by: Paulo Alcantara <pcacjr at zytor.com>
---
 core/fs/fs.c             | 14 +++++++-----
 core/include/multidisk.h |  4 +++-
 core/multidisk.c         | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/core/fs/fs.c b/core/fs/fs.c
index b9878fe..225df05 100644
--- a/core/fs/fs.c
+++ b/core/fs/fs.c
@@ -14,7 +14,6 @@ char *PATH;
 
 /* The currently mounted filesystem */
 struct fs_info *this_fs = NULL;		/* Root filesystem */
-struct fs_info *fs_array[256][4];
 
 /* Actual file structures (we don't have malloc yet...) */
 struct file files[MAX_OPEN];
@@ -221,6 +220,7 @@ const struct fs_ops *fs_ops_array [4] = {
 
 struct fs_info *get_fs_info(uint8_t hdd, uint8_t partition)
 {
+    struct fs_info *fsp;
     struct fs_info fs;
     uint8_t disk_devno, disk_cdrom;
     sector_t disk_offset;
@@ -232,8 +232,9 @@ struct fs_info *get_fs_info(uint8_t hdd, uint8_t partition)
     int blk_shift = -1;
     struct device *dev = NULL;
 
-    if (fs_array[hdd][partition - 1])
-        return fs_array[hdd][partition - 1];
+    fsp = get_fs(hdd, partition - 1);
+    if (fsp)
+        return fsp;
 
     disk_devno = 0x80 + hdd;
 
@@ -293,7 +294,8 @@ struct fs_info *get_fs_info(uint8_t hdd, uint8_t partition)
         while (1)
             ;
     }
-    fs_array[hdd][partition - 1] = &fs;
+    add_fs(&fs, hdd, partition - 1);
+    fsp = &fs;
 
     /* initialize the cache */
     if (fs.fs_dev && fs.fs_dev->cache_data)
@@ -306,10 +308,10 @@ struct fs_info *get_fs_info(uint8_t hdd, uint8_t partition)
     }
 
     if (fs.fs_ops->chdir_start) {
-        if (fs.fs_ops->chdir_start(fs_array[hdd][partition -1]) < 0)
+        if (fs.fs_ops->chdir_start(fsp) < 0)
             printf("Failed to chdir to start directory\n");
     }
-    return fs_array[hdd][partition - 1];
+    return fsp;
 }
 
 
diff --git a/core/include/multidisk.h b/core/include/multidisk.h
index 3fd9c08..ccf4ad0 100644
--- a/core/include/multidisk.h
+++ b/core/include/multidisk.h
@@ -3,6 +3,8 @@
 #include "partiter.h"
 
 void do_magic(void *);
-int find_partition(struct part_iter **, int, int);
+int find_partition(struct part_iter **_iter, int drive, int partition);
+int add_fs(struct fs_info *fs, uint8_t disk, uint8_t partition);
+struct fs_info *get_fs(uint8_t disk, uint8_t partition);
 
 #endif /* MULTIDISK_H */
diff --git a/core/multidisk.c b/core/multidisk.c
index 9623899..bcc24bc 100644
--- a/core/multidisk.c
+++ b/core/multidisk.c
@@ -18,6 +18,63 @@
 #include "disk.h"
 #include "partiter.h"
 
+/* 0x80 - 0xFF
+ * BIOS limitation */
+#define DISKS_MAX 128
+
+struct part_node {
+    int partition;
+    struct fs_info *fs;
+    struct part_node *next;
+};
+
+struct queue_head {
+    struct part_node *first;
+    struct part_node *last;
+};
+
+struct queue_head *parts_info[DISKS_MAX];
+
+int add_fs(struct fs_info *fs, uint8_t disk, uint8_t partition)
+{
+    struct queue_head *head = parts_info[disk];
+    struct part_node *node;
+
+    node = malloc(sizeof(struct part_node));
+    if (!node)
+        return -1;
+
+    node->fs = fs;
+    node->next = NULL;
+    node->partition = partition;
+    if (!head) {
+        head = malloc(sizeof(struct queue_head));
+        if(!head)
+            goto bail;
+        head->first = head->last = node;
+        parts_info[disk] = head;
+        return 0;
+    }
+    head->last->next = node;
+    head->last = node;
+    return 0;
+
+bail:
+    free(node);
+    return -1;
+}
+
+struct fs_info *get_fs(uint8_t disk, uint8_t partition)
+{
+    struct part_node *i;
+
+    for (i = parts_info[disk]->first; i; i = i->next) {
+        if (i->partition == partition)
+            return i->fs;
+    }
+    return NULL;
+}
+
 void do_magic(void *buff)
 {
 
-- 
1.7.11.3




More information about the Syslinux mailing list