2000-05-06 21:34:20 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
|
|
|
/* fatdir.c */
|
|
|
|
/* DOS-C */
|
|
|
|
/* */
|
|
|
|
/* FAT File System dir Functions */
|
|
|
|
/* */
|
|
|
|
/* Copyright (c) 1995 */
|
|
|
|
/* Pasquale J. Villani */
|
|
|
|
/* All Rights Reserved */
|
|
|
|
/* */
|
|
|
|
/* This file is part of DOS-C. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is free software; you can redistribute it and/or */
|
|
|
|
/* modify it under the terms of the GNU General Public License */
|
|
|
|
/* as published by the Free Software Foundation; either version */
|
|
|
|
/* 2, or (at your option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is distributed in the hope that it will be useful, but */
|
|
|
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
|
|
|
|
/* the GNU General Public License for more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public */
|
|
|
|
/* License along with DOS-C; see the file COPYING. If not, */
|
|
|
|
/* write to the Free Software Foundation, 675 Mass Ave, */
|
|
|
|
/* Cambridge, MA 02139, USA. */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
#include "portab.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
#ifdef VERSION_STRINGS
|
|
|
|
static BYTE *fatdirRcsId = "$Id$";
|
|
|
|
#endif
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Description.
|
|
|
|
* Initialize a fnode so that it will point to the directory with
|
|
|
|
* dirstart starting cluster; in case of passing dirstart == 0
|
|
|
|
* fnode will point to the start of a root directory */
|
|
|
|
VOID dir_init_fnode(f_node_ptr fnp, CLUSTER dirstart)
|
|
|
|
{
|
|
|
|
/* reset the directory flags */
|
|
|
|
fnp->f_flags.f_dmod = FALSE;
|
|
|
|
fnp->f_flags.f_droot = FALSE;
|
|
|
|
fnp->f_flags.f_ddir = TRUE;
|
|
|
|
fnp->f_flags.f_dnew = TRUE;
|
|
|
|
fnp->f_diroff = fnp->f_offset = fnp->f_cluster_offset = fnp->f_highwater = 0l;
|
|
|
|
|
|
|
|
/* root directory */
|
|
|
|
if (dirstart == 0)
|
|
|
|
{
|
|
|
|
#ifdef WITHFAT32
|
|
|
|
if (ISFAT32(fnp->f_dpb))
|
|
|
|
{
|
|
|
|
fnp->f_cluster = fnp->f_dirstart = fnp->f_dpb->dpb_xrootclst;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
fnp->f_dirstart = 0l;
|
|
|
|
fnp->f_flags.f_droot = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* non-root */
|
|
|
|
fnp->f_cluster = fnp->f_dirstart = dirstart;
|
|
|
|
}
|
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
f_node_ptr dir_open(BYTE * dirname)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-06-03 16:16:18 +02:00
|
|
|
f_node_ptr fnp;
|
2000-05-06 21:34:20 +02:00
|
|
|
COUNT drive;
|
|
|
|
BYTE *p;
|
2001-04-03 01:18:30 +02:00
|
|
|
WORD i;
|
2000-05-06 21:34:20 +02:00
|
|
|
struct cds FAR *cdsp;
|
2001-07-22 03:58:58 +02:00
|
|
|
BYTE *pszPath = dirname + 2;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Allocate an fnode if possible - error return (0) if not. */
|
2001-06-03 16:16:18 +02:00
|
|
|
if ((fnp = get_f_node()) == (f_node_ptr)0)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-06-03 16:16:18 +02:00
|
|
|
return (f_node_ptr)0;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Force the fnode into read-write mode */
|
|
|
|
fnp->f_mode = RDWR;
|
|
|
|
|
|
|
|
/* determine what drive we are using... */
|
|
|
|
if (ParseDosName(dirname, &drive, (BYTE *) 0, (BYTE *) 0, (BYTE *) 0, FALSE)
|
|
|
|
!= SUCCESS)
|
|
|
|
{
|
|
|
|
release_f_node(fnp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the drive was specified, drive is non-negative and */
|
|
|
|
/* corresponds to the one passed in, i.e., 0 = A, 1 = B, etc. */
|
|
|
|
/* We use that and skip the "D:" part of the string. */
|
|
|
|
/* Otherwise, just use the default drive */
|
|
|
|
if (drive >= 0)
|
|
|
|
{
|
|
|
|
dirname += 2; /* Assume FAT style drive */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drive = default_drive;
|
|
|
|
}
|
2001-03-31 00:27:42 +02:00
|
|
|
if (drive >= lastdrive) {
|
2000-05-08 06:30:00 +02:00
|
|
|
release_f_node(fnp);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
cdsp = &CDSp->cds_table[drive];
|
|
|
|
|
|
|
|
/* Generate full path name */
|
2001-07-22 03:58:58 +02:00
|
|
|
/* not necessary anymore, since truename did that already
|
|
|
|
i = cdsp->cdsJoinOffset;
|
|
|
|
ParseDosPath(dirname, (COUNT *) 0, pszPath, (BYTE FAR *) & cdsp->cdsCurrentPath[i]); */
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2000-05-26 21:25:19 +02:00
|
|
|
/* for testing only for now */
|
|
|
|
#if 0
|
2000-05-08 06:30:00 +02:00
|
|
|
if ((cdsp->cdsFlags & CDSNETWDRV))
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
printf("FailSafe %x \n", Int21AX);
|
|
|
|
return fnp;
|
|
|
|
}
|
2000-05-26 21:25:19 +02:00
|
|
|
#endif
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
if (cdsp->cdsDpb == 0)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
release_f_node(fnp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
fnp->f_dpb = cdsp->cdsDpb;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Perform all directory common handling after all special */
|
|
|
|
/* handling has been performed. */
|
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
if (media_check(fnp->f_dpb) < 0)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
release_f_node(fnp);
|
2001-06-03 16:16:18 +02:00
|
|
|
return (f_node_ptr)0;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk the directory tree to find the starting cluster */
|
|
|
|
/* */
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Start from the root directory (dirstart = 0) */
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
dir_init_fnode(fnp, 0);
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
for (p = pszPath; *p != '\0';)
|
|
|
|
{
|
|
|
|
/* skip all path seperators */
|
|
|
|
while (*p == '\\')
|
|
|
|
++p;
|
|
|
|
/* don't continue if we're at the end */
|
|
|
|
if (*p == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Convert the name into an absolute name for */
|
|
|
|
/* comparison... */
|
|
|
|
/* first the file name with trailing spaces... */
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
memset(TempBuffer, ' ', FNAME_SIZE+FEXT_SIZE);
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
for (i = 0; i < FNAME_SIZE; i++)
|
|
|
|
{
|
|
|
|
if (*p != '\0' && *p != '.' && *p != '/' && *p != '\\')
|
|
|
|
TempBuffer[i] = *p++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and the extension (don't forget to */
|
|
|
|
/* add trailing spaces)... */
|
|
|
|
if (*p == '.')
|
|
|
|
++p;
|
|
|
|
for (i = 0; i < FEXT_SIZE; i++)
|
|
|
|
{
|
|
|
|
if (*p != '\0' && *p != '.' && *p != '/' && *p != '\\')
|
|
|
|
TempBuffer[i + FNAME_SIZE] = *p++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now search through the directory to */
|
|
|
|
/* find the entry... */
|
|
|
|
i = FALSE;
|
|
|
|
|
2000-08-06 07:50:17 +02:00
|
|
|
DosUpFMem((BYTE FAR *) TempBuffer, FNAME_SIZE + FEXT_SIZE);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
while (dir_read(fnp) == 1)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED)
|
|
|
|
{
|
2001-07-22 03:58:58 +02:00
|
|
|
if (fcmp(TempBuffer, (BYTE *)fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE))
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
i = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!i || !(fnp->f_dir.dir_attrib & D_DIR))
|
|
|
|
{
|
|
|
|
|
|
|
|
release_f_node(fnp);
|
2001-06-03 16:16:18 +02:00
|
|
|
return (f_node_ptr)0;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* make certain we've moved off */
|
|
|
|
/* root */
|
2001-11-04 20:47:39 +01:00
|
|
|
dir_init_fnode(fnp, getdstart(fnp->f_dir));
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return fnp;
|
|
|
|
}
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Description.
|
|
|
|
* 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
|
|
|
|
* which has been read.
|
|
|
|
* Return value.
|
|
|
|
* 1 - all OK, directory entry having been read is not empty.
|
|
|
|
* 0 - Directory entry is empty.
|
2001-11-14 00:36:45 +01:00
|
|
|
* DE_SEEK - Attempt to read beyound the end of the directory.
|
|
|
|
* DE_BLKINVLD - Invalid block.
|
2001-11-04 20:47:39 +01:00
|
|
|
* Note. Empty directory entries always resides at the end of the directory. */
|
2001-06-03 16:16:18 +02:00
|
|
|
COUNT dir_read(REG f_node_ptr fnp)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
struct buffer FAR *bp;
|
2001-07-23 14:47:42 +02:00
|
|
|
REG UWORD secsize = fnp->f_dpb->dpb_secsize;
|
2001-11-04 20:47:39 +01:00
|
|
|
ULONG new_diroff = fnp->f_diroff;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Directories need to point to their current offset, not for */
|
|
|
|
/* next op. Therefore, if it is anything other than the first */
|
|
|
|
/* directory entry, we will update the offset on entry rather */
|
|
|
|
/* than wait until exit. If it was new, clear the special new */
|
|
|
|
/* flag. */
|
2001-11-04 20:47:39 +01:00
|
|
|
if (!fnp->f_flags.f_dnew)
|
|
|
|
new_diroff += DIRENT_SIZE;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Determine if we hit the end of the directory. If we have, */
|
|
|
|
/* bump the offset back to the end and exit. If not, fill the */
|
|
|
|
/* dirent portion of the fnode, clear the f_dmod bit and leave, */
|
|
|
|
/* but only for root directories */
|
2001-11-04 20:47:39 +01:00
|
|
|
|
|
|
|
if (fnp->f_flags.f_droot)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-11-04 20:47:39 +01:00
|
|
|
if (new_diroff >= DIRENT_SIZE * (ULONG)fnp->f_dpb->dpb_dirents)
|
2001-11-14 00:36:45 +01:00
|
|
|
return DE_SEEK;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
bp = getblock((ULONG) (new_diroff / secsize
|
|
|
|
+ fnp->f_dpb->dpb_dirstrt),
|
|
|
|
fnp->f_dpb->dpb_unit);
|
2000-05-06 21:34:20 +02:00
|
|
|
#ifdef DISPLAY_GETBLOCK
|
2001-11-04 20:47:39 +01:00
|
|
|
printf("DIR (dir_read)\n");
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
2001-11-04 20:47:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Do a "seek" to the directory position */
|
|
|
|
fnp->f_offset = new_diroff;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Search through the FAT to find the block */
|
|
|
|
/* that this entry is in. */
|
2000-05-06 21:34:20 +02:00
|
|
|
#ifdef DISPLAY_GETBLOCK
|
2001-11-04 20:47:39 +01:00
|
|
|
printf("dir_read: ");
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
2001-11-14 00:36:45 +01:00
|
|
|
if (map_cluster(fnp, XFR_READ) != SUCCESS)
|
|
|
|
return DE_SEEK;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Compute the block within the cluster and the */
|
|
|
|
/* offset within the block. */
|
|
|
|
fnp->f_sector = (fnp->f_offset / secsize) & fnp->f_dpb->dpb_clsmask;
|
|
|
|
fnp->f_boff = fnp->f_offset % secsize;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Get the block we need from cache */
|
|
|
|
bp = getblock(clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector,
|
|
|
|
fnp->f_dpb->dpb_unit);
|
2000-05-06 21:34:20 +02:00
|
|
|
#ifdef DISPLAY_GETBLOCK
|
2001-11-04 20:47:39 +01:00
|
|
|
printf("DIR (dir_read)\n");
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
2001-11-04 20:47:39 +01:00
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Now that we have the block for our entry, get the */
|
|
|
|
/* directory entry. */
|
|
|
|
if (bp == NULL)
|
|
|
|
return DE_BLKINVLD;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
bp->b_flag &= ~(BFR_DATA | BFR_FAT);
|
|
|
|
bp->b_flag |= BFR_DIR | BFR_VALID;
|
2001-07-23 14:47:42 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
getdirent((BYTE FAR *) & bp->b_buffer[((UWORD)new_diroff) % fnp->f_dpb->dpb_secsize],
|
|
|
|
(struct dirent FAR *)&fnp->f_dir);
|
2001-07-23 14:47:42 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Update the fnode's directory info */
|
|
|
|
fnp->f_flags.f_dmod = FALSE;
|
|
|
|
fnp->f_flags.f_dnew = FALSE;
|
|
|
|
fnp->f_diroff = new_diroff;
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* and for efficiency, stop when we hit the first */
|
|
|
|
/* unused entry. */
|
|
|
|
/* either returns 1 or 0 */
|
|
|
|
return (fnp->f_dir.dir_name[0] != '\0');
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Description.
|
|
|
|
* Writes directory entry pointed by fnp to disk. In case of erroneous
|
|
|
|
* situation fnode is released.
|
|
|
|
* Return value.
|
|
|
|
* TRUE - all OK.
|
|
|
|
* FALSE - error occured (fnode is released).
|
|
|
|
*/
|
2000-05-06 21:34:20 +02:00
|
|
|
#ifndef IPL
|
2001-11-04 20:47:39 +01:00
|
|
|
BOOL dir_write(REG f_node_ptr fnp)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
struct buffer FAR *bp;
|
2001-07-23 14:47:42 +02:00
|
|
|
REG UWORD secsize = fnp->f_dpb->dpb_secsize;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Update the entry if it was modified by a write or create... */
|
|
|
|
if (fnp->f_flags.f_dmod)
|
|
|
|
{
|
|
|
|
/* Root is a consecutive set of blocks, so handling is */
|
|
|
|
/* simple. */
|
|
|
|
if (fnp->f_flags.f_droot)
|
|
|
|
{
|
|
|
|
bp = getblock(
|
2001-07-23 14:47:42 +02:00
|
|
|
(ULONG) ((UWORD)fnp->f_diroff / secsize
|
2000-05-06 21:34:20 +02:00
|
|
|
+ fnp->f_dpb->dpb_dirstrt),
|
|
|
|
fnp->f_dpb->dpb_unit);
|
|
|
|
#ifdef DISPLAY_GETBLOCK
|
|
|
|
printf("DIR (dir_write)\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All other directories are just files. The only */
|
|
|
|
/* special handling is resetting the offset so that we */
|
|
|
|
/* can continually update the same directory entry. */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Do a "seek" to the directory position */
|
|
|
|
/* and convert the fnode to a directory fnode. */
|
|
|
|
fnp->f_offset = fnp->f_diroff;
|
|
|
|
fnp->f_back = LONG_LAST_CLUSTER;
|
|
|
|
fnp->f_cluster = fnp->f_dirstart;
|
|
|
|
fnp->f_cluster_offset = 0l; /*JPP */
|
|
|
|
|
|
|
|
/* Search through the FAT to find the block */
|
|
|
|
/* that this entry is in. */
|
|
|
|
#ifdef DISPLAY_GETBLOCK
|
|
|
|
printf("dir_write: ");
|
|
|
|
#endif
|
2001-11-14 00:36:45 +01:00
|
|
|
if (map_cluster(fnp, XFR_READ) != SUCCESS)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
release_f_node(fnp);
|
2001-11-04 20:47:39 +01:00
|
|
|
return FALSE;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the block within the cluster and the */
|
|
|
|
/* offset within the block. */
|
|
|
|
fnp->f_sector = (fnp->f_offset / secsize) & fnp->f_dpb->dpb_clsmask;
|
|
|
|
fnp->f_boff = fnp->f_offset % secsize;
|
|
|
|
|
|
|
|
/* Get the block we need from cache */
|
2001-11-04 20:47:39 +01:00
|
|
|
bp = getblock(clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector,
|
2000-05-06 21:34:20 +02:00
|
|
|
fnp->f_dpb->dpb_unit);
|
|
|
|
bp->b_flag &= ~(BFR_DATA | BFR_FAT);
|
2001-06-03 16:16:18 +02:00
|
|
|
bp->b_flag |= BFR_DIR | BFR_VALID;
|
2000-05-06 21:34:20 +02:00
|
|
|
#ifdef DISPLAY_GETBLOCK
|
|
|
|
printf("DIR (dir_write)\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-04-29 19:34:41 +02:00
|
|
|
/* Now that we have a block, transfer the directory */
|
2000-05-06 21:34:20 +02:00
|
|
|
/* entry into the block. */
|
|
|
|
if (bp == NULL)
|
|
|
|
{
|
|
|
|
release_f_node(fnp);
|
2001-11-04 20:47:39 +01:00
|
|
|
return FALSE;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-09-23 22:39:44 +02:00
|
|
|
|
|
|
|
if (fnp->f_flags.f_dnew && fnp->f_dir.dir_attrib != D_LFN)
|
|
|
|
fmemset(&fnp->f_dir.dir_case, 0, 8);
|
2000-05-06 21:34:20 +02:00
|
|
|
putdirent((struct dirent FAR *)&fnp->f_dir,
|
2001-07-23 14:47:42 +02:00
|
|
|
(VOID FAR *) & bp->b_buffer[(UWORD)fnp->f_diroff % fnp->f_dpb->dpb_secsize]);
|
|
|
|
|
|
|
|
bp->b_flag &= ~(BFR_DATA | BFR_FAT);
|
|
|
|
bp->b_flag |= BFR_DIR | BFR_DIRTY | BFR_VALID;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-11-04 20:47:39 +01:00
|
|
|
return TRUE;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-06-03 16:16:18 +02:00
|
|
|
VOID dir_close(REG f_node_ptr fnp)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
REG COUNT disk = fnp->f_dpb->dpb_unit;
|
|
|
|
|
|
|
|
/* Test for invalid f_nodes */
|
|
|
|
if (fnp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifndef IPL
|
|
|
|
/* Write out the entry */
|
|
|
|
dir_write(fnp);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/* Clear buffers after release */
|
|
|
|
flush_buffers(disk);
|
|
|
|
|
|
|
|
/* and release this instance of the fnode */
|
|
|
|
release_f_node(fnp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef IPL
|
2001-07-22 03:58:58 +02:00
|
|
|
COUNT dos_findfirst(UCOUNT attr, BYTE *name)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-06-03 16:16:18 +02:00
|
|
|
REG f_node_ptr fnp;
|
2001-07-24 18:56:29 +02:00
|
|
|
REG dmatch *dmp = (dmatch *) TempBuffer;
|
2000-05-06 21:34:20 +02:00
|
|
|
REG COUNT i;
|
2001-07-24 18:56:29 +02:00
|
|
|
COUNT nDrive;
|
2000-05-06 21:34:20 +02:00
|
|
|
BYTE *p;
|
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
BYTE local_name[FNAME_SIZE + 1],
|
2001-03-21 03:56:26 +01:00
|
|
|
local_ext[FEXT_SIZE + 1];
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
/* printf("ff %Fs\n", name);*/
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* The findfirst/findnext calls are probably the worst of the */
|
|
|
|
/* DOS calls. They must work somewhat on the fly (i.e. - open */
|
|
|
|
/* but never close). Since we don't want to lose fnodes every */
|
|
|
|
/* time a directory is searched, we will initialize the DOS */
|
|
|
|
/* dirmatch structure and then for every find, we will open the */
|
|
|
|
/* current directory, do a seek and read, then close the fnode. */
|
|
|
|
|
|
|
|
/* Parse out the drive, file name and file extension. */
|
2001-07-24 18:56:29 +02:00
|
|
|
i = ParseDosName(name, &nDrive, &szDirName[2], local_name, local_ext, TRUE);
|
2000-05-06 21:34:20 +02:00
|
|
|
if (i != SUCCESS)
|
|
|
|
return i;
|
2000-06-01 08:46:57 +02:00
|
|
|
/*
|
2000-06-01 08:37:38 +02:00
|
|
|
printf("\nff %s", Tname);
|
|
|
|
printf("ff %s", local_name);
|
|
|
|
printf("ff %s\n", local_ext);
|
2000-06-01 08:46:57 +02:00
|
|
|
*/
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Build the match pattern out of the passed string */
|
|
|
|
/* copy the part of the pattern which belongs to the filename and is fixed */
|
2001-11-04 20:47:39 +01:00
|
|
|
for (p = local_name, i = 0; i < FNAME_SIZE && *p; ++p, ++i)
|
2000-05-06 21:34:20 +02:00
|
|
|
SearchDir.dir_name[i] = *p;
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
for (; i < FNAME_SIZE; ++i)
|
2001-11-04 20:47:39 +01:00
|
|
|
SearchDir.dir_name[i] = ' ';
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* and the extension (don't forget to add trailing spaces)... */
|
2001-11-04 20:47:39 +01:00
|
|
|
for (p = local_ext, i = 0; i < FEXT_SIZE && *p; ++p, ++i)
|
2000-05-06 21:34:20 +02:00
|
|
|
SearchDir.dir_ext[i] = *p;
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
for (; i < FEXT_SIZE; ++i)
|
2001-11-04 20:47:39 +01:00
|
|
|
SearchDir.dir_ext[i] = ' ';
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Convert everything to uppercase. */
|
2000-08-06 07:50:17 +02:00
|
|
|
DosUpFMem(SearchDir.dir_name, FNAME_SIZE + FEXT_SIZE);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Now search through the directory to find the entry... */
|
2001-04-15 05:21:50 +02:00
|
|
|
|
|
|
|
/* Complete building the directory from the passed in */
|
|
|
|
/* name */
|
2001-07-24 18:56:29 +02:00
|
|
|
szDirName[0] = 'A' + nDrive;
|
2001-07-22 03:58:58 +02:00
|
|
|
szDirName[1] = ':';
|
2001-04-15 05:21:50 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Special handling - the volume id is only in the root */
|
|
|
|
/* directory and only searched for once. So we need to open */
|
|
|
|
/* the root and return only the first entry that contains the */
|
|
|
|
/* volume id bit set. */
|
2001-08-19 14:58:36 +02:00
|
|
|
if (attr == D_VOLID)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-07-22 03:58:58 +02:00
|
|
|
szDirName[2] = '\\';
|
|
|
|
szDirName[3] = '\0';
|
2001-04-15 05:21:50 +02:00
|
|
|
}
|
|
|
|
/* Now open this directory so that we can read the */
|
|
|
|
/* fnode entry and do a match on it. */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
/* printf("dir_open %s\n", szDirName);*/
|
|
|
|
if ((fnp = dir_open(szDirName)) == NULL)
|
2001-04-15 05:21:50 +02:00
|
|
|
return DE_PATHNOTFND;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-07-24 18:56:29 +02:00
|
|
|
/* Now initialize the dirmatch structure. */
|
|
|
|
|
|
|
|
nDrive=get_verify_drive(name);
|
|
|
|
if (nDrive < 0)
|
|
|
|
return nDrive;
|
|
|
|
dmp->dm_drive = nDrive;
|
|
|
|
dmp->dm_attr_srch = attr;
|
|
|
|
|
|
|
|
/* Copy the raw pattern from our data segment to the DTA. */
|
2001-11-18 00:26:45 +01:00
|
|
|
fmemcpy(dmp->dm_name_pat, SearchDir.dir_name, FNAME_SIZE + FEXT_SIZE);
|
2001-07-24 18:56:29 +02:00
|
|
|
|
2001-08-19 14:58:36 +02:00
|
|
|
if (attr == D_VOLID)
|
2001-04-15 05:21:50 +02:00
|
|
|
{
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Now do the search */
|
2001-11-04 20:47:39 +01:00
|
|
|
while (dir_read(fnp) == 1)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
/* Test the attribute and return first found */
|
|
|
|
if ((fnp->f_dir.dir_attrib & ~(D_RDONLY | D_ARCHIVE)) == D_VOLID)
|
|
|
|
{
|
2001-09-23 22:39:44 +02:00
|
|
|
dmp->dm_dircluster = fnp->f_dirstart; /* TE */
|
2001-07-24 18:56:29 +02:00
|
|
|
memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
|
2000-05-06 21:34:20 +02:00
|
|
|
dir_close(fnp);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now that we've done our failed search, close it and */
|
|
|
|
/* return an error. */
|
|
|
|
dir_close(fnp);
|
|
|
|
return DE_FILENOTFND;
|
|
|
|
}
|
|
|
|
/* Otherwise just do a normal find next */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dmp->dm_entry = 0;
|
|
|
|
if (!fnp->f_flags.f_droot)
|
2001-09-23 22:39:44 +02:00
|
|
|
dmp->dm_dircluster = fnp->f_dirstart;
|
2000-05-06 21:34:20 +02:00
|
|
|
else
|
2001-09-23 22:39:44 +02:00
|
|
|
dmp->dm_dircluster = 0;
|
2000-05-06 21:34:20 +02:00
|
|
|
dir_close(fnp);
|
|
|
|
return dos_findnext();
|
|
|
|
}
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
/*
|
|
|
|
BUGFIX TE 06/28/01
|
|
|
|
|
|
|
|
when using FcbFindXxx, the only information available is
|
|
|
|
the cluster number + entrycount. everything else MUST\
|
|
|
|
be recalculated.
|
|
|
|
a good test for this is MSDOS CHKDSK, which now (seems too) work
|
|
|
|
*/
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
COUNT dos_findnext(void)
|
|
|
|
{
|
2001-07-24 18:56:29 +02:00
|
|
|
REG dmatch *dmp = (dmatch *) TempBuffer;
|
2001-06-03 16:16:18 +02:00
|
|
|
REG f_node_ptr fnp;
|
2000-05-06 21:34:20 +02:00
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
/* Allocate an fnode if possible - error return (0) if not. */
|
2001-06-03 16:16:18 +02:00
|
|
|
if ((fnp = get_f_node()) == (f_node_ptr)0)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-04-15 05:21:50 +02:00
|
|
|
return DE_NFILES;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
memset(fnp, 0, sizeof(*fnp));
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Force the fnode into read-write mode */
|
|
|
|
fnp->f_mode = RDWR;
|
|
|
|
|
|
|
|
/* Select the default to help non-drive specified path */
|
|
|
|
/* searches... */
|
2001-04-15 05:21:50 +02:00
|
|
|
fnp->f_dpb = CDSp->cds_table[dmp->dm_drive].cdsDpb;
|
2000-05-06 21:34:20 +02:00
|
|
|
if (media_check(fnp->f_dpb) < 0)
|
|
|
|
{
|
|
|
|
release_f_node(fnp);
|
2001-04-15 05:21:50 +02:00
|
|
|
return DE_NFILES;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
dir_init_fnode(fnp, dmp->dm_dircluster);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Search through the directory to find the entry, but do a */
|
|
|
|
/* seek first. */
|
|
|
|
if (dmp->dm_entry > 0)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-11-04 20:47:39 +01:00
|
|
|
fnp->f_diroff = (ULONG)(dmp->dm_entry - 1) * DIRENT_SIZE;
|
2001-07-10 00:19:33 +02:00
|
|
|
fnp->f_flags.f_dnew = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fnp->f_diroff = 0;
|
|
|
|
fnp->f_flags.f_dnew = TRUE;
|
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Loop through the directory */
|
2001-11-04 20:47:39 +01:00
|
|
|
while (dir_read(fnp) == 1)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
++dmp->dm_entry;
|
2001-09-23 22:39:44 +02:00
|
|
|
if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED
|
|
|
|
&& (fnp->f_dir.dir_attrib & D_VOLID) != D_VOLID )
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-07-22 03:58:58 +02:00
|
|
|
if (fcmp_wild((BYTE FAR *)dmp->dm_name_pat, (BYTE FAR *)fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE))
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2000-06-21 20:16:46 +02:00
|
|
|
/*
|
|
|
|
MSD Command.com uses FCB FN 11 & 12 with attrib set to 0x16.
|
|
|
|
Bits 0x21 seem to get set some where in MSD so Rd and Arc
|
2001-07-10 00:19:33 +02:00
|
|
|
files are returned.
|
|
|
|
RdOnly + Archive bits are ignored
|
2000-06-21 20:16:46 +02:00
|
|
|
*/
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Test the attribute as the final step */
|
2001-08-19 14:58:36 +02:00
|
|
|
if (!(fnp->f_dir.dir_attrib & D_VOLID) &&
|
|
|
|
((~dmp->dm_attr_srch & fnp->f_dir.dir_attrib & (D_DIR | D_SYSTEM | D_HIDDEN)) == 0))
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If found, transfer it to the dmatch structure */
|
|
|
|
if (found)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-09-23 22:39:44 +02:00
|
|
|
dmp->dm_dircluster = fnp->f_dirstart;
|
2001-07-24 18:56:29 +02:00
|
|
|
memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* return the result */
|
|
|
|
release_f_node(fnp);
|
|
|
|
|
2001-04-03 01:18:30 +02:00
|
|
|
return found ? SUCCESS : DE_NFILES;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-03-21 03:56:26 +01:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
this receives a name in 11 char field NAME+EXT and builds
|
|
|
|
a zeroterminated string
|
2001-06-03 16:16:18 +02:00
|
|
|
|
|
|
|
unfortunately, blanks are allowed in filenames. like
|
|
|
|
"test e", " test .y z",...
|
|
|
|
|
|
|
|
so we have to work from the last blank backward
|
2001-03-21 03:56:26 +01:00
|
|
|
*/
|
|
|
|
void ConvertName83ToNameSZ(BYTE FAR *destSZ, BYTE FAR *srcFCBName)
|
|
|
|
{
|
|
|
|
int loop;
|
|
|
|
int noExtension = FALSE;
|
|
|
|
|
|
|
|
if (*srcFCBName == '.')
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-03-21 03:56:26 +01:00
|
|
|
noExtension = TRUE;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2001-06-03 16:16:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
fmemcpy(destSZ,srcFCBName,FNAME_SIZE);
|
|
|
|
|
|
|
|
srcFCBName += FNAME_SIZE;
|
|
|
|
|
|
|
|
for (loop = FNAME_SIZE; --loop >= 0; )
|
|
|
|
{
|
|
|
|
if (destSZ[loop] != ' ')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
destSZ += loop + 1;
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (!noExtension) /* not for ".", ".." */
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-06-03 16:16:18 +02:00
|
|
|
|
|
|
|
for (loop = FEXT_SIZE; --loop >= 0; )
|
2001-03-21 03:56:26 +01:00
|
|
|
{
|
2001-06-03 16:16:18 +02:00
|
|
|
if (srcFCBName[loop] != ' ')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (loop >= 0)
|
|
|
|
{
|
2001-03-21 03:56:26 +01:00
|
|
|
*destSZ++ = '.';
|
2001-06-03 16:16:18 +02:00
|
|
|
fmemcpy(destSZ,srcFCBName,loop+1);
|
|
|
|
destSZ += loop+1;
|
2001-03-21 03:56:26 +01:00
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-03-21 03:56:26 +01:00
|
|
|
*destSZ = '\0';
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-06-03 16:16:18 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
returns the asciiSZ length of a 8.3 filename
|
|
|
|
*/
|
|
|
|
|
|
|
|
int FileName83Length(BYTE *filename83)
|
|
|
|
{
|
|
|
|
BYTE buff[13];
|
|
|
|
|
|
|
|
ConvertName83ToNameSZ(buff, filename83);
|
|
|
|
|
|
|
|
return strlen(buff);
|
2001-07-24 18:56:29 +02:00
|
|
|
}
|
2001-11-18 00:26:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Log: fatdir.c,v - for newer log entries do a "cvs log fatdir.c"
|
|
|
|
*
|
|
|
|
* Revision 1.12 2000/03/31 05:40:09 jtabor
|
|
|
|
* Added Eric W. Biederman Patches
|
|
|
|
*
|
|
|
|
* Revision 1.11 2000/03/17 22:59:04 kernel
|
|
|
|
* Steffen Kaiser's NLS changes
|
|
|
|
*
|
|
|
|
* Revision 1.10 2000/03/09 06:07:11 kernel
|
|
|
|
* 2017f updates by James Tabor
|
|
|
|
*
|
|
|
|
* Revision 1.9 1999/08/25 03:18:07 jprice
|
|
|
|
* ror4 patches to allow TC 2.01 compile.
|
|
|
|
*
|
|
|
|
* Revision 1.8 1999/08/10 17:57:12 jprice
|
|
|
|
* ror4 2011-02 patch
|
|
|
|
*
|
|
|
|
* Revision 1.7 1999/05/03 06:25:45 jprice
|
|
|
|
* Patches from ror4 and many changed of signed to unsigned variables.
|
|
|
|
*
|
|
|
|
* Revision 1.6 1999/04/16 00:53:32 jprice
|
|
|
|
* Optimized FAT handling
|
|
|
|
*
|
|
|
|
* Revision 1.5 1999/04/13 15:48:20 jprice
|
|
|
|
* no message
|
|
|
|
*
|
|
|
|
* Revision 1.4 1999/04/11 04:33:38 jprice
|
|
|
|
* ror4 patches
|
|
|
|
*
|
|
|
|
* Revision 1.2 1999/04/04 18:51:43 jprice
|
|
|
|
* no message
|
|
|
|
*
|
|
|
|
* Revision 1.1.1.1 1999/03/29 15:41:58 jprice
|
|
|
|
* New version without IPL.SYS
|
|
|
|
*
|
|
|
|
* Revision 1.7 1999/03/25 05:06:57 jprice
|
|
|
|
* Fixed findfirst & findnext functions to treat the attributes like MSDOS does.
|
|
|
|
*
|
|
|
|
* Revision 1.6 1999/02/14 04:27:09 jprice
|
|
|
|
* Changed check media so that it checks if a floppy disk has been changed.
|
|
|
|
*
|
|
|
|
* Revision 1.5 1999/02/09 02:54:23 jprice
|
|
|
|
* Added Pat's 1937 kernel patches
|
|
|
|
*
|
|
|
|
* Revision 1.4 1999/02/01 01:43:28 jprice
|
|
|
|
* Fixed findfirst function to find volume label with Windows long filenames
|
|
|
|
*
|
|
|
|
* Revision 1.3 1999/01/30 08:25:34 jprice
|
|
|
|
* Clean up; Fixed bug with set attribute function. If you tried to
|
|
|
|
* change the attributres of a directory, it would erase it.
|
|
|
|
*
|
|
|
|
* Revision 1.2 1999/01/22 04:15:28 jprice
|
|
|
|
* Formating
|
|
|
|
*
|
|
|
|
* Revision 1.1.1.1 1999/01/20 05:51:00 jprice
|
|
|
|
* Imported sources
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Rev 1.10 06 Dec 1998 8:44:36 patv
|
|
|
|
* Bug fixes.
|
|
|
|
*
|
|
|
|
* Rev 1.9 22 Jan 1998 4:09:00 patv
|
|
|
|
* Fixed pointer problems affecting SDA
|
|
|
|
*
|
|
|
|
* Rev 1.8 04 Jan 1998 23:14:36 patv
|
|
|
|
* Changed Log for strip utility
|
|
|
|
*
|
|
|
|
* Rev 1.7 03 Jan 1998 8:36:02 patv
|
|
|
|
* Converted data area to SDA format
|
|
|
|
*
|
|
|
|
* Rev 1.6 16 Jan 1997 12:46:30 patv
|
|
|
|
* pre-Release 0.92 feature additions
|
|
|
|
*
|
|
|
|
* Rev 1.5 29 May 1996 21:15:18 patv
|
|
|
|
* bug fixes for v0.91a
|
|
|
|
*
|
|
|
|
* Rev 1.4 19 Feb 1996 3:20:12 patv
|
|
|
|
* Added NLS, int2f and config.sys processing
|
|
|
|
*
|
|
|
|
* Rev 1.2 01 Sep 1995 17:48:38 patv
|
|
|
|
* First GPL release.
|
|
|
|
*
|
|
|
|
* Rev 1.1 30 Jul 1995 20:50:24 patv
|
|
|
|
* Eliminated version strings in ipl
|
|
|
|
*
|
|
|
|
* Rev 1.0 02 Jul 1995 8:04:34 patv
|
|
|
|
* Initial revision.
|
|
|
|
*/
|
|
|
|
|