[syslinux] [PATCH 06/12] core: multidisk parser related changes

Matt Fleming matt at console-pimps.org
Mon Oct 15 06:42:04 PDT 2012


On Mon, 2012-08-20 at 05:16 -0300, Andre Ericson wrote:
> 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);

You need to be checking the return value of get_fs_info().

>          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);

... and here.

-- 
Matt Fleming, Intel Open Source Technology Center




More information about the Syslinux mailing list