Avoid bitfields for fnodes, using flags instead.

Replaced droot field by checks for f_dirstart == 0.


git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@867 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Bart Oldeman 2004-04-13 10:46:37 +00:00
parent 5c72b4a0e9
commit 5d712fc2a6
3 changed files with 53 additions and 80 deletions

View File

@ -39,13 +39,7 @@ struct f_node {
UWORD f_count; /* number of uses of this file */ UWORD f_count; /* number of uses of this file */
COUNT f_mode; /* read, write, read-write, etc */ COUNT f_mode; /* read, write, read-write, etc */
struct { UWORD f_flags; /* file flags */
BITS f_dmod:1; /* directory has been modified */
BITS f_droot:1; /* directory is the root */
BITS f_dnew:1; /* fnode is new and needs fill */
BITS f_ddir:1; /* fnode is assigned to dir */
BITS f_ddate:1; /* date set using setdate */
} f_flags; /* file flags */
struct dirent f_dir; /* this file's dir entry image */ struct dirent f_dir; /* this file's dir entry image */
@ -59,6 +53,11 @@ struct f_node {
CLUSTER f_cluster; /* the cluster we are at */ CLUSTER f_cluster; /* the cluster we are at */
}; };
#define F_DMOD 1 /* directory has been modified */
#define F_DNEW 2 /* fnode is new and needs fill */
#define F_DDIR 4 /* fnode is assigned to dir */
#define F_DDATE 8 /* date set using setdate */
typedef struct f_node *f_node_ptr; typedef struct f_node *f_node_ptr;
struct lfn_inode { struct lfn_inode {
@ -66,7 +65,7 @@ struct lfn_inode {
/* If the string is empty, */ /* If the string is empty, */
/* then file has the 8.3 name */ /* then file has the 8.3 name */
struct dirent l_dir; /* Directory entry image */ struct dirent l_dir; /* Directory entry image */
ULONG l_diroff; /* Current directory entry offset */ UWORD l_diroff; /* Current directory entry offset */
}; };
typedef struct lfn_inode FAR * lfn_inode_ptr; typedef struct lfn_inode FAR * lfn_inode_ptr;

View File

@ -42,31 +42,18 @@ static BYTE *fatdirRcsId =
VOID dir_init_fnode(f_node_ptr fnp, CLUSTER dirstart) VOID dir_init_fnode(f_node_ptr fnp, CLUSTER dirstart)
{ {
/* reset the directory flags */ /* reset the directory flags */
fnp->f_flags.f_dmod = FALSE; fnp->f_flags = F_DDIR | F_DNEW;
fnp->f_flags.f_droot = FALSE;
fnp->f_flags.f_ddir = TRUE;
fnp->f_flags.f_dnew = TRUE;
fnp->f_diroff = 0; fnp->f_diroff = 0;
fnp->f_offset = 0l; fnp->f_offset = 0l;
fnp->f_cluster_offset = 0; fnp->f_cluster_offset = 0;
/* root directory */ /* root directory */
if (dirstart == 0)
{
#ifdef WITHFAT32 #ifdef WITHFAT32
if (dirstart == 0)
if (ISFAT32(fnp->f_dpb)) if (ISFAT32(fnp->f_dpb))
{ dirstart = fnp->f_dpb->dpb_xrootclst;
fnp->f_cluster = fnp->f_dirstart = fnp->f_dpb->dpb_xrootclst;
}
else
#endif #endif
{ fnp->f_cluster = fnp->f_dirstart = dirstart;
fnp->f_dirstart = 0;
fnp->f_flags.f_droot = TRUE;
}
}
else /* non-root */
fnp->f_cluster = fnp->f_dirstart = dirstart;
} }
f_node_ptr dir_open(register const char *dirname) f_node_ptr dir_open(register const char *dirname)
@ -216,7 +203,7 @@ COUNT dir_read(REG f_node_ptr fnp)
/* can't have more than 65535 directory entries /* can't have more than 65535 directory entries
remove lfn entries may call us with new_diroff == -1 remove lfn entries may call us with new_diroff == -1
for root directories though */ for root directories though */
if (!fnp->f_flags.f_droot && new_diroff >= 65535U) if (fnp->f_dirstart != 0 && new_diroff >= 65535U)
return DE_SEEK; return DE_SEEK;
/* Directories need to point to their current offset, not for */ /* Directories need to point to their current offset, not for */
@ -224,7 +211,7 @@ COUNT dir_read(REG f_node_ptr fnp)
/* directory entry, we will update the offset on entry rather */ /* directory entry, we will update the offset on entry rather */
/* than wait until exit. If it was new, clear the special new */ /* than wait until exit. If it was new, clear the special new */
/* flag. */ /* flag. */
if (!fnp->f_flags.f_dnew) if (!(fnp->f_flags & F_DNEW))
new_diroff++; new_diroff++;
/* Determine if we hit the end of the directory. If we have, */ /* Determine if we hit the end of the directory. If we have, */
@ -232,7 +219,7 @@ COUNT dir_read(REG f_node_ptr fnp)
/* dirent portion of the fnode, clear the f_dmod bit and leave, */ /* dirent portion of the fnode, clear the f_dmod bit and leave, */
/* but only for root directories */ /* but only for root directories */
if (fnp->f_flags.f_droot) if (fnp->f_dirstart == 0)
{ {
if (new_diroff >= fnp->f_dpb->dpb_dirents) if (new_diroff >= fnp->f_dpb->dpb_dirents)
return DE_SEEK; return DE_SEEK;
@ -277,8 +264,7 @@ COUNT dir_read(REG f_node_ptr fnp)
swap_deleted(fnp->f_dir.dir_name); swap_deleted(fnp->f_dir.dir_name);
/* Update the fnode's directory info */ /* Update the fnode's directory info */
fnp->f_flags.f_dmod = FALSE; fnp->f_flags &= ~(F_DMOD | F_DNEW);
fnp->f_flags.f_dnew = FALSE;
fnp->f_diroff = new_diroff; fnp->f_diroff = new_diroff;
/* and for efficiency, stop when we hit the first */ /* and for efficiency, stop when we hit the first */
@ -291,8 +277,8 @@ COUNT dir_read(REG f_node_ptr fnp)
* Writes directory entry pointed by fnp to disk. In case of erroneous * Writes directory entry pointed by fnp to disk. In case of erroneous
* situation fnode is released. * situation fnode is released.
* The caller should set * The caller should set
* 1. f_dmod flag if original directory entry was modified. * 1. F_DMOD flag if original directory entry was modified.
* 2. f_dmod & f_dnew flags if new directory entry is created. In this * 2. F_DMOD & F_DNEW flags if new directory entry is created. In this
* case the reserved fields is cleared, but only if new dentry isn't * case the reserved fields is cleared, but only if new dentry isn't
* a LFN entry (has D_LFN attribute). * a LFN entry (has D_LFN attribute).
* Return value. * Return value.
@ -305,15 +291,15 @@ BOOL dir_write(REG f_node_ptr fnp)
struct buffer FAR *bp; struct buffer FAR *bp;
REG UWORD secsize = fnp->f_dpb->dpb_secsize; REG UWORD secsize = fnp->f_dpb->dpb_secsize;
if (!fnp->f_flags.f_ddir) if (!(fnp->f_flags & F_DDIR))
return FALSE; return FALSE;
/* Update the entry if it was modified by a write or create... */ /* Update the entry if it was modified by a write or create... */
if (fnp->f_flags.f_dmod) if (fnp->f_flags & F_DMOD)
{ {
/* Root is a consecutive set of blocks, so handling is */ /* Root is a consecutive set of blocks, so handling is */
/* simple. */ /* simple. */
if (fnp->f_flags.f_droot) if (fnp->f_dirstart == 0)
{ {
bp = getblock(fnp->f_diroff / (secsize / DIRENT_SIZE) bp = getblock(fnp->f_diroff / (secsize / DIRENT_SIZE)
+ fnp->f_dpb->dpb_dirstrt, + fnp->f_dpb->dpb_dirstrt,
@ -362,7 +348,7 @@ BOOL dir_write(REG f_node_ptr fnp)
return FALSE; return FALSE;
} }
if (fnp->f_flags.f_dnew && fnp->f_dir.dir_attrib != D_LFN) if ((fnp->f_flags & F_DNEW) && fnp->f_dir.dir_attrib != D_LFN)
fmemset(&fnp->f_dir.dir_case, 0, 8); fmemset(&fnp->f_dir.dir_case, 0, 8);
swap_deleted(fnp->f_dir.dir_name); swap_deleted(fnp->f_dir.dir_name);
@ -382,7 +368,7 @@ BOOL dir_write(REG f_node_ptr fnp)
VOID dir_close(REG f_node_ptr fnp) VOID dir_close(REG f_node_ptr fnp)
{ {
/* Test for invalid f_nodes */ /* Test for invalid f_nodes */
if (fnp == NULL || !fnp->f_flags.f_ddir) if (fnp == NULL || !(fnp->f_flags & F_DDIR))
return; return;
#ifndef IPL #ifndef IPL
@ -479,10 +465,7 @@ COUNT dos_findfirst(UCOUNT attr, BYTE * name)
else else
{ {
dmp->dm_entry = 0; dmp->dm_entry = 0;
if (!fnp->f_flags.f_droot) dmp->dm_dircluster = fnp->f_dirstart;
dmp->dm_dircluster = fnp->f_dirstart;
else
dmp->dm_dircluster = 0;
dir_close(fnp); dir_close(fnp);
return dos_findnext(); return dos_findnext();
} }
@ -526,11 +509,11 @@ COUNT dos_findnext(void)
/* Search through the directory to find the entry, but do a */ /* Search through the directory to find the entry, but do a */
/* seek first. */ /* seek first. */
fnp->f_flags.f_dnew = TRUE; fnp->f_flags |= F_DNEW;
if (dmp->dm_entry > 0) if (dmp->dm_entry > 0)
{ {
fnp->f_diroff = dmp->dm_entry - 1; fnp->f_diroff = dmp->dm_entry - 1;
fnp->f_flags.f_dnew = FALSE; fnp->f_flags &= ~F_DNEW;
} }
/* Loop through the directory */ /* Loop through the directory */

View File

@ -225,10 +225,7 @@ long dos_open(char *path, unsigned flags, unsigned attrib)
if (status != S_OPENED) if (status != S_OPENED)
{ {
init_direntry(&fnp->f_dir, attrib, FREE); init_direntry(&fnp->f_dir, attrib, FREE);
fnp->f_flags.f_dmod = TRUE; fnp->f_flags = F_DMOD | F_DDIR;
fnp->f_flags.f_ddate = FALSE;
fnp->f_flags.f_dnew = FALSE;
fnp->f_flags.f_ddir = TRUE;
if (!dir_write(fnp)) if (!dir_write(fnp))
{ {
release_f_node(fnp); release_f_node(fnp);
@ -245,12 +242,11 @@ long dos_open(char *path, unsigned flags, unsigned attrib)
setdstart(fnp->f_dpb, &fnp->f_dir, FREE); setdstart(fnp->f_dpb, &fnp->f_dir, FREE);
fnp->f_cluster_offset = 0; fnp->f_cluster_offset = 0;
} }
fnp->f_flags.f_dmod = (status != S_OPENED); fnp->f_flags = 0;
fnp->f_flags.f_ddate = FALSE; if (status != S_OPENED)
fnp->f_flags.f_dnew = FALSE; fnp->f_flags = F_DMOD;
fnp->f_flags.f_ddir = FALSE;
merge_file_changes(fnp, status == S_OPENED); /* /// Added - Ron Cemer */ merge_file_changes(fnp, status == S_OPENED); /* /// Added - Ron Cemer */
/* /// Moved from above. - Ron Cemer */ /* /// Moved from above. - Ron Cemer */
fnp->f_cluster = getdstart(fnp->f_dpb, &fnp->f_dir); fnp->f_cluster = getdstart(fnp->f_dpb, &fnp->f_dir);
@ -288,9 +284,9 @@ COUNT dos_close(COUNT fd)
if (fnp == (f_node_ptr) 0) if (fnp == (f_node_ptr) 0)
return DE_INVLDHNDL; return DE_INVLDHNDL;
if (fnp->f_flags.f_dmod) if (fnp->f_flags & F_DMOD)
{ {
if (fnp->f_flags.f_ddate == FALSE) if (!(fnp->f_flags & F_DDATE))
{ {
fnp->f_dir.dir_time = dos_gettime(); fnp->f_dir.dir_time = dos_gettime();
fnp->f_dir.dir_date = dos_getdate(); fnp->f_dir.dir_date = dos_getdate();
@ -298,7 +294,7 @@ COUNT dos_close(COUNT fd)
merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */
} }
fnp->f_flags.f_ddir = TRUE; fnp->f_flags |= F_DDIR;
dir_close(fnp); dir_close(fnp);
return SUCCESS; return SUCCESS;
@ -443,7 +439,7 @@ COUNT remove_lfn_entries(f_node_ptr fnp)
if (fnp->f_dir.dir_attrib != D_LFN) if (fnp->f_dir.dir_attrib != D_LFN)
break; break;
fnp->f_dir.dir_name[0] = DELETED; fnp->f_dir.dir_name[0] = DELETED;
fnp->f_flags.f_dmod = TRUE; fnp->f_flags |= F_DMOD;
if (!dir_write(fnp)) return DE_BLKINVLD; if (!dir_write(fnp)) return DE_BLKINVLD;
} }
fnp->f_diroff = original_diroff - 1; fnp->f_diroff = original_diroff - 1;
@ -546,7 +542,7 @@ STATIC COUNT delete_dir_entry(f_node_ptr fnp)
/* The directory has been modified, so set the */ /* The directory has been modified, so set the */
/* bit before closing it, allowing it to be */ /* bit before closing it, allowing it to be */
/* updated */ /* updated */
fnp->f_flags.f_dmod = TRUE; fnp->f_flags |= F_DMOD;
dir_close(fnp); dir_close(fnp);
/* SUCCESSful completion, return it */ /* SUCCESSful completion, return it */
@ -631,7 +627,7 @@ COUNT dos_rmdir(BYTE * path)
/* Check that the directory is empty. Only the */ /* Check that the directory is empty. Only the */
/* "." and ".." are permissable. */ /* "." and ".." are permissable. */
fnp->f_flags.f_dmod = FALSE; fnp->f_flags &= ~F_DMOD;
fnp1 = dir_open(path); fnp1 = dir_open(path);
if (fnp1 == NULL) if (fnp1 == NULL)
{ {
@ -749,9 +745,7 @@ COUNT dos_rename(BYTE * path1, BYTE * path2, int attrib)
/* The directory has been modified, so set the bit before */ /* The directory has been modified, so set the bit before */
/* closing it, allowing it to be updated. */ /* closing it, allowing it to be updated. */
fnp1->f_flags.f_dmod = fnp2->f_flags.f_dmod = TRUE; fnp1->f_flags = fnp2->f_flags = F_DMOD | F_DDIR;
fnp1->f_flags.f_dnew = fnp2->f_flags.f_dnew = FALSE;
fnp1->f_flags.f_ddir = fnp2->f_flags.f_ddir = TRUE;
/* Ok, so we can delete this one. Save the file info. */ /* Ok, so we can delete this one. Save the file info. */
*(fnp1->f_dir.dir_name) = DELETED; *(fnp1->f_dir.dir_name) = DELETED;
@ -833,7 +827,7 @@ STATIC BOOL find_free(f_node_ptr fnp)
/* available, tries to extend the directory. */ /* available, tries to extend the directory. */
STATIC int alloc_find_free(f_node_ptr fnp, char *path, char *fcbname) STATIC int alloc_find_free(f_node_ptr fnp, char *path, char *fcbname)
{ {
fnp->f_flags.f_dmod = FALSE; fnp->f_flags &= ~F_DMOD;
dir_close(fnp); dir_close(fnp);
fnp = split_path(path, fcbname); fnp = split_path(path, fcbname);
@ -843,9 +837,9 @@ STATIC int alloc_find_free(f_node_ptr fnp, char *path, char *fcbname)
/* find an empty slot, we need to abort. */ /* find an empty slot, we need to abort. */
if (find_free(fnp) == 0) if (find_free(fnp) == 0)
{ {
if (fnp->f_flags.f_droot) if (fnp->f_dirstart == 0)
{ {
fnp->f_flags.f_dmod = FALSE; fnp->f_flags &= ~F_DMOD;
dir_close(fnp); dir_close(fnp);
return DE_TOOMANY; return DE_TOOMANY;
} }
@ -934,8 +928,8 @@ COUNT dos_setftime(COUNT fd, date dp, time tp)
/* 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;
fnp->f_dir.dir_time = tp; fnp->f_dir.dir_time = tp;
fnp->f_flags.f_dmod = TRUE; /* mark file as modified */ /* mark file as modified and set this date upon closing */
fnp->f_flags.f_ddate = TRUE; /* set this date upon closing */ fnp->f_flags |= F_DMOD | F_DDATE;
save_far_f_node(fnp); save_far_f_node(fnp);
return SUCCESS; return SUCCESS;
@ -1130,9 +1124,7 @@ COUNT dos_mkdir(BYTE * dir)
init_direntry(&fnp->f_dir, D_DIR, free_fat); init_direntry(&fnp->f_dir, D_DIR, free_fat);
fnp->f_flags.f_dmod = TRUE; fnp->f_flags = F_DMOD | F_DDIR;
fnp->f_flags.f_dnew = FALSE;
fnp->f_flags.f_ddir = TRUE;
fnp->f_offset = 0l; fnp->f_offset = 0l;
@ -1205,7 +1197,7 @@ COUNT dos_mkdir(BYTE * dir)
flush_buffers(dpbp->dpb_unit); flush_buffers(dpbp->dpb_unit);
/* Close the directory so that the entry is updated */ /* Close the directory so that the entry is updated */
fnp->f_flags.f_dmod = TRUE; fnp->f_flags |= F_DMOD;
dir_close(fnp); dir_close(fnp);
return SUCCESS; return SUCCESS;
@ -1232,7 +1224,7 @@ STATIC CLUSTER extend(f_node_ptr fnp)
link_fat(fnp->f_dpb, free_fat, LONG_LAST_CLUSTER); link_fat(fnp->f_dpb, free_fat, LONG_LAST_CLUSTER);
/* Mark the directory so that the entry is updated */ /* Mark the directory so that the entry is updated */
fnp->f_flags.f_dmod = TRUE; fnp->f_flags |= F_DMOD;
return free_fat; return free_fat;
} }
@ -1337,7 +1329,7 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode)
if (relcluster < fnp->f_cluster_offset) if (relcluster < fnp->f_cluster_offset)
{ {
/* Set internal index and cluster size. */ /* Set internal index and cluster size. */
fnp->f_cluster = fnp->f_flags.f_ddir ? fnp->f_dirstart : fnp->f_cluster = (fnp->f_flags & F_DDIR) ? fnp->f_dirstart :
getdstart(fnp->f_dpb, &fnp->f_dir); getdstart(fnp->f_dpb, &fnp->f_dir);
fnp->f_cluster_offset = 0; fnp->f_cluster_offset = 0;
} }
@ -1561,8 +1553,8 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
if (mode==XFR_WRITE) if (mode==XFR_WRITE)
{ {
fnp->f_dir.dir_attrib |= D_ARCHIVE; fnp->f_dir.dir_attrib |= D_ARCHIVE;
fnp->f_flags.f_dmod = TRUE; /* mark file as modified */ fnp->f_flags |= F_DMOD; /* mark file as modified */
fnp->f_flags.f_ddate = FALSE; /* set date not valid any more */ fnp->f_flags &= ~F_DDATE; /* set date not valid any more */
if (dos_extend(fnp) != SUCCESS) if (dos_extend(fnp) != SUCCESS)
{ {
@ -1609,7 +1601,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
/* Do an EOF test and return whatever was transferred */ /* Do an EOF test and return whatever was transferred */
/* 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); save_far_f_node(fnp);
return ret_cnt; return ret_cnt;
@ -1659,7 +1651,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
/* see comments above */ /* see comments above */
if (!fnp->f_flags.f_ddir && /* don't experiment with directories yet */ if (!(fnp->f_flags & F_DDIR) && /* don't experiment with directories yet */
boff == 0) /* complete sectors only */ boff == 0) /* complete sectors only */
{ {
static ULONG startoffset; static ULONG startoffset;
@ -1749,7 +1741,7 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
/* Then compare to what is left, since we can transfer */ /* Then compare to what is left, since we can transfer */
/* a maximum of what is left. */ /* a maximum of what is left. */
xfr_cnt = min(to_xfer, secsize - boff); xfr_cnt = min(to_xfer, secsize - boff);
if (!fnp->f_flags.f_ddir && mode == XFR_READ) if (!(fnp->f_flags & F_DDIR) && mode == XFR_READ)
xfr_cnt = (UWORD) min(xfr_cnt, fnp->f_dir.dir_size - fnp->f_offset); xfr_cnt = (UWORD) min(xfr_cnt, fnp->f_dir.dir_size - fnp->f_offset);
/* transfer a block */ /* transfer a block */
@ -2010,8 +2002,7 @@ COUNT dos_setfattr(BYTE * name, UWORD attrp)
/* set attributes that user requested */ /* set attributes that user requested */
fnp->f_dir.dir_attrib |= attrp; /* JPP */ fnp->f_dir.dir_attrib |= attrp; /* JPP */
fnp->f_flags.f_dmod = TRUE; fnp->f_flags |= F_DMOD | F_DDATE;
fnp->f_flags.f_ddate = TRUE;
save_far_f_node(fnp); save_far_f_node(fnp);
dos_close(fd); dos_close(fd);
return SUCCESS; return SUCCESS;