mirror of
https://github.com/FDOS/kernel.git
synced 2025-07-26 23:34:18 +02:00
Eliminate xlt_fd(), save_far_f_node(), and the redundant fnode f_mode field.
git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1404 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
parent
4a81e6e9a2
commit
76f1c10a4e
@ -36,8 +36,6 @@ static BYTE *fnode_hRcsId =
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct f_node {
|
struct f_node {
|
||||||
COUNT f_mode; /* read, write, read-write, etc */
|
|
||||||
|
|
||||||
UWORD f_flags; /* file flags */
|
UWORD f_flags; /* file flags */
|
||||||
|
|
||||||
struct dirent f_dir; /* this file's dir entry image */
|
struct dirent f_dir; /* this file's dir entry image */
|
||||||
|
@ -61,9 +61,6 @@ f_node_ptr dir_open(register const char *dirname, f_node_ptr fnp)
|
|||||||
int i;
|
int i;
|
||||||
char fcbname[FNAME_SIZE + FEXT_SIZE];
|
char fcbname[FNAME_SIZE + FEXT_SIZE];
|
||||||
|
|
||||||
/* Force the fnode into read-write mode */
|
|
||||||
fnp->f_mode = RDWR;
|
|
||||||
|
|
||||||
/* determine what drive and dpb we are using... */
|
/* determine what drive and dpb we are using... */
|
||||||
fnp->f_dpb = get_dpb(dirname[0]-'A');
|
fnp->f_dpb = get_dpb(dirname[0]-'A');
|
||||||
/* Perform all directory common handling after all special */
|
/* Perform all directory common handling after all special */
|
||||||
@ -411,9 +408,6 @@ COUNT dos_findnext(void)
|
|||||||
fnp = &fnode[0];
|
fnp = &fnode[0];
|
||||||
memset(fnp, 0, sizeof(*fnp));
|
memset(fnp, 0, sizeof(*fnp));
|
||||||
|
|
||||||
/* Force the fnode into read-write mode */
|
|
||||||
fnp->f_mode = RDWR;
|
|
||||||
|
|
||||||
/* Select the default to help non-drive specified path */
|
/* Select the default to help non-drive specified path */
|
||||||
/* searches... */
|
/* searches... */
|
||||||
fnp->f_dpb = get_dpb(dmp->dm_drive);
|
fnp->f_dpb = get_dpb(dmp->dm_drive);
|
||||||
|
@ -37,10 +37,8 @@ BYTE *RcsId = "$Id$";
|
|||||||
/* */
|
/* */
|
||||||
/* function prototypes */
|
/* function prototypes */
|
||||||
/* */
|
/* */
|
||||||
STATIC int sft_to_fnode(f_node_ptr fnp, int fd);
|
STATIC f_node_ptr sft_to_fnode(int fd);
|
||||||
f_node_ptr xlt_fd(COUNT);
|
STATIC void fnode_to_sft(f_node_ptr fnp);
|
||||||
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 f_node_ptr split_path(char *, char *, f_node_ptr fnp);
|
||||||
STATIC BOOL find_fname(f_node_ptr, char *, int);
|
STATIC BOOL find_fname(f_node_ptr, char *, int);
|
||||||
/* /// Added - Ron Cemer */
|
/* /// Added - Ron Cemer */
|
||||||
@ -148,7 +146,7 @@ int dos_open(char *path, unsigned flags, unsigned attrib, int fd)
|
|||||||
|
|
||||||
/* next split the passed dir into comopnents (i.e. - path to */
|
/* next split the passed dir into comopnents (i.e. - path to */
|
||||||
/* new directory and name of new directory. */
|
/* new directory and name of new directory. */
|
||||||
if ((fnp = split_path(path, fcbname, xlt_fd(fd))) == NULL)
|
if ((fnp = split_path(path, fcbname, sft_to_fnode(fd))) == NULL)
|
||||||
return DE_PATHNOTFND;
|
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 */
|
||||||
@ -208,10 +206,6 @@ int dos_open(char *path, unsigned flags, unsigned attrib, int fd)
|
|||||||
return DE_FILENOTFND;
|
return DE_FILENOTFND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the fnode to the desired mode */
|
|
||||||
/* Updating the directory entry first. */
|
|
||||||
fnp->f_mode = flags & O_ACCMODE;
|
|
||||||
|
|
||||||
if (status != S_OPENED)
|
if (status != S_OPENED)
|
||||||
{
|
{
|
||||||
init_direntry(&fnp->f_dir, attrib, FREE, fcbname);
|
init_direntry(&fnp->f_dir, attrib, FREE, fcbname);
|
||||||
@ -239,7 +233,7 @@ int dos_open(char *path, unsigned flags, unsigned attrib, int fd)
|
|||||||
fnp->f_cluster = getdstart(fnp->f_dpb, &fnp->f_dir);
|
fnp->f_cluster = getdstart(fnp->f_dpb, &fnp->f_dir);
|
||||||
fnp->f_cluster_offset = 0;
|
fnp->f_cluster_offset = 0;
|
||||||
|
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,10 +247,8 @@ BOOL fcmp_wild(const char * s1, const char * s2, unsigned n)
|
|||||||
|
|
||||||
COUNT dos_close(COUNT fd)
|
COUNT dos_close(COUNT fd)
|
||||||
{
|
{
|
||||||
f_node_ptr fnp;
|
|
||||||
|
|
||||||
/* Translate the fd into a useful pointer */
|
/* Translate the fd into a useful pointer */
|
||||||
fnp = xlt_fd(fd);
|
f_node_ptr fnp = sft_to_fnode(fd);
|
||||||
|
|
||||||
if (fnp->f_flags & F_DMOD)
|
if (fnp->f_flags & F_DMOD)
|
||||||
{
|
{
|
||||||
@ -826,11 +818,9 @@ time dos_gettime(void)
|
|||||||
/* */
|
/* */
|
||||||
COUNT dos_setftime(COUNT fd, date dp, time tp)
|
COUNT dos_setftime(COUNT fd, date dp, time tp)
|
||||||
{
|
{
|
||||||
f_node_ptr fnp;
|
|
||||||
|
|
||||||
/* Translate the fd into an fnode pointer, since all internal */
|
/* Translate the fd into an fnode pointer, since all internal */
|
||||||
/* operations are achieved through fnodes. */
|
/* operations are achieved through fnodes. */
|
||||||
fnp = xlt_fd(fd);
|
f_node_ptr fnp = sft_to_fnode(fd);
|
||||||
|
|
||||||
/* Set the date and time from the fnode and return */
|
/* Set the date and time from the fnode and return */
|
||||||
fnp->f_dir.dir_date = dp;
|
fnp->f_dir.dir_date = dp;
|
||||||
@ -838,7 +828,7 @@ COUNT dos_setftime(COUNT fd, date dp, time tp)
|
|||||||
/* mark file as modified and set this date upon closing */
|
/* mark file as modified and set this date upon closing */
|
||||||
fnp->f_flags |= F_DMOD | F_DDATE;
|
fnp->f_flags |= F_DMOD | F_DDATE;
|
||||||
|
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -847,17 +837,15 @@ COUNT dos_setftime(COUNT fd, date dp, time tp)
|
|||||||
/* */
|
/* */
|
||||||
BOOL dos_setfsize(COUNT fd, LONG size)
|
BOOL dos_setfsize(COUNT fd, LONG size)
|
||||||
{
|
{
|
||||||
f_node_ptr fnp;
|
|
||||||
|
|
||||||
/* Translate the fd into an fnode pointer, since all internal */
|
/* Translate the fd into an fnode pointer, since all internal */
|
||||||
/* operations are achieved through fnodes. */
|
/* operations are achieved through fnodes. */
|
||||||
fnp = xlt_fd(fd);
|
f_node_ptr fnp = sft_to_fnode(fd);
|
||||||
|
|
||||||
/* Change the file size */
|
/* Change the file size */
|
||||||
fnp->f_dir.dir_size = size;
|
fnp->f_dir.dir_size = size;
|
||||||
|
|
||||||
merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */
|
merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -992,9 +980,6 @@ COUNT dos_mkdir(BYTE * dir)
|
|||||||
return DE_HNDLDSKFULL;
|
return DE_HNDLDSKFULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the fnode to the desired mode */
|
|
||||||
fnp->f_mode = WRONLY;
|
|
||||||
|
|
||||||
init_direntry(&fnp->f_dir, D_DIR, free_fat, fcbname);
|
init_direntry(&fnp->f_dir, D_DIR, free_fat, fcbname);
|
||||||
|
|
||||||
fnp->f_flags = F_DMOD | F_DDIR;
|
fnp->f_flags = F_DMOD | F_DDIR;
|
||||||
@ -1414,7 +1399,9 @@ STATIC COUNT dos_extend(f_node_ptr fnp)
|
|||||||
dosfns.c */
|
dosfns.c */
|
||||||
long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
||||||
{
|
{
|
||||||
REG f_node_ptr fnp;
|
/* Translate the fd into an fnode pointer, since all internal */
|
||||||
|
/* operations are achieved through fnodes. */
|
||||||
|
REG f_node_ptr fnp = sft_to_fnode(fd);
|
||||||
REG struct buffer FAR *bp;
|
REG struct buffer FAR *bp;
|
||||||
UCOUNT xfr_cnt = 0;
|
UCOUNT xfr_cnt = 0;
|
||||||
UCOUNT ret_cnt = 0;
|
UCOUNT ret_cnt = 0;
|
||||||
@ -1429,9 +1416,6 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
fd, FP_SEG(buffer), FP_OFF(buffer), count);
|
fd, FP_SEG(buffer), FP_OFF(buffer), count);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Translate the fd into an fnode pointer, since all internal */
|
|
||||||
/* operations are achieved through fnodes. */
|
|
||||||
fnp = xlt_fd(fd);
|
|
||||||
|
|
||||||
if (mode==XFR_WRITE)
|
if (mode==XFR_WRITE)
|
||||||
{
|
{
|
||||||
@ -1441,7 +1425,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
|
|
||||||
if (dos_extend(fnp) != SUCCESS)
|
if (dos_extend(fnp) != SUCCESS)
|
||||||
{
|
{
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1467,7 +1451,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
shrink_file(fnp); /* this is the only call to shrink_file... */
|
shrink_file(fnp); /* this is the only call to shrink_file... */
|
||||||
/* why does empty write -always- truncate to current offset? */
|
/* why does empty write -always- truncate to current offset? */
|
||||||
}
|
}
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1487,7 +1471,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
/* but only for regular files. */
|
/* but only for regular files. */
|
||||||
if (mode == XFR_READ && !(fnp->f_flags & F_DDIR) && (fnp->f_offset >= fnp->f_dir.dir_size))
|
if (mode == XFR_READ && !(fnp->f_flags & F_DDIR) && (fnp->f_offset >= fnp->f_dir.dir_size))
|
||||||
{
|
{
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return ret_cnt;
|
return ret_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1518,7 +1502,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
#endif
|
#endif
|
||||||
if (map_cluster(fnp, mode) != SUCCESS)
|
if (map_cluster(fnp, mode) != SUCCESS)
|
||||||
{
|
{
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return ret_cnt;
|
return ret_cnt;
|
||||||
}
|
}
|
||||||
if (mode == XFR_WRITE)
|
if (mode == XFR_WRITE)
|
||||||
@ -1590,7 +1574,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
mode == XFR_READ ? DSKREAD : DSKWRITE))
|
mode == XFR_READ ? DSKREAD : DSKWRITE))
|
||||||
{
|
{
|
||||||
fnp->f_offset = startoffset;
|
fnp->f_offset = startoffset;
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return DE_ACCESS;
|
return DE_ACCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1615,7 +1599,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
#endif
|
#endif
|
||||||
if (bp == NULL) /* (struct buffer *)0 --> DS:0 !! */
|
if (bp == NULL) /* (struct buffer *)0 --> DS:0 !! */
|
||||||
{
|
{
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return ret_cnt;
|
return ret_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1668,7 +1652,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */
|
merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return ret_cnt;
|
return ret_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1676,11 +1660,8 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
|
|||||||
/* Returns a long current offset or a negative error code */
|
/* Returns a long current offset or a negative error code */
|
||||||
LONG dos_lseek(COUNT fd, LONG foffset, COUNT origin)
|
LONG dos_lseek(COUNT fd, LONG foffset, COUNT origin)
|
||||||
{
|
{
|
||||||
REG f_node_ptr fnp;
|
|
||||||
|
|
||||||
/* Translate the fd into a useful pointer */
|
/* Translate the fd into a useful pointer */
|
||||||
|
REG f_node_ptr fnp = sft_to_fnode(fd);
|
||||||
fnp = xlt_fd(fd);
|
|
||||||
|
|
||||||
/* now do the actual lseek adjustment to the file poitner */
|
/* now do the actual lseek adjustment to the file poitner */
|
||||||
switch (origin)
|
switch (origin)
|
||||||
@ -1704,7 +1685,7 @@ LONG dos_lseek(COUNT fd, LONG foffset, COUNT origin)
|
|||||||
default:
|
default:
|
||||||
return (LONG) DE_INVLDFUNC;
|
return (LONG) DE_INVLDFUNC;
|
||||||
}
|
}
|
||||||
save_far_f_node(fnp);
|
fnode_to_sft(fnp);
|
||||||
return fnp->f_offset;
|
return fnp->f_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2017,19 +1998,17 @@ COUNT media_check(REG struct dpb FAR * dpbp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int sft_to_fnode(f_node_ptr fnp, int fd)
|
/* copy the SFT fd into the first near fnode */
|
||||||
|
STATIC f_node_ptr sft_to_fnode(int fd)
|
||||||
{
|
{
|
||||||
sft FAR *sftp = idx_to_sft(fd);
|
sft FAR *sftp = idx_to_sft(fd);
|
||||||
|
f_node_ptr fnp = &fnode[0];
|
||||||
UWORD flags;
|
UWORD flags;
|
||||||
|
|
||||||
if (FP_OFF(sftp) == (size_t) - 1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
fnp->f_sft_idx = fd;
|
fnp->f_sft_idx = fd;
|
||||||
|
|
||||||
flags = sftp->sft_flags;
|
flags = sftp->sft_flags;
|
||||||
fnp->f_flags = (flags & SFT_FDATE) | ((flags & SFT_FDIRTY) ^ SFT_FDIRTY);
|
fnp->f_flags = (flags & SFT_FDATE) | ((flags & SFT_FDIRTY) ^ SFT_FDIRTY);
|
||||||
fnp->f_mode = sftp->sft_mode & O_ACCMODE;
|
|
||||||
|
|
||||||
fnp->f_dir.dir_attrib = sftp->sft_attrib;
|
fnp->f_dir.dir_attrib = sftp->sft_attrib;
|
||||||
fmemcpy(fnp->f_dir.dir_name, sftp->sft_name, FNAME_SIZE + FEXT_SIZE);
|
fmemcpy(fnp->f_dir.dir_name, sftp->sft_name, FNAME_SIZE + FEXT_SIZE);
|
||||||
@ -2049,23 +2028,12 @@ STATIC int sft_to_fnode(f_node_ptr fnp, int fd)
|
|||||||
#else
|
#else
|
||||||
fnp->f_cluster_offset = sftp->sft_relclust;
|
fnp->f_cluster_offset = sftp->sft_relclust;
|
||||||
#endif
|
#endif
|
||||||
return SUCCESS;
|
return fnp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy the SFT fd into the first near fnode */
|
STATIC void fnode_to_sft(f_node_ptr fnp)
|
||||||
f_node_ptr xlt_fd(int fd)
|
|
||||||
{
|
{
|
||||||
/* If the fd was invalid because it was out of range or the */
|
sft FAR *sftp = idx_to_sft(fnp->f_sft_idx);
|
||||||
/* requested file was not open, tell the caller and exit */
|
|
||||||
/* note: an invalid fd is indicated by a 0 return */
|
|
||||||
if (sft_to_fnode(&fnode[0], fd) == SUCCESS)
|
|
||||||
return &fnode[0];
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) |
|
sftp->sft_flags = (sftp->sft_flags & ~(SFT_FDATE | SFT_FDIRTY)) |
|
||||||
((fnp->f_flags & (SFT_FDATE | SFT_FDIRTY)) ^ SFT_FDIRTY);
|
((fnp->f_flags & (SFT_FDATE | SFT_FDIRTY)) ^ SFT_FDIRTY);
|
||||||
@ -2088,12 +2056,6 @@ STATIC void fnode_to_sft(f_node_ptr fnp, int fd)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy a near fnode to the corresponding SFT */
|
|
||||||
STATIC void save_far_f_node(f_node_ptr fnp)
|
|
||||||
{
|
|
||||||
fnode_to_sft(fnp, fnp->f_sft_idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TE
|
/* TE
|
||||||
if the current filesize in FAT is larger then the dir_size
|
if the current filesize in FAT is larger then the dir_size
|
||||||
it's truncated here.
|
it's truncated here.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user