[syslinux] [PATCH 06/12] core: multidisk parser related changes
Andre Ericson
de.ericson at gmail.com
Mon Aug 20 01:16:48 PDT 2012
This commits makes a small change to multidisk path syntax it's now
"(hdx,y)/path/to/file". opendir() has also been changed to accept multidisk
paths. Parser code has moved to multidisk.c.
Signed-off-by: Andre Ericson <de.ericson at gmail.com>
---
com32/modules/fopen_test.c | 8 +++----
core/fs/fs.c | 46 ++++++------------------------------
core/fs/readdir.c | 32 +++++++++++++++++++++----
core/include/fs.h | 1 +
core/include/multidisk.h | 7 ++++++
core/multidisk.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 105 insertions(+), 47 deletions(-)
diff --git a/com32/modules/fopen_test.c b/com32/modules/fopen_test.c
index 37d98cd..a360f52 100644
--- a/com32/modules/fopen_test.c
+++ b/com32/modules/fopen_test.c
@@ -8,10 +8,10 @@
#include <stdlib.h>
#define FILENAME "(0 2):/andre/hello_mate"
-/* should have this syntax: (hd part):/path/to/file */
+/* should have this syntax: (hdx,y)/path/to/file */
const char *paths [] = {
- "(0 2):/andre/fat_info",
- "(0 3):/andre/ntfs_info",
+ "(hd0,2)/andre/fat_info",
+ "(hd0,3)/andre/ntfs_info",
NULL
};
@@ -28,7 +28,7 @@ int main(int argc __unused, char **argv __unused)
printf("Reading file: %s, content:\n", *c);
if (!f)
printf("File not found.\n"
- "For multidisk files use (hd part):/path/to/file\n");
+ "For multidisk files use (hdx,y)/path/to/file\n");
else {
while ((buff[i++] = fgetc(f)) && i < 50);
buff[i < 49 ? i : 49] = '\0';
diff --git a/core/fs/fs.c b/core/fs/fs.c
index 0834d97..9f9e4fc 100644
--- a/core/fs/fs.c
+++ b/core/fs/fs.c
@@ -491,49 +491,17 @@ int open_file(const char *name, struct com32_filedata *filedata)
int rv;
struct file *file;
char mangled_name[FILENAME_MAX];
- uint8_t hdd = 0;
- uint8_t partition = 0;
- char buff[4];
+ struct muldisk_path *mul_path;
if (name[0] == '(') {
- char relative_name[FILENAME_MAX];
- const char *c = name;
- int i = 0;
- int mult = 1;
-
- /* get hdd number */
- for (++c; *c != ' '; ++c)
- buff[i++] = *c;
- buff[i] = '\0';
-
- /* str to uint8_t */
- while (i--) {
- hdd += (buff[i] - 48) * mult;
- mult *= 10;
- }
-
- /* get partition number */
- i = 0;
- for (++c; *c != ')'; ++c)
- buff[i++] = *c;
- buff[i] = '\0';
-
- /* str to uint8_t */
- mult = 1;
- while (i--) {
- partition += (buff[i] - 48) * mult;
- mult *= 10;
- }
-
- i = 0;
- /* c was on ')' jump ':' and stop at beginning of path */
- for (c += 2; *c; c++)
- relative_name[i++] = *c;
- relative_name[i] = '\0';
+ mul_path = muldisk_path_parse(name);
+ if (!mul_path)
+ return -1;
- mangle_name(mangled_name, relative_name, get_fs_info(hdd, partition));
+ mangle_name(mangled_name, mul_path->relative_name, get_fs_info(mul_path->hdd, mul_path->partition));
- rv = searchdir(mangled_name, get_fs_info(hdd, partition));
+ rv = searchdir(mangled_name, get_fs_info(mul_path->hdd, mul_path->partition));
+ free(mul_path);
if (rv < 0)
return rv;
diff --git a/core/fs/readdir.c b/core/fs/readdir.c
index ca03a80..fe68b01 100644
--- a/core/fs/readdir.c
+++ b/core/fs/readdir.c
@@ -3,6 +3,7 @@
#include <sys/dirent.h>
#include "fs.h"
#include "core.h"
+#include "multidisk.h"
/*
* Open a directory
@@ -11,16 +12,39 @@ DIR *opendir(const char *path)
{
int rv;
struct file *file;
+ struct muldisk_path *mul_path;
+
+ if (path[0] == '(') {
+
+ mul_path = muldisk_path_parse(path);
+ if (!mul_path)
+ return NULL;
+
+ rv = searchdir(mul_path->relative_name, get_fs_info(mul_path->hdd, mul_path->partition));
+ free(mul_path);
+
+ if (rv < 0)
+ return NULL;
+
+ file = handle_to_file(rv);
+
+ if (file->inode->mode != DT_DIR) {
+ _close_file(file);
+ return NULL;
+ }
+
+ return (DIR *)file;
+ }
rv = searchdir(path, NULL);
if (rv < 0)
- return NULL;
+ return NULL;
file = handle_to_file(rv);
if (file->inode->mode != DT_DIR) {
- _close_file(file);
- return NULL;
+ _close_file(file);
+ return NULL;
}
return (DIR *)file;
@@ -34,7 +58,7 @@ struct dirent *readdir(DIR *dir)
static struct dirent buf;
struct file *dd_dir = (struct file *)dir;
int rv = -1;
-
+
if (dd_dir) {
if (dd_dir->fs->fs_ops->readdir) {
rv = dd_dir->fs->fs_ops->readdir(dd_dir, &buf);
diff --git a/core/include/fs.h b/core/include/fs.h
index 0d870e0..6690f03 100644
--- a/core/include/fs.h
+++ b/core/include/fs.h
@@ -192,6 +192,7 @@ void mangle_name(char *, const char *, struct fs_info *);
int searchdir(const char *name, struct fs_info *);
void _close_file(struct file *);
size_t pmapi_read_file(uint16_t *handle, void *buf, size_t sectors);
+struct fs_info *get_fs_info(uint8_t hdd, uint8_t partition);
int open_file(const char *name, struct com32_filedata *filedata);
void pm_open_file(com32sys_t *);
void close_file(uint16_t handle);
diff --git a/core/include/multidisk.h b/core/include/multidisk.h
index fc5995b..2515887 100644
--- a/core/include/multidisk.h
+++ b/core/include/multidisk.h
@@ -2,8 +2,15 @@
#define MULTIDISK_H
#include "partiter.h"
+struct muldisk_path {
+ char relative_name[FILENAME_MAX];
+ uint8_t hdd;
+ uint8_t partition;
+};
+
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);
+struct muldisk_path* muldisk_path_parse(const char *path);
#endif /* MULTIDISK_H */
diff --git a/core/multidisk.c b/core/multidisk.c
index 78b751c..78d3dbf 100644
--- a/core/multidisk.c
+++ b/core/multidisk.c
@@ -17,6 +17,8 @@
#include "core.h"
#include "disk.h"
#include "partiter.h"
+#include "fs.h"
+#include "multidisk.h"
/* 0x80 - 0xFF
* BIOS limitation */
@@ -102,3 +104,59 @@ bail:
return -1;
}
+struct muldisk_path* muldisk_path_parse(const char *path)
+{
+ struct muldisk_path *mpath;
+ const char *c = path;
+ char buff[4];
+ uint8_t hdd = 0;
+ uint8_t partition = 0;
+ int i = 0;
+ int mult = 1;
+
+ mpath = malloc(sizeof *mpath);
+ if (!mpath)
+ return NULL;
+
+ if (path[1] == 'h' && path[2] == 'd') {
+ c += 2;
+ /* get hdd number */
+ for (++c; *c && *c != ','; ++c)
+ buff[i++] = *c;
+ if (!*c)
+ goto bail;
+ buff[i] = '\0';
+
+ /* str to uint8_t */
+ while (i--) {
+ hdd += (buff[i] - 48) * mult;
+ mult *= 10;
+ }
+ mpath->hdd = hdd;
+ /* get partition number */
+ i = 0;
+ for (++c; *c && *c != ')'; ++c)
+ buff[i++] = *c;
+ if (!*c)
+ goto bail;
+ buff[i] = '\0';
+
+ /* str to uint8_t */
+ mult = 1;
+ while (i--) {
+ partition += (buff[i] - 48) * mult;
+ mult *= 10;
+ }
+ mpath->partition = partition;
+ i = 0;
+ /* c was on ')' jump it and stop at beginning of path */
+ for (c++; *c; c++)
+ mpath->relative_name[i++] = *c;
+ mpath->relative_name[i] = '\0';
+ return mpath;
+ }
+
+bail:
+ free(mpath);
+ return NULL;
+}
--
1.7.11.3
More information about the Syslinux
mailing list