Optimization: changed find_fname() to call split_path() because find_fname

was always preceeded by split_path(). The return code is now an error code,
DE_FILENOTFND, DE_PATHNOTFND, or SUCCESS, depending on the failure.


git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1445 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Bart Oldeman 2009-06-16 15:22:16 +00:00
parent d20b59ebe0
commit 5252faa425

View File

@ -39,7 +39,7 @@ BYTE *RcsId = "$Id$";
/* */ /* */
STATIC f_node_ptr sft_to_fnode(int fd); STATIC f_node_ptr sft_to_fnode(int fd);
STATIC void fnode_to_sft(f_node_ptr fnp); STATIC void fnode_to_sft(f_node_ptr fnp);
STATIC BOOL find_fname(f_node_ptr, int); STATIC int find_fname(const char *path, int attr, f_node_ptr fnp);
/* /// Added - Ron Cemer */ /* /// Added - Ron Cemer */
STATIC int merge_file_changes(f_node_ptr fnp, int collect); STATIC int merge_file_changes(f_node_ptr fnp, int collect);
STATIC BOOL find_free(f_node_ptr); STATIC BOOL find_free(f_node_ptr);
@ -131,17 +131,12 @@ STATIC void init_direntry(struct dirent *dentry, unsigned attrib,
int dos_open(char *path, unsigned flags, unsigned attrib, int fd) int dos_open(char *path, unsigned flags, unsigned attrib, int fd)
{ {
REG f_node_ptr fnp; REG f_node_ptr fnp = sft_to_fnode(fd);
int status = S_OPENED; int status = find_fname(path, D_ALL | attrib, fnp);
/* next split the passed dir into comopnents (i.e. - path to */
/* new directory and name of new directory. */
if ((fnp = split_path(path, sft_to_fnode(fd))) == NULL)
return DE_PATHNOTFND;
/* Check that we don't have a duplicate name, so if we */ /* Check that we don't have a duplicate name, so if we */
/* find one, truncate it (O_CREAT). */ /* find one, truncate it (O_CREAT). */
if (find_fname(fnp, D_ALL | attrib)) if (status == SUCCESS)
{ {
if (flags & O_TRUNC) if (flags & O_TRUNC)
{ {
@ -171,13 +166,14 @@ int dos_open(char *path, unsigned flags, unsigned attrib, int fd)
((fnp->f_dir.dir_attrib & D_RDONLY) && ((fnp->f_dir.dir_attrib & D_RDONLY) &&
((flags & O_ACCMODE) != O_RDONLY))) ((flags & O_ACCMODE) != O_RDONLY)))
return DE_ACCESS; return DE_ACCESS;
status = S_OPENED;
} }
else else
{ {
return DE_FILEEXISTS; return DE_FILEEXISTS;
} }
} }
else if (flags & O_CREAT) else if (status == DE_FILENOTFND && (flags & O_CREAT))
{ {
int ret = alloc_find_free(fnp, path); int ret = alloc_find_free(fnp, path);
if (ret != SUCCESS) if (ret != SUCCESS)
@ -188,7 +184,7 @@ int dos_open(char *path, unsigned flags, unsigned attrib, int fd)
{ {
/* open: If we can't find the file, just return a not */ /* open: If we can't find the file, just return a not */
/* found error. */ /* found error. */
return DE_FILENOTFND; return status;
} }
if (status != S_OPENED) if (status != S_OPENED)
@ -295,18 +291,23 @@ BOOL fcbmatch(const char *fcbname1, const char *fcbname2)
return memcmp(fcbname1, fcbname2, FNAME_SIZE + FEXT_SIZE) == 0; return memcmp(fcbname1, fcbname2, FNAME_SIZE + FEXT_SIZE) == 0;
} }
STATIC BOOL find_fname(f_node_ptr fnp, int attr) STATIC int find_fname(const char *path, int attr, f_node_ptr fnp)
{ {
/* check for leading backslash and open the directory given that */
/* contains the file given by path. */
if ((fnp = split_path(path, fnp)) == NULL)
return DE_PATHNOTFND;
while (dir_read(fnp) == 1) while (dir_read(fnp) == 1)
{ {
if (fcbmatch(fnp->f_dir.dir_name, fnp->f_dmp->dm_name_pat) if (fcbmatch(fnp->f_dir.dir_name, fnp->f_dmp->dm_name_pat)
&& (fnp->f_dir.dir_attrib & ~(D_RDONLY | D_ARCHIVE | attr)) == 0) && (fnp->f_dir.dir_attrib & ~(D_RDONLY | D_ARCHIVE | attr)) == 0)
{ {
return TRUE; return SUCCESS;
} }
fnp->f_dmp->dm_entry++; fnp->f_dmp->dm_entry++;
} }
return FALSE; return DE_FILENOTFND;
} }
/* Description. /* Description.
@ -437,18 +438,12 @@ STATIC COUNT delete_dir_entry(f_node_ptr fnp)
COUNT dos_delete(BYTE * path, int attrib) COUNT dos_delete(BYTE * path, int attrib)
{ {
REG f_node_ptr fnp; REG f_node_ptr fnp = &fnode[0];
/* first split the passed dir into components (i.e. - */
/* path to new directory and name of new directory */
if ((fnp = split_path(path, &fnode[0])) == NULL)
{
return DE_PATHNOTFND;
}
/* Check that we don't have a duplicate name, so if we */ /* Check that we don't have a duplicate name, so if we */
/* find one, it's an error. */ /* find one, it's an error. */
if (find_fname(fnp, attrib)) int ret = find_fname(path, attrib, fnp);
if (ret == SUCCESS)
{ {
/* Do not delete directories or r/o files */ /* Do not delete directories or r/o files */
/* lfn entries and volume labels are only found */ /* lfn entries and volume labels are only found */
@ -461,7 +456,7 @@ COUNT dos_delete(BYTE * path, int attrib)
} }
else else
/* No such file, return the error */ /* No such file, return the error */
return DE_FILENOTFND; return ret;
} }
COUNT dos_rmdir(BYTE * path) COUNT dos_rmdir(BYTE * path)
@ -495,7 +490,7 @@ COUNT dos_rmdir(BYTE * path)
fnp->f_dmp->dm_entry++; fnp->f_dmp->dm_entry++;
dir_read(fnp); dir_read(fnp);
/* secondard entry should be ".." */ /* second entry should be ".." */
if (fnp->f_dir.dir_name[0] != '.' || fnp->f_dir.dir_name[1] != '.') if (fnp->f_dir.dir_name[0] != '.' || fnp->f_dir.dir_name[1] != '.')
return DE_ACCESS; return DE_ACCESS;
@ -512,8 +507,7 @@ COUNT dos_rmdir(BYTE * path)
/* next, split the passed dir into components (i.e. - */ /* next, split the passed dir into components (i.e. - */
/* path to new directory and name of new directory */ /* path to new directory and name of new directory */
if ((fnp = split_path(path, &fnode[0])) == NULL || if (find_fname(path, D_ALL, fnp) != SUCCESS)
!find_fname(fnp, D_ALL))
/* this error should not happen because dir_open() succeeded above */ /* this error should not happen because dir_open() succeeded above */
return DE_PATHNOTFND; return DE_PATHNOTFND;
@ -532,23 +526,18 @@ COUNT dos_rename(BYTE * path1, BYTE * path2, int attrib)
if (!fstrcmp(path1, cdsp->cdsCurrentPath)) if (!fstrcmp(path1, cdsp->cdsCurrentPath))
return DE_RMVCUDIR; return DE_RMVCUDIR;
/* first split the passed source into components (i.e. - path to*/ /* first check if the source file exists */
/* old file name and name of old file name */ fnp1 = &fnode[0];
if ((fnp1 = split_path(path1, &fnode[0])) == NULL) ret = find_fname(path1, attrib, fnp1);
return DE_PATHNOTFND; if (ret != SUCCESS)
return ret;
if (!find_fname(fnp1, attrib))
return DE_FILENOTFND;
/* next split the passed target into components (i.e. - path to */
/* new file name and name of new file name */
if ((fnp2 = split_path(path2, &fnode[1])) == NULL)
return DE_PATHNOTFND;
/* Check that we don't have a duplicate name, so if we find */ /* Check that we don't have a duplicate name, so if we find */
/* one, it's an error. */ /* one, it's an error. */
if (find_fname(fnp2, attrib)) fnp2 = &fnode[1];
return DE_ACCESS; ret = find_fname(path2, attrib, fnp2);
if (ret != DE_FILENOTFND)
return ret == SUCCESS ? DE_ACCESS : ret;
fcbname = fnp2->f_dmp->dm_name_pat; fcbname = fnp2->f_dmp->dm_name_pat;
if (fnp1->f_dmp->dm_dircluster == fnp2->f_dmp->dm_dircluster) if (fnp1->f_dmp->dm_dircluster == fnp2->f_dmp->dm_dircluster)
@ -816,13 +805,6 @@ COUNT dos_mkdir(BYTE * dir)
CLUSTER free_fat, parent; CLUSTER free_fat, parent;
COUNT ret; COUNT ret;
/* first split the passed dir into components (i.e. - */
/* path to new directory and name of new directory */
if ((fnp = split_path(dir, &fnode[0])) == NULL)
{
return DE_PATHNOTFND;
}
/* check that the resulting combined path does not exceed /* check that the resulting combined path does not exceed
the 67 MAX_CDSPATH limit. this leads to problems: the 67 MAX_CDSPATH limit. this leads to problems:
A) you can't CD to this directory later A) you can't CD to this directory later
@ -836,8 +818,10 @@ COUNT dos_mkdir(BYTE * dir)
/* Check that we don't have a duplicate name, so if we */ /* Check that we don't have a duplicate name, so if we */
/* find one, it's an error. */ /* find one, it's an error. */
if (find_fname(fnp, D_ALL)) fnp = &fnode[0];
return DE_ACCESS; ret = find_fname(dir, D_ALL, fnp);
if (ret != DE_FILENOTFND)
return ret == SUCCESS ? DE_ACCESS : ret;
parent = fnp->f_dmp->dm_dircluster; parent = fnp->f_dmp->dm_dircluster;
@ -1533,16 +1517,9 @@ int dos_cd(char * PathName)
#ifndef IPL #ifndef IPL
COUNT dos_getfattr(BYTE * name) COUNT dos_getfattr(BYTE * name)
{ {
f_node_ptr fnp; f_node_ptr fnp = &fnode[0];
int ret = find_fname(name, D_ALL, fnp);
/* split the passed dir into components (i.e. - path to */ return ret == SUCCESS ? fnp->f_dir.dir_attrib : ret;
/* new directory and name of new directory. */
if ((fnp = split_path(name, &fnode[0])) == NULL)
return DE_PATHNOTFND;
if (find_fname(fnp, D_ALL))
return fnp->f_dir.dir_attrib;
return DE_FILENOTFND;
} }
COUNT dos_setfattr(BYTE * name, UWORD attrp) COUNT dos_setfattr(BYTE * name, UWORD attrp)
@ -1559,13 +1536,10 @@ COUNT dos_setfattr(BYTE * name, UWORD attrp)
if ((attrp & (D_VOLID | 0xC0)) != 0) if ((attrp & (D_VOLID | 0xC0)) != 0)
return DE_ACCESS; return DE_ACCESS;
/* split the passed dir into components (i.e. - path to */ fnp = &fnode[0];
/* new directory and name of new directory. */ rc = find_fname(name, D_ALL, fnp);
if ((fnp = split_path(name, &fnode[0])) == NULL) if (rc != SUCCESS)
return DE_PATHNOTFND; return rc;
if (!find_fname(fnp, D_ALL))
return DE_FILENOTFND;
/* if caller tries to set DIR on non-directory, return error */ /* if caller tries to set DIR on non-directory, return error */
if ((attrp & D_DIR) && !(fnp->f_dir.dir_attrib & D_DIR)) if ((attrp & D_DIR) && !(fnp->f_dir.dir_attrib & D_DIR))