From a21bcd8a856ab0bec1912177cad5f55712c61dff Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Wed, 10 Jun 2009 19:02:24 +0000 Subject: [PATCH] Split 8.3 FCB-style filename extraction from ParseDosName into a new ConvertNameSZToName83 function, also used by dir_open(). git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1433 6ac86273-5f31-0410-b378-82cca8765d1b --- kernel/dosnames.c | 29 ++++++----------------------- kernel/fatdir.c | 42 ++++++++++++++++++++++++------------------ kernel/fatfs.c | 6 +++++- kernel/proto.h | 4 ++-- 4 files changed, 37 insertions(+), 44 deletions(-) diff --git a/kernel/dosnames.c b/kernel/dosnames.c index 0d53d6a..f06b178 100644 --- a/kernel/dosnames.c +++ b/kernel/dosnames.c @@ -75,13 +75,13 @@ VOID XlateLcase(BYTE * szFname, COUNT nChars) returns number of characters in the directory component (up to the last backslash, including d:) or negative if error */ -int ParseDosName(const char *filename, char *fcbname, BOOL bAllowWildcards) +int ParseDosName(const char *filename, BOOL bAllowWildcards) { - int nDirCnt, nFileCnt, nExtCnt; - const char *lpszLclDir, *lpszLclFile, *lpszLclExt; + int nDirCnt; + const char *lpszLclDir, *lpszLclFile; /* Initialize the users data fields */ - nDirCnt = nFileCnt = nExtCnt = 0; + nDirCnt = 0; /* NB: this code assumes ASCII */ @@ -101,12 +101,9 @@ int ParseDosName(const char *filename, char *fcbname, BOOL bAllowWildcards) filename = lpszLclFile; while (bAllowWildcards ? WildChar(*filename) : NameChar(*filename)) - { - ++nFileCnt; ++filename; - } - if (nFileCnt == 0) + if (filename == lpszLclFile) { int err = DE_PATHNOTFND; if (bAllowWildcards && *filename == '\0' && @@ -118,35 +115,21 @@ int ParseDosName(const char *filename, char *fcbname, BOOL bAllowWildcards) /* Now we have pointers set to the directory portion and the */ /* file portion. Now determine the existance of an extension. */ - lpszLclExt = filename; if ('.' == *filename) { - lpszLclExt = ++filename; + ++filename; while (*filename) { if (bAllowWildcards ? WildChar(*filename) : NameChar(*filename)) - { - ++nExtCnt; ++filename; - } else - { return DE_FILENOTFND; - } } } else if (*filename) return DE_FILENOTFND; - /* Finally copy whatever the user wants extracted to the user's */ - /* buffers. */ - memset(fcbname, ' ', FNAME_SIZE + FEXT_SIZE); - memcpy(fcbname, lpszLclFile, nFileCnt); - memcpy(&fcbname[FNAME_SIZE], lpszLclExt, nExtCnt); - - /* Clean up before leaving */ - return nDirCnt; } diff --git a/kernel/fatdir.c b/kernel/fatdir.c index fb757c7..7d441e8 100644 --- a/kernel/fatdir.c +++ b/kernel/fatdir.c @@ -98,18 +98,7 @@ f_node_ptr dir_open(register const char *dirname, f_node_ptr fnp) /* Convert the name into an absolute name for */ /* comparison... */ - memset(fcbname, ' ', FNAME_SIZE + FEXT_SIZE); - - for (i = 0; i < FNAME_SIZE + FEXT_SIZE; i++, dirname++) - { - char c = *dirname; - if (c == '.') - i = FNAME_SIZE - 1; - else if (c != '\0' && c != '\\') - fcbname[i] = c; - else - break; - } + dirname = ConvertNameSZToName83(fcbname, dirname); /* Now search through the directory to */ /* find the entry... */ @@ -309,7 +298,7 @@ COUNT dos_findfirst(UCOUNT attr, BYTE * name) /* current directory, do a seek and read. */ /* Parse out the file name */ - i = ParseDosName(name, SearchDir.dir_name, TRUE); + i = ParseDosName(name, TRUE); if (i < SUCCESS) return i; /* @@ -344,13 +333,10 @@ COUNT dos_findfirst(UCOUNT attr, BYTE * name) } /* Now initialize the dirmatch structure. */ - + ConvertNameSZToName83(dmp->dm_name_pat, &name[i]); dmp->dm_drive = name[0] - 'A'; dmp->dm_attr_srch = attr; - /* Copy the raw pattern from our data segment to the DTA. */ - fmemcpy(dmp->dm_name_pat, SearchDir.dir_name, FNAME_SIZE + FEXT_SIZE); - if ((attr & (D_VOLID|D_DIR))==D_VOLID) { /* Now do the search */ @@ -393,7 +379,7 @@ COUNT dos_findnext(void) /* Select the default to help non-drive specified path */ /* searches... */ fnp = &fnode[0]; - dmp = fnp->f_dmp; + dmp = &sda_tmp_dm; fnp->f_dpb = get_dpb(dmp->dm_drive); if (media_check(fnp->f_dpb) < 0) return DE_NFILES; @@ -503,3 +489,23 @@ int FileName83Length(BYTE * filename83) } #endif +/* this routine converts a name portion of a fully qualified path */ +/* name, so . and .. are not allowed, only straightforward 8+3 names */ +const char *ConvertNameSZToName83(char *fcbname, const char *dirname) +{ + int i; + memset(fcbname, ' ', FNAME_SIZE + FEXT_SIZE); + + for (i = 0; i < FNAME_SIZE + FEXT_SIZE; i++, dirname++) + { + char c = *dirname; + if (c == '.') + i = FNAME_SIZE - 1; + else if (c != '\0' && c != '\\') + fcbname[i] = c; + else + break; + } + return dirname; +} + diff --git a/kernel/fatfs.c b/kernel/fatfs.c index 8b363b3..72e64ae 100644 --- a/kernel/fatfs.c +++ b/kernel/fatfs.c @@ -260,7 +260,7 @@ COUNT dos_close(COUNT fd) f_node_ptr split_path(char * path, char * fcbname, f_node_ptr fnp) { /* Start off by parsing out the components. */ - int dirlength = ParseDosName(path, fcbname, FALSE); + int dirlength = ParseDosName(path, FALSE); if (dirlength < SUCCESS) return (f_node_ptr) 0; @@ -292,6 +292,10 @@ f_node_ptr split_path(char * path, char * fcbname, f_node_ptr fnp) fnp = dir_open(path, fnp); path[dirlength] = tmp; } + + /* Extract the 8.3 filename from the path */ + ConvertNameSZToName83(fcbname, &path[dirlength]); + return fnp; } diff --git a/kernel/proto.h b/kernel/proto.h index 38e8a4c..a336f5e 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -130,7 +130,7 @@ VOID ASMCFUNC DosIdle_hlt(void); #endif /* dosnames.c */ -int ParseDosName(const char *, char *, BOOL); +int ParseDosName(const char *, BOOL); /* error.c */ VOID dump(void); @@ -146,7 +146,7 @@ BOOL dir_write_update(REG f_node_ptr fnp, BOOL update); COUNT dos_findfirst(UCOUNT attr, BYTE * name); COUNT dos_findnext(void); void ConvertName83ToNameSZ(BYTE FAR * destSZ, BYTE FAR * srcFCBName); -int FileName83Length(BYTE * filename83); +const char *ConvertNameSZToName83(char *destFCBName, const char *srcSZ); /* fatfs.c */ struct dpb FAR *get_dpb(COUNT dsk);