Move the fnode fields f_diroff and f_dirstart into a referenced directory

match structure with fields dm_entry and dm_dircluster.


git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1432 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Bart Oldeman 2009-06-10 16:10:54 +00:00
parent 3239b3d4b0
commit 8e2b96a70b
6 changed files with 51 additions and 57 deletions

View File

@ -38,12 +38,11 @@ static BYTE *fnode_hRcsId =
struct f_node {
UWORD f_flags; /* file flags */
dmatch *f_dmp; /* this file's dir match */
struct dirent f_dir; /* this file's dir entry image */
ULONG f_dirsector; /* the sector containing dir entry*/
UBYTE f_diridx; /* offset/32 of dir entry in sec*/
UWORD f_diroff; /* offset/32 of the dir entry */
CLUSTER f_dirstart; /* the starting cluster of dir */
/* when dir is not root */
struct dpb FAR *f_dpb; /* the block device for file */

View File

@ -45,7 +45,9 @@ VOID dir_init_fnode(f_node_ptr fnp, CLUSTER dirstart)
fnp->f_sft_idx = 0xff;
fnp->f_flags &= ~SFT_FDATE;
fnp->f_flags |= SFT_FCLEAN;
fnp->f_diroff = 0;
fnp->f_dmp = &sda_tmp_dm;
if (fnp == &fnode[1])
fnp->f_dmp = &sda_tmp_dm_ren;
fnp->f_offset = 0l;
fnp->f_cluster_offset = 0;
@ -55,7 +57,7 @@ VOID dir_init_fnode(f_node_ptr fnp, CLUSTER dirstart)
if (ISFAT32(fnp->f_dpb))
dirstart = fnp->f_dpb->dpb_xrootclst;
#endif
fnp->f_cluster = fnp->f_dirstart = dirstart;
fnp->f_cluster = fnp->f_dmp->dm_dircluster = dirstart;
}
f_node_ptr dir_open(register const char *dirname, f_node_ptr fnp)
@ -81,6 +83,7 @@ f_node_ptr dir_open(register const char *dirname, f_node_ptr fnp)
-- 2001/09/04 ska*/
dir_init_fnode(fnp, 0);
fnp->f_dmp->dm_entry = 0;
dirname += 2; /* Assume FAT style drive */
while(*dirname != '\0')
@ -120,7 +123,7 @@ f_node_ptr dir_open(register const char *dirname, f_node_ptr fnp)
i = TRUE;
break;
}
fnp->f_diroff++;
fnp->f_dmp->dm_entry++;
}
if (!i || !(fnp->f_dir.dir_attrib & D_DIR))
@ -132,6 +135,7 @@ f_node_ptr dir_open(register const char *dirname, f_node_ptr fnp)
/* make certain we've moved off */
/* root */
dir_init_fnode(fnp, getdstart(fnp->f_dpb, &fnp->f_dir));
fnp->f_dmp->dm_entry = 0;
}
}
return fnp;
@ -148,7 +152,7 @@ STATIC void swap_deleted(char *name)
* Read next consequitive directory entry, pointed by fnp.
* If some error occures the other critical
* fields aren't changed, except those used for caching.
* The fnp->f_diroff always corresponds to the directory entry
* The fnp->f_dmp->dm_entry always corresponds to the directory entry
* which has been read.
* Return value.
* 1 - all OK, directory entry having been read is not empty.
@ -161,9 +165,10 @@ COUNT dir_read(REG f_node_ptr fnp)
struct buffer FAR *bp;
REG UWORD secsize = fnp->f_dpb->dpb_secsize;
unsigned sector;
unsigned entry = fnp->f_dmp->dm_entry;
/* can't have more than 65535 directory entries */
if (fnp->f_diroff >= 65535U)
if (entry >= 65535U)
return DE_SEEK;
/* Determine if we hit the end of the directory. If we have, */
@ -171,18 +176,18 @@ COUNT dir_read(REG f_node_ptr fnp)
/* dirent portion of the fnode, set the SFT_FCLEAN bit and leave,*/
/* but only for root directories */
if (fnp->f_dirstart == 0)
if (fnp->f_dmp->dm_dircluster == 0)
{
if (fnp->f_diroff >= fnp->f_dpb->dpb_dirents)
if (entry >= fnp->f_dpb->dpb_dirents)
return DE_SEEK;
fnp->f_dirsector = fnp->f_diroff / (secsize / DIRENT_SIZE) +
fnp->f_dirsector = entry / (secsize / DIRENT_SIZE) +
fnp->f_dpb->dpb_dirstrt;
}
else
{
/* Do a "seek" to the directory position */
fnp->f_offset = fnp->f_diroff * (ULONG)DIRENT_SIZE;
fnp->f_offset = entry * (ULONG)DIRENT_SIZE;
/* Search through the FAT to find the block */
/* that this entry is in. */
@ -211,7 +216,7 @@ COUNT dir_read(REG f_node_ptr fnp)
bp->b_flag &= ~(BFR_DATA | BFR_FAT);
bp->b_flag |= BFR_DIR | BFR_VALID;
fnp->f_diridx = fnp->f_diroff % (secsize / DIRENT_SIZE);
fnp->f_diridx = entry % (secsize / DIRENT_SIZE);
getdirent(&bp->b_buffer[fnp->f_diridx * DIRENT_SIZE], &fnp->f_dir);
swap_deleted(fnp->f_dir.dir_name);
@ -355,26 +360,20 @@ COUNT dos_findfirst(UCOUNT attr, BYTE * name)
if ((fnp->f_dir.dir_attrib & ~(D_RDONLY | D_ARCHIVE)) == D_VOLID &&
fnp->f_dir.dir_name[0] != DELETED)
{
dmp->dm_dircluster = fnp->f_dirstart; /* TE */
memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
#ifdef DEBUG
printf("dos_findfirst: %11s\n", fnp->f_dir.dir_name);
#endif
return SUCCESS;
}
fnp->f_diroff++;
dmp->dm_entry++;
}
/* Now that we've done our failed search, return an error. */
return DE_NFILES;
}
/* Otherwise just do a normal find next */
else
{
dmp->dm_entry = 0;
dmp->dm_dircluster = fnp->f_dirstart;
return dos_findnext();
}
return dos_findnext();
}
/*
@ -389,14 +388,12 @@ COUNT dos_findfirst(UCOUNT attr, BYTE * name)
COUNT dos_findnext(void)
{
REG f_node_ptr fnp;
REG dmatch *dmp = &sda_tmp_dm;
/* Allocate an fnode if possible - error return (0) if not. */
fnp = &fnode[0];
memset(fnp, 0, sizeof(*fnp));
REG dmatch *dmp;
/* Select the default to help non-drive specified path */
/* searches... */
fnp = &fnode[0];
dmp = fnp->f_dmp;
fnp->f_dpb = get_dpb(dmp->dm_drive);
if (media_check(fnp->f_dpb) < 0)
return DE_NFILES;
@ -405,13 +402,10 @@ COUNT dos_findnext(void)
/* Search through the directory to find the entry, but do a */
/* seek first. */
fnp->f_diroff = dmp->dm_entry;
/* Loop through the directory */
while (dir_read(fnp) == 1)
{
++dmp->dm_entry;
++fnp->f_diroff;
if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED
&& !(fnp->f_dir.dir_attrib & D_VOLID))
{
@ -430,7 +424,6 @@ COUNT dos_findnext(void)
fnp->f_dir.dir_attrib))
{
/* If found, transfer it to the dmatch structure */
dmp->dm_dircluster = fnp->f_dirstart;
memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
/* return the result */
return SUCCESS;

View File

@ -317,7 +317,7 @@ STATIC BOOL find_fname(f_node_ptr fnp, char *fcbname, int attr)
{
return TRUE;
}
fnp->f_diroff++;
fnp->f_dmp->dm_entry++;
}
return FALSE;
}
@ -333,13 +333,13 @@ STATIC BOOL find_fname(f_node_ptr fnp, char *fcbname, int attr)
*/
COUNT remove_lfn_entries(f_node_ptr fnp)
{
unsigned original_diroff = fnp->f_diroff;
unsigned original_diroff = fnp->f_dmp->dm_entry;
while (TRUE)
{
if (fnp->f_diroff == 0)
if (fnp->f_dmp->dm_entry == 0)
break;
fnp->f_diroff--;
fnp->f_dmp->dm_entry--;
if (dir_read(fnp) <= 0)
return DE_BLKINVLD;
if (fnp->f_dir.dir_attrib != D_LFN)
@ -348,7 +348,7 @@ COUNT remove_lfn_entries(f_node_ptr fnp)
fnp->f_flags &= ~SFT_FCLEAN;
if (!dir_write(fnp)) return DE_BLKINVLD;
}
fnp->f_diroff = original_diroff;
fnp->f_dmp->dm_entry = original_diroff;
if (dir_read(fnp) <= 0)
return DE_BLKINVLD;
@ -510,7 +510,7 @@ COUNT dos_rmdir(BYTE * path)
if (fnp->f_dir.dir_name[0] != '.' || fnp->f_dir.dir_name[1] != ' ')
return DE_ACCESS;
fnp->f_diroff++;
fnp->f_dmp->dm_entry++;
dir_read(fnp);
/* secondard entry should be ".." */
if (fnp->f_dir.dir_name[0] != '.' || fnp->f_dir.dir_name[1] != '.')
@ -518,13 +518,13 @@ COUNT dos_rmdir(BYTE * path)
/* Now search through the directory and make certain */
/* that there are no entries */
fnp->f_diroff++;
fnp->f_dmp->dm_entry++;
while (dir_read(fnp) == 1)
{
/* If anything was found, exit with an error. */
if (fnp->f_dir.dir_name[0] != DELETED && fnp->f_dir.dir_attrib != D_LFN)
return DE_ACCESS;
fnp->f_diroff++;
fnp->f_dmp->dm_entry++;
}
/* next, split the passed dir into components (i.e. - */
@ -567,7 +567,7 @@ COUNT dos_rename(BYTE * path1, BYTE * path2, int attrib)
if (find_fname(fnp2, fcbname, attrib))
return DE_ACCESS;
if (fnp1->f_dirstart == fnp2->f_dirstart)
if (fnp1->f_dmp->dm_dircluster == fnp2->f_dmp->dm_dircluster)
{
/* rename in the same directory: change the directory entry in-place */
fnp2 = fnp1;
@ -676,7 +676,7 @@ STATIC BOOL find_free(f_node_ptr fnp)
{
if (fnp->f_dir.dir_name[0] == DELETED)
return TRUE;
fnp->f_diroff++;
fnp->f_dmp->dm_entry++;
}
return rc >= 0;
}
@ -695,7 +695,7 @@ STATIC int alloc_find_free(f_node_ptr fnp, char *path, char *fcbname)
/* find an empty slot, we need to abort. */
if (find_free(fnp) == 0)
{
if (fnp->f_dirstart == 0)
if (fnp->f_dmp->dm_dircluster == 0)
{
fnp->f_flags |= SFT_FCLEAN;
return DE_TOOMANY;
@ -866,7 +866,7 @@ COUNT dos_mkdir(BYTE * dir)
if (find_fname(fnp, fcbname, D_ALL))
return DE_ACCESS;
parent = fnp->f_dirstart;
parent = fnp->f_dmp->dm_dircluster;
ret = alloc_find_free(fnp, dir, fcbname);
if (ret != SUCCESS)
@ -903,6 +903,7 @@ COUNT dos_mkdir(BYTE * dir)
/* directory just under the root, ".." pointer is 0. */
dir_init_fnode(fnp, free_fat);
fnp->f_dmp->dm_entry = 0;
find_free(fnp);
/* Create the "." entry */
@ -1051,7 +1052,7 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode)
/* If seek is to earlier in file than current position, */
/* we have to follow chain from the beginning again... */
/* Set internal index and cluster size. */
fnp->f_cluster = fnp->f_sft_idx == 0xff ? fnp->f_dirstart :
fnp->f_cluster = fnp->f_sft_idx == 0xff ? fnp->f_dmp->dm_dircluster :
getdstart(fnp->f_dpb, &fnp->f_dir);
fnp->f_cluster_offset = 0;
}
@ -1134,7 +1135,7 @@ STATIC COUNT dos_extend(f_node_ptr fnp)
#ifdef DSK_DEBUG
printf("write %d links; dir offset %ld, cluster %d\n",
fnp->f_count, fnp->f_diroff, fnp->f_cluster);
fnp->f_count, fnp->f_dmp->dm_entry, fnp->f_cluster);
#endif
xfr_cnt = count < (ULONG) secsize - boff ?
@ -1430,7 +1431,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
#ifdef DSK_DEBUG
printf("r/w %d links; dir offset %d, cluster %d, mode %x\n",
fnp->f_count, fnp->f_diroff, fnp->f_cluster, mode);
fnp->f_count, fnp->f_dmp->dm_entry, fnp->f_cluster, mode);
#endif
/* Get the block we need from cache */
@ -1557,7 +1558,7 @@ int dos_cd(char * PathName)
/* problem: RBIL table 01643 does not give a FAT32 field for the
CDS start cluster. But we are not using this field ourselves */
cdsp->cdsStrtClst = (UWORD)fnp->f_dirstart;
cdsp->cdsStrtClst = (UWORD)fnp->f_dmp->dm_dircluster;
return SUCCESS;
}
#endif

View File

@ -46,8 +46,8 @@ static BYTE *Globals_hRcsId =
#include "sft.h"
#include "cds.h"
#include "exe.h"
#include "fnode.h"
#include "dirmatch.h"
#include "fnode.h"
#include "file.h"
#include "clock.h"
#include "kbd.h"
@ -308,6 +308,7 @@ extern UWORD ASM wAttr;
extern BYTE ASM default_drive; /* default drive for dos */
extern dmatch ASM sda_tmp_dm; /* Temporary directory match buffer */
extern dmatch ASM sda_tmp_dm_ren; /* 2nd Temporary directory match buffer */
extern BYTE
ASM internal_data[], /* sda areas */
ASM swap_always[], /* " " */

View File

@ -7,7 +7,6 @@
#include "mcb.h"
#include "sft.h"
#include "fat.h"
#include "fnode.h"
#include "file.h"
#include "cds.h"
#include "device.h"

View File

@ -617,19 +617,20 @@ _ext_open_mode dw 0 ;2E1 - extended open mode
; Pad to 0620h
times (300h - ($ - _internal_data)) db 0
global _szNames
_szNames:
;; times 11 db 0
global _FcbSearchBuffer ; during FCB search 1st/next use bottom
_FcbSearchBuffer: ; of error stack as scratch buffer
; times 43 db 0 ; - only used during int 21 call
; stacks are made to initialize to no-ops so that high-water
; testing can be performed
global apistk_bottom
apistk_bottom:
times STACK_SIZE dw 0x9090 ;300 - Error Processing Stack
; use bottom of error stack as scratch buffer
; - only used during int 21 call
global _sda_tmp_dm_ren
_sda_tmp_dm_ren:times 21 db 0x90 ;300 - 21 byte srch state for rename
global _SearchDir_ren
_SearchDir_ren: times 32 db 0x90 ;315 - 32 byte dir entry for rename
; stacks are made to initialize to no-ops so that high-water
; testing can be performed
times STACK_SIZE*2-($-apistk_bottom) db 0x90
;300 - Error Processing Stack
global _error_tos
_error_tos:
times STACK_SIZE dw 0x9090 ;480 - Disk Function Stack