Gene Cumm
2009-Mar-05 00:32 UTC
[syslinux] [PATCH 3/5] COM32: Improve opendir() to deal with no '/' at end of string
From: Gene Cumm <gene.cumm at gmail.com> COM32: Improve opendir() to deal with no '/' at end of string Signed-off-by: Gene Cumm <gene.cumm at gmail.com> --- Originally, this was going to be 3 patches but I ended up doing a little more. Currently, the COMBOOT call required a '/' to recognize that you're searching for a directory. This checks and automatically appends a '/' to the end of the pathname string (by creating another string temporarily) then making the COMBOOT call. diff --git a/com32/lib/opendir.c b/com32/lib/opendir.c index aa2ba5b..7063f8c 100644 --- a/com32/lib/opendir.c +++ b/com32/lib/opendir.c @@ -16,10 +17,20 @@ DIR *opendir(const char *pathname) { DIR *newdir; com32sys_t regs; + char *tpath; + int pathlen; newdir = NULL; + pathlen = strlen(pathname); + if (pathname[pathlen-1] != '/') { + tpath = calloc(1, pathlen + 2); + strcpy(tpath, pathname); + strcpy(tpath + pathlen, "/"); + } else { + tpath = pathname; + } - strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size); + strlcpy(__com32.cs_bounce, tpath, __com32.cs_bounce_size); regs.eax.w[0] = 0x0020; regs.esi.w[0] = OFFS(__com32.cs_bounce); @@ -34,6 +45,10 @@ DIR *opendir(const char *pathname) newdir->dd_fd = regs.esi.w[0]; newdir->dd_sect = regs.eax.l; newdir->dd_stat = 0; + errno = 0; + } else { + /* ENOTDIR is another but a file must exist */ + errno = ENOENT; } /* We're done */
H. Peter Anvin
2009-Mar-06 06:11 UTC
[syslinux] [PATCH 3/5] COM32: Improve opendir() to deal with no '/' at end of string
Gene Cumm wrote:> > Currently, the COMBOOT call required a '/' to recognize that you're > searching for a directory. This checks and automatically appends a > '/' to the end of the pathname string (by creating another string > temporarily) then making the COMBOOT call. >I'm concerned about doing this if we ever intend to make this work properly over TFTP. -hpa -- H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.