This is the main change to eliminate far fnodes.
SFT info is copied from and to the two near fnodes. Some cleanups still follow. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1397 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
parent
39e6570be9
commit
d7d201a53b
@ -55,9 +55,9 @@ struct f_node {
|
||||
CLUSTER f_cluster; /* the cluster we are at */
|
||||
};
|
||||
|
||||
#define F_DMOD 1 /* directory has been modified */
|
||||
#define F_DMOD 0x40 /* directory has been modified */
|
||||
#define F_DDIR 2 /* fnode is assigned to dir */
|
||||
#define F_DDATE 4 /* date set using setdate */
|
||||
#define F_DDATE 0x4000 /* date set using setdate */
|
||||
|
||||
typedef struct f_node *f_node_ptr;
|
||||
|
||||
|
@ -80,7 +80,5 @@ struct lol {
|
||||
unsigned char os_major; /* 6d major DOS version */
|
||||
unsigned char rev_number; /* 6e minor DOS version */
|
||||
unsigned char version_flags; /* 6f DOS version flags */
|
||||
struct f_node FAR *f_nodes; /* 70 pointer to the array */
|
||||
unsigned short f_nodes_cnt; /* 74 number of allocated f_nodes */
|
||||
char *os_release; /* 76 near pointer to os_release string */
|
||||
char *os_release; /* 70 near pointer to os_release string */
|
||||
};
|
||||
|
@ -234,7 +234,6 @@ STATIC void umb_init(void);
|
||||
|
||||
void HMAconfig(int finalize);
|
||||
STATIC void config_init_buffers(int anzBuffers); /* from BLOCKIO.C */
|
||||
STATIC void config_init_fnodes(int f_nodes_cnt);
|
||||
|
||||
#ifdef I86
|
||||
STATIC VOID FAR * AlignParagraph(VOID FAR * lpPtr);
|
||||
@ -348,9 +347,6 @@ void PreConfig(void)
|
||||
LoL->DPBp =
|
||||
DynAlloc("DPBp", blk_dev.dh_name[0], sizeof(struct dpb));
|
||||
|
||||
/* Initialize the file table */
|
||||
config_init_fnodes(Config.cfgFiles);
|
||||
|
||||
LoL->sfthead = MK_FP(FP_SEG(LoL), 0xcc); /* &(LoL->firstsftt) */
|
||||
/* LoL->FCBp = (sfttbl FAR *)&FcbSft; */
|
||||
/* LoL->FCBp = (sfttbl FAR *)
|
||||
@ -362,7 +358,6 @@ void PreConfig(void)
|
||||
LoL->CDSp = KernelAlloc(sizeof(struct cds) * LoL->lastdrive, 'L', 0);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Preliminary:\n f_node 0x%p\n", LoL->f_nodes);
|
||||
/* printf(" FCB table 0x%p\n",LoL->FCBp);*/
|
||||
printf(" sft table 0x%p\n", LoL->sfthead);
|
||||
printf(" CDS table 0x%p\n", LoL->CDSp);
|
||||
@ -440,9 +435,6 @@ void PostConfig(void)
|
||||
|
||||
DebugPrintf(("starting FAR allocations at %x\n", base_seg));
|
||||
|
||||
/* Initialize the file table */
|
||||
config_init_fnodes(Config.cfgFiles);
|
||||
|
||||
/* Begin by initializing our system buffers */
|
||||
/* dma_scratch = (BYTE FAR *) KernelAllocDma(BUFFERSIZE); */
|
||||
#ifdef DEBUG
|
||||
@ -465,7 +457,6 @@ void PostConfig(void)
|
||||
LoL->CDSp = KernelAlloc(sizeof(struct cds) * LoL->lastdrive, 'L', Config.cfgLastdriveHigh);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Final: \n f_node 0x%p\n", LoL->f_nodes);
|
||||
/* printf(" FCB table 0x%p\n",LoL->FCBp);*/
|
||||
printf(" sft table 0x%p\n", LoL->sfthead->sftt_next);
|
||||
printf(" CDS table 0x%p\n", LoL->CDSp);
|
||||
@ -1791,21 +1782,6 @@ STATIC void config_init_buffers(int wantedbuffers)
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void config_init_fnodes(int f_nodes_cnt)
|
||||
{
|
||||
struct f_node FAR *p;
|
||||
size_t bytes;
|
||||
|
||||
/* number of allocated files */
|
||||
LoL->f_nodes_cnt = f_nodes_cnt;
|
||||
bytes = f_nodes_cnt * sizeof(struct f_node);
|
||||
|
||||
p = HMAalloc(bytes);
|
||||
if (p == NULL)
|
||||
p = KernelAlloc(bytes, 'F', 0);
|
||||
LoL->f_nodes = p;
|
||||
}
|
||||
|
||||
/*
|
||||
Undocumented feature: ANYDOS
|
||||
will report to MSDOS programs just the version number
|
||||
|
@ -598,7 +598,7 @@ long DosOpenSft(char FAR * fname, unsigned flags, unsigned attrib)
|
||||
return DE_ACCESS;
|
||||
|
||||
sftp->sft_count++;
|
||||
result = dos_open(PriPathName, flags, attrib);
|
||||
result = dos_open(PriPathName, flags, attrib, sft_idx);
|
||||
if (result >= 0)
|
||||
{
|
||||
int status = (int)(result >> 16);
|
||||
@ -754,10 +754,7 @@ COUNT DosCloseSft(int sft_idx, BOOL commitonly)
|
||||
}
|
||||
|
||||
/* else call file system handler */
|
||||
if (commitonly || sftp->sft_count > 1)
|
||||
result = dos_commit(sftp->sft_status);
|
||||
else
|
||||
result = dos_close(sftp->sft_status);
|
||||
result = dos_close(sftp->sft_status);
|
||||
if (commitonly || result != SUCCESS)
|
||||
return result;
|
||||
|
||||
|
134
kernel/fatfs.c
134
kernel/fatfs.c
@ -37,8 +37,10 @@ BYTE *RcsId = "$Id$";
|
||||
/* */
|
||||
/* function prototypes */
|
||||
/* */
|
||||
STATIC void sft_to_fnode(f_node_ptr fnp, int fd);
|
||||
f_node_ptr xlt_fd(COUNT);
|
||||
COUNT xlt_fnp(f_node_ptr);
|
||||
STATIC void fnode_to_sft(f_node_ptr fnp, int fd);
|
||||
STATIC void save_far_f_node(f_node_ptr fnp);
|
||||
STATIC f_node_ptr split_path(char *, char *, f_node_ptr fnp);
|
||||
STATIC BOOL find_fname(f_node_ptr, char *, int);
|
||||
@ -135,7 +137,7 @@ STATIC void init_direntry(struct dirent *dentry, unsigned attrib,
|
||||
/* see DosOpenSft(), dosfns.c for an explanation of the flags bits */
|
||||
/* directory opens are allowed here; these are not allowed by DosOpenSft*/
|
||||
|
||||
long dos_open(char *path, unsigned flags, unsigned attrib)
|
||||
long dos_open(char *path, unsigned flags, unsigned attrib, int fd)
|
||||
{
|
||||
REG f_node_ptr fnp;
|
||||
char fcbname[FNAME_SIZE + FEXT_SIZE];
|
||||
@ -148,7 +150,7 @@ long dos_open(char *path, unsigned flags, unsigned attrib)
|
||||
|
||||
/* next split the passed dir into comopnents (i.e. - path to */
|
||||
/* new directory and name of new directory. */
|
||||
if ((fnp = split_path(path, fcbname, &fnode[0])) == NULL)
|
||||
if ((fnp = split_path(path, fcbname, xlt_fd(fd))) == NULL)
|
||||
return DE_PATHNOTFND;
|
||||
|
||||
/* Check that we don't have a duplicate name, so if we */
|
||||
@ -284,31 +286,6 @@ COUNT dos_close(COUNT fd)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
COUNT dos_commit(COUNT fd)
|
||||
{
|
||||
f_node_ptr fnp, fnp2;
|
||||
|
||||
/* Translate the fd into a useful pointer */
|
||||
fnp = xlt_fd(fd);
|
||||
|
||||
/* If the fd was invalid because it was out of range or the */
|
||||
/* requested file was not open, tell the caller and exit */
|
||||
/* note: an invalid fd is indicated by a 0 return */
|
||||
if (fnp == (f_node_ptr) 0)
|
||||
return DE_INVLDHNDL;
|
||||
fnp2 = get_f_node(&fnode[1]);
|
||||
if (fnp2 == (f_node_ptr) 0)
|
||||
{
|
||||
return DE_INVLDHNDL;
|
||||
}
|
||||
|
||||
/* a copy of the fnode is closed meaning that the directory info
|
||||
is updated etc, but we keep our old info */
|
||||
memcpy(fnp2, fnp, sizeof(*fnp));
|
||||
save_far_f_node(fnp2);
|
||||
return dos_close(xlt_fnp(fnp2));
|
||||
}
|
||||
|
||||
/* */
|
||||
/* split a path into it's component directory and file name */
|
||||
/* */
|
||||
@ -429,6 +406,16 @@ COUNT remove_lfn_entries(f_node_ptr fnp)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
STATIC unsigned get_f_nodes_cnt(void)
|
||||
{
|
||||
sfttbl FAR *sp;
|
||||
|
||||
unsigned f_nodes_cnt = 0;
|
||||
for (sp = sfthead; sp != (sfttbl FAR *) - 1; sp = sp->sftt_next)
|
||||
f_nodes_cnt += sp->sftt_count;
|
||||
return f_nodes_cnt;
|
||||
}
|
||||
|
||||
/* /// Added - Ron Cemer */
|
||||
/* If more than one f_node has a file open, and a write
|
||||
occurs, this function must be called to propagate the
|
||||
@ -442,15 +429,17 @@ STATIC void merge_file_changes(f_node_ptr fnp, int collect)
|
||||
{
|
||||
f_node_ptr fnp2;
|
||||
int i, fd;
|
||||
unsigned f_nodes_cnt;
|
||||
|
||||
if (!IsShareInstalled(FALSE))
|
||||
return;
|
||||
|
||||
fd = xlt_fnp(fnp);
|
||||
fnp2 = &fnode[1];
|
||||
f_nodes_cnt = get_f_nodes_cnt();
|
||||
for (i = 0; i < f_nodes_cnt; i++)
|
||||
{
|
||||
fmemcpy(fnp2, &f_nodes[i], sizeof(*fnp2));
|
||||
sft_to_fnode(fnp2, i);
|
||||
if ((fnp != (f_node_ptr) 0)
|
||||
&& (i != fd)
|
||||
&& (fnp->f_count > 0) && (is_same_file(fnp, fnp2)))
|
||||
@ -471,7 +460,7 @@ STATIC void merge_file_changes(f_node_ptr fnp, int collect)
|
||||
distributing these changes to the other f_nodes
|
||||
which refer to this file. */
|
||||
copy_file_changes(fnp, fnp2);
|
||||
fmemcpy(&f_nodes[i], fnp2, sizeof(*fnp2));
|
||||
fnode_to_sft(fnp2, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1891,33 +1880,15 @@ int dos_cd(char * PathName)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Try to allocate an f_node from the available files array */
|
||||
|
||||
/* Compat functions for SFT transition */
|
||||
f_node_ptr get_f_node(f_node_ptr fnp)
|
||||
{
|
||||
REG int i;
|
||||
|
||||
for (i = 0; i < f_nodes_cnt; i++)
|
||||
{
|
||||
if (f_nodes[i].f_count == 0)
|
||||
{
|
||||
++f_nodes[i].f_count;
|
||||
fnp->f_count = 1;
|
||||
fnode_fd[fnp - fnode] = i;
|
||||
return fnp;
|
||||
}
|
||||
}
|
||||
return (f_node_ptr) 0;
|
||||
fnp->f_count = 1;
|
||||
return fnp;
|
||||
}
|
||||
|
||||
VOID release_f_node(f_node_ptr fnp)
|
||||
{
|
||||
struct f_node FAR *fp = &f_nodes[xlt_fnp(fnp)];
|
||||
|
||||
if (fp->f_count > 0)
|
||||
--fp->f_count;
|
||||
else
|
||||
fp->f_count = 0;
|
||||
}
|
||||
|
||||
#ifndef IPL
|
||||
@ -2172,15 +2143,43 @@ COUNT xlt_fnp(f_node_ptr fnp)
|
||||
return fnode_fd[fnp - fnode];
|
||||
}
|
||||
|
||||
/* copy the far fnode fd into the first near fnode */
|
||||
STATIC void sft_to_fnode(f_node_ptr fnp, int fd)
|
||||
{
|
||||
sft FAR *sftp = idx_to_sft(fd);
|
||||
UWORD flags;
|
||||
|
||||
fnp->f_count = sftp->sft_count;
|
||||
flags = sftp->sft_flags;
|
||||
fnp->f_flags = (flags & SFT_FDATE) | ((flags & SFT_FDIRTY) ^ SFT_FDIRTY);
|
||||
fnp->f_dir.dir_attrib = sftp->sft_attrib;
|
||||
fmemcpy(fnp->f_dir.dir_name, sftp->sft_name, FNAME_SIZE + FEXT_SIZE);
|
||||
fnp->f_dir.dir_time = sftp->sft_time;
|
||||
fnp->f_dir.dir_date = sftp->sft_date;
|
||||
fnp->f_dir.dir_size = sftp->sft_size;
|
||||
setdstart(fnp->f_dpb, &fnp->f_dir, sftp->sft_stclust);
|
||||
|
||||
fnp->f_diridx = sftp->sft_diridx;
|
||||
fnp->f_dirsector = sftp->sft_dirsector;
|
||||
fnp->f_dpb = sftp->sft_dcb;
|
||||
fnp->f_offset = sftp->sft_posit;
|
||||
fnp->f_cluster = sftp->sft_cuclust;
|
||||
#ifdef WITHFAT32
|
||||
fnp->f_cluster_offset = sftp->sft_relclust |
|
||||
((ULONG)sftp->sft_relclust_high << 16);
|
||||
#else
|
||||
fnp->f_cluster_offset = sftp->sft_relclust;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* copy the SFT fd into the first near fnode */
|
||||
f_node_ptr xlt_fd(int fd)
|
||||
{
|
||||
/* If the fd was invalid because it was out of range or the */
|
||||
/* requested file was not open, tell the caller and exit */
|
||||
/* note: an invalid fd is indicated by a 0 return */
|
||||
if (fd < f_nodes_cnt)
|
||||
if (fd < get_f_nodes_cnt())
|
||||
{
|
||||
fmemcpy(&fnode[0], &f_nodes[fd], sizeof(fnode[0]));
|
||||
sft_to_fnode(&fnode[0], fd);
|
||||
if (fnode[0].f_count > 0)
|
||||
{
|
||||
fnode_fd[0] = fd;
|
||||
@ -2190,10 +2189,35 @@ f_node_ptr xlt_fd(int fd)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* copy a near fnode to the corresponding far one */
|
||||
STATIC void fnode_to_sft(f_node_ptr fnp, int fd)
|
||||
{
|
||||
sft FAR *sftp = idx_to_sft(fd);
|
||||
|
||||
sftp->sft_flags = (sftp->sft_flags & ~(SFT_FDATE | SFT_FDIRTY)) |
|
||||
((fnp->f_flags & (SFT_FDATE | SFT_FDIRTY)) ^ SFT_FDIRTY);
|
||||
|
||||
sftp->sft_attrib = fnp->f_dir.dir_attrib;
|
||||
fmemcpy(sftp->sft_name, fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE);
|
||||
sftp->sft_time = fnp->f_dir.dir_time;
|
||||
sftp->sft_date = fnp->f_dir.dir_date;
|
||||
sftp->sft_size = fnp->f_dir.dir_size;
|
||||
sftp->sft_stclust = getdstart(fnp->f_dpb, &fnp->f_dir);
|
||||
|
||||
sftp->sft_diridx = fnp->f_diridx;
|
||||
sftp->sft_dirsector = fnp->f_dirsector;
|
||||
sftp->sft_dcb = fnp->f_dpb;
|
||||
/* Do not update sftp->sft_posit (fnp->f_offset): dosfns.c takes care of it */
|
||||
sftp->sft_cuclust = fnp->f_cluster;
|
||||
sftp->sft_relclust = (UWORD)fnp->f_cluster_offset;
|
||||
#ifdef WITHFAT32
|
||||
sftp->sft_relclust_high = (UWORD)(fnp->f_cluster_offset >> 16);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* copy a near fnode to the corresponding SFT */
|
||||
STATIC void save_far_f_node(f_node_ptr fnp)
|
||||
{
|
||||
fmemcpy(&f_nodes[xlt_fnp(fnp)], fnp, sizeof(*fnp));
|
||||
fnode_to_sft(fnp, xlt_fnp(fnp));
|
||||
}
|
||||
|
||||
/* TE
|
||||
|
@ -351,9 +351,6 @@ GLOBAL WORD dump_regs; /* dump registers of bad call */
|
||||
|
||||
#endif
|
||||
|
||||
extern struct f_node FAR * ASM f_nodes; /* pointer to the array */
|
||||
extern UWORD ASM f_nodes_cnt; /* number of allocated f_nodes */
|
||||
|
||||
/* */
|
||||
/* Function prototypes - automatically generated */
|
||||
/* */
|
||||
|
@ -379,10 +379,6 @@ _os_major db 5
|
||||
_rev_number db 0
|
||||
global _version_flags
|
||||
_version_flags db 0
|
||||
global _f_nodes
|
||||
_f_nodes dd 0
|
||||
global _f_nodes_cnt
|
||||
_f_nodes_cnt dw 0
|
||||
global os_release
|
||||
extern _os_release
|
||||
os_release dw _os_release
|
||||
|
@ -151,12 +151,11 @@ int FileName83Length(BYTE * filename83);
|
||||
/* fatfs.c */
|
||||
struct dpb FAR *get_dpb(COUNT dsk);
|
||||
ULONG clus2phys(CLUSTER cl_no, struct dpb FAR * dpbp);
|
||||
long dos_open(char * path, unsigned flag, unsigned attrib);
|
||||
long dos_open(char * path, unsigned flag, unsigned attrib, int fd);
|
||||
BOOL fcbmatch(const char *fcbname1, const char *fcbname2);
|
||||
BOOL fcmp_wild(const char * s1, const char * s2, unsigned n);
|
||||
VOID touc(BYTE * s, COUNT n);
|
||||
COUNT dos_close(COUNT fd);
|
||||
COUNT dos_commit(COUNT fd);
|
||||
COUNT dos_delete(BYTE * path, int attrib);
|
||||
COUNT dos_rmdir(BYTE * path);
|
||||
COUNT dos_rename(BYTE * path1, BYTE * path2, int attrib);
|
||||
|
Loading…
Reference in New Issue
Block a user