mirror of
https://github.com/FDOS/kernel.git
synced 2025-07-24 22:34:29 +02:00
Introduce clear_dir() to clear a directory, this was code shared between
dos_mkdir() and extend_dir(). Now dos_mkdir() calls this function to clear the new directory, and then creates the . and .. entries using higher level functions instead of dealing with the blocks directly. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1421 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
parent
ec30074f48
commit
f57099220b
119
kernel/fatfs.c
119
kernel/fatfs.c
@ -807,6 +807,31 @@ STATIC CLUSTER find_fat_free(f_node_ptr fnp)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clear out the blocks in the cluster for a directory */
|
||||||
|
STATIC int clear_dir(f_node_ptr fnp, CLUSTER cluster)
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
for (idx = 0; idx <= fnp->f_dpb->dpb_clsmask; idx++)
|
||||||
|
{
|
||||||
|
struct buffer FAR *bp;
|
||||||
|
|
||||||
|
/* as we are overwriting it completely, don't read first */
|
||||||
|
bp = getblockOver(clus2phys(cluster, fnp->f_dpb) + idx,
|
||||||
|
fnp->f_dpb->dpb_unit);
|
||||||
|
#ifdef DISPLAY_GETBLOCK
|
||||||
|
printf("DIR (clear_dir)\n");
|
||||||
|
#endif
|
||||||
|
if (bp == NULL)
|
||||||
|
return DE_BLKINVLD;
|
||||||
|
fmemset(bp->b_buffer, 0, BUFFERSIZE);
|
||||||
|
bp->b_flag |= BFR_DIRTY | BFR_VALID;
|
||||||
|
|
||||||
|
if (idx != 0)
|
||||||
|
bp->b_flag |= BFR_UNCACHE; /* needs not be cached */
|
||||||
|
}
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
/* create a directory - returns success or a negative error */
|
/* create a directory - returns success or a negative error */
|
||||||
/* number */
|
/* number */
|
||||||
@ -814,9 +839,6 @@ STATIC CLUSTER find_fat_free(f_node_ptr fnp)
|
|||||||
COUNT dos_mkdir(BYTE * dir)
|
COUNT dos_mkdir(BYTE * dir)
|
||||||
{
|
{
|
||||||
REG f_node_ptr fnp;
|
REG f_node_ptr fnp;
|
||||||
REG COUNT idx;
|
|
||||||
struct buffer FAR *bp;
|
|
||||||
struct dpb FAR *dpbp;
|
|
||||||
CLUSTER free_fat, parent;
|
CLUSTER free_fat, parent;
|
||||||
COUNT ret;
|
COUNT ret;
|
||||||
char fcbname[FNAME_SIZE + FEXT_SIZE];
|
char fcbname[FNAME_SIZE + FEXT_SIZE];
|
||||||
@ -865,69 +887,45 @@ COUNT dos_mkdir(BYTE * dir)
|
|||||||
|
|
||||||
fnp->f_flags &= ~SFT_FCLEAN;
|
fnp->f_flags &= ~SFT_FCLEAN;
|
||||||
|
|
||||||
fnp->f_offset = 0l;
|
|
||||||
|
|
||||||
/* Mark the cluster in the FAT as used and create new dir there */
|
/* Mark the cluster in the FAT as used and create new dir there */
|
||||||
dpbp = fnp->f_dpb;
|
if (link_fat(fnp->f_dpb, free_fat, LONG_LAST_CLUSTER) != SUCCESS) /* free->last */
|
||||||
if (link_fat(dpbp, free_fat, LONG_LAST_CLUSTER) != SUCCESS) /* free->last */
|
|
||||||
return DE_HNDLDSKFULL; /* should never happen */
|
return DE_HNDLDSKFULL; /* should never happen */
|
||||||
|
|
||||||
|
/* clean out the new directory */
|
||||||
|
ret = clear_dir(fnp, free_fat);
|
||||||
|
if (ret != SUCCESS)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* Write the new directory entry */
|
||||||
|
dir_write(fnp);
|
||||||
|
|
||||||
/* Craft the new directory. Note that if we're in a new */
|
/* Craft the new directory. Note that if we're in a new */
|
||||||
/* directory just under the root, ".." pointer is 0. */
|
/* directory just under the root, ".." pointer is 0. */
|
||||||
/* as we are overwriting it completely, don't read first */
|
|
||||||
bp = getblockOver(clus2phys(free_fat, dpbp), dpbp->dpb_unit);
|
dir_init_fnode(fnp, free_fat);
|
||||||
#ifdef DISPLAY_GETBLOCK
|
find_free(fnp);
|
||||||
printf("FAT (dos_mkdir)\n");
|
|
||||||
#endif
|
|
||||||
if (bp == NULL)
|
|
||||||
return DE_BLKINVLD;
|
|
||||||
|
|
||||||
/* Create the "." entry */
|
/* Create the "." entry */
|
||||||
init_direntry(&DirEntBuffer, D_DIR, free_fat, ". ");
|
init_direntry(&fnp->f_dir, D_DIR, free_fat, ". ");
|
||||||
|
|
||||||
/* And put it out */
|
/* And put it out */
|
||||||
putdirent(&DirEntBuffer, bp->b_buffer);
|
fnp->f_flags &= ~SFT_FCLEAN;
|
||||||
|
dir_write(fnp);
|
||||||
|
|
||||||
/* create the ".." entry */
|
/* create the ".." entry */
|
||||||
DirEntBuffer.dir_name[1] = '.';
|
if (!find_free(fnp) && ((ret = extend_dir(fnp)) != SUCCESS))
|
||||||
|
return ret;
|
||||||
#ifdef WITHFAT32
|
#ifdef WITHFAT32
|
||||||
if (ISFAT32(dpbp) && parent == dpbp->dpb_xrootclst)
|
if (ISFAT32(fnp->f_dpb) && parent == fnp->f_dpb->dpb_xrootclst)
|
||||||
{
|
{
|
||||||
parent = 0;
|
parent = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
setdstart(dpbp, &DirEntBuffer, parent);
|
/* use . to allow the compiler to merge duplicate strings */
|
||||||
|
init_direntry(&fnp->f_dir, D_DIR, parent, ". ");
|
||||||
|
fnp->f_dir.dir_name[1] = '.';
|
||||||
|
|
||||||
/* and put it out */
|
/* and put it out */
|
||||||
putdirent(&DirEntBuffer, &bp->b_buffer[DIRENT_SIZE]);
|
|
||||||
|
|
||||||
/* fill the rest of the block with zeros */
|
|
||||||
fmemset(&bp->b_buffer[2 * DIRENT_SIZE], 0, BUFFERSIZE - 2 * DIRENT_SIZE);
|
|
||||||
|
|
||||||
/* Mark the block to be written out */
|
|
||||||
bp->b_flag |= BFR_DIRTY | BFR_VALID;
|
|
||||||
|
|
||||||
/* clear out the rest of the blocks in the cluster */
|
|
||||||
for (idx = 1; idx <= dpbp->dpb_clsmask; idx++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* as we are overwriting it completely, don't read first */
|
|
||||||
bp = getblockOver(clus2phys(getdstart(dpbp, &fnp->f_dir), dpbp) + idx,
|
|
||||||
dpbp->dpb_unit);
|
|
||||||
#ifdef DISPLAY_GETBLOCK
|
|
||||||
printf("DIR (dos_mkdir)\n");
|
|
||||||
#endif
|
|
||||||
if (bp == NULL)
|
|
||||||
return DE_BLKINVLD;
|
|
||||||
fmemset(bp->b_buffer, 0, BUFFERSIZE);
|
|
||||||
bp->b_flag |= BFR_DIRTY | BFR_VALID | BFR_UNCACHE; /* need not be cached */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* flush the drive buffers so that all info is written */
|
|
||||||
/* hazard: no error checking! */
|
|
||||||
flush_buffers(dpbp->dpb_unit);
|
|
||||||
|
|
||||||
/* Close the directory so that the entry is updated */
|
|
||||||
fnp->f_flags &= ~SFT_FCLEAN;
|
fnp->f_flags &= ~SFT_FCLEAN;
|
||||||
dir_write(fnp);
|
dir_write(fnp);
|
||||||
|
|
||||||
@ -978,31 +976,14 @@ STATIC CLUSTER extend(f_node_ptr fnp)
|
|||||||
|
|
||||||
STATIC COUNT extend_dir(f_node_ptr fnp)
|
STATIC COUNT extend_dir(f_node_ptr fnp)
|
||||||
{
|
{
|
||||||
REG COUNT idx;
|
int ret;
|
||||||
|
|
||||||
CLUSTER cluster = extend(fnp);
|
CLUSTER cluster = extend(fnp);
|
||||||
if (cluster == LONG_LAST_CLUSTER)
|
if (cluster == LONG_LAST_CLUSTER)
|
||||||
return DE_HNDLDSKFULL;
|
return DE_HNDLDSKFULL;
|
||||||
|
|
||||||
/* clear out the blocks in the cluster */
|
ret = clear_dir(fnp, cluster);
|
||||||
for (idx = 0; idx <= fnp->f_dpb->dpb_clsmask; idx++)
|
if (ret != SUCCESS)
|
||||||
{
|
return ret;
|
||||||
REG struct buffer FAR *bp;
|
|
||||||
|
|
||||||
/* as we are overwriting it completely, don't read first */
|
|
||||||
bp = getblockOver(clus2phys(cluster, fnp->f_dpb) + idx,
|
|
||||||
fnp->f_dpb->dpb_unit);
|
|
||||||
#ifdef DISPLAY_GETBLOCK
|
|
||||||
printf("DIR (extend_dir)\n");
|
|
||||||
#endif
|
|
||||||
if (bp == NULL)
|
|
||||||
return DE_BLKINVLD;
|
|
||||||
fmemset(bp->b_buffer, 0, BUFFERSIZE);
|
|
||||||
bp->b_flag |= BFR_DIRTY | BFR_VALID;
|
|
||||||
|
|
||||||
if (idx != 0)
|
|
||||||
bp->b_flag |= BFR_UNCACHE; /* needs not be cached */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!find_free(fnp))
|
if (!find_free(fnp))
|
||||||
return DE_HNDLDSKFULL;
|
return DE_HNDLDSKFULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user