📄 drobj.c
字号:
Description
Find the next block in either the root or a cluster chain.
Returns
Returns 0 on end of root dir or chain.
****************************************************************************/
/* Return the next block in a chain */
BLOCKT pc_l_next_block(DDRIVE *pdrive, BLOCKT curblock) /*__fn__*/
{
#if (RTFS_SUBDIRS || FAT32) /* DM: 7-6-99: added conditional */
CLUSTERTYPE cluster;
#endif
/* If the block is in the root area */
if (curblock < pdrive->firstclblock)
{
if (curblock < pdrive->rootblock)
return (BLOCKEQ0);
else if (++curblock < pdrive->firstclblock)
return (curblock);
else
return (BLOCKEQ0);
}
#if (RTFS_SUBDIRS || FAT32) /* DM: 7-6-99: FIX -- added || FAT32 */
/* In cluster space */
else
{
if (curblock >= pdrive->numsecs)
return (BLOCKEQ0);
/* Get the next block */
curblock += 1;
/* If the next block is not on a cluster edge then it must be
in the same cluster as the current. - otherwise we have to
get the firt block from the next cluster in the chain */
if (pc_sec2index(pdrive, curblock))
return (curblock);
else
{
curblock -= 1;
/* Get the old cluster number - No error test needed */
cluster = pc_sec2cluster(pdrive,curblock);
/* Consult the fat for the next cluster */
cluster = pc_clnext(pdrive, cluster);
if (!cluster)
return (BLOCKEQ0); /* End of chain */
else
return (pc_cl2sector(pdrive, cluster));
}
}
#else
return (BLOCKEQ0);
#endif
}
RTFS_FILE(marki.c, pc_marki)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/**************************************************************************
PC_MARKI - Set dr:sec:index info and stitch a FINODE into the inode list
Description
Each inode is uniquely determined by DRIVE, BLOCK and Index into that
block. This routine takes an inode structure assumed to contain the
equivalent of a DOS directory entry. And stitches it into the current
active inode list. Drive block and index are stored for later calls
to pc_scani and the inode's opencount is set to one.
Returns
Nothing
***************************************************************************/
/* Take an unlinked inode and link it in to the inode chain. Initialize
the open count and sector locater info. */
void pc_marki( FINODE *pfi, DDRIVE *pdrive, BLOCKT sectorno, int index)/*__fn__*/
{
OS_CLAIM_FSCRITICAL()
pfi->my_drive = pdrive;
pfi->my_block = sectorno;
pfi->my_index = index;
pfi->opencount = 1;
/* Stitch the inode at the front of the list */
if (inoroot)
inoroot->pprev = pfi;
pfi->pprev = 0;
pfi->pnext = inoroot;
inoroot = pfi;
OS_RELEASE_FSCRITICAL()
}
RTFS_FILE(scani.c, pc_scani)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/**************************************************************************
PC_SCANI - Search for an inode in the internal inode list.
Description
Each inode is uniquely determined by DRIVE, BLOCK and Index into that
block. This routine searches the current active inode list to see
if the inode is in use. If so the opencount is changed and a pointer is
returned. This guarantees that two processes will work on the same
information when manipulating the same file or directory.
Returns
A pointer to the FINODE for pdrive:sector:index or NULL if not found
****************************************************************************/
/* See if the inode for drive,sector , index is in the list. If so..
bump its open count and return it. Else return NULL */
FINODE *pc_scani( DDRIVE *pdrive, BLOCKT sectorno, int index) /*__fn__*/
{
FINODE *pfi;
OS_CLAIM_FSCRITICAL()
pfi = inoroot;
while (pfi)
{
if ( (pfi->my_drive == pdrive) &&
(pfi->my_block == sectorno) &&
(pfi->my_index == index) )
{
pfi->opencount += 1;
OS_RELEASE_FSCRITICAL()
return (pfi);
}
pfi = pfi->pnext;
}
OS_RELEASE_FSCRITICAL()
return (0);
}
RTFS_FILE(allocobj.c, pc_allocobj)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/**************************************************************************
PC_ALLOCOBJ - Allocate a DROBJ structure
Description
Allocates and zeroes the space needed to store a DROBJ structure. Also
allocates and zeroes a FINODE structure and links the two via the
finode field in the DROBJ structure.
Returns
Returns a valid pointer or NULL if no more core.
*****************************************************************************/
DROBJ *pc_allocobj(void) /*__fn__*/
{
DROBJ *pobj;
/* Alloc a DROBJ */
pobj = pc_memory_drobj(0);
if (pobj)
{
pobj->finode = pc_alloci();
if (!pobj->finode)
{
/* Free the DROBJ */
pc_memory_drobj(pobj);
pobj = 0;
}
}
return (pobj);
}
RTFS_FILE(alloci.c, pc_alloci)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/**************************************************************************
PC_ALLOCI - Allocate a FINODE structure
Description
Allocates and zeroes a FINODE structure.
Returns
Returns a valid pointer or NULL if no more core.
****************************************************************************/
FINODE *pc_alloci(void) /*__fn__*/
{
FINODE *p;
p = pc_memory_finode(0);
return(p);
}
RTFS_FILE(freealli.c, pc_free_all_i)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/**************************************************************************
PC_FREE_ALL_I - Release all inode buffers associated with a drive.
Description
For each internally buffered finode (dirent) check if it exists on
pdrive. If so delete it. In debug mode print a message since all
finodes should be freed before pc_dskclose is called.
Returns
Nothing
****************************************************************************/
void pc_free_all_i( DDRIVE *pdrive) /*__fn__*/
{
FINODE *pfi;
OS_CLAIM_FSCRITICAL()
pfi = inoroot;
OS_RELEASE_FSCRITICAL()
while (pfi)
{
if (pfi->my_drive == pdrive)
{
/* Set the opencount to 1 so freei releases the inode */
pfi->opencount = 1;
pc_freei(pfi);
/* Since we changed the list go back to the top */
OS_CLAIM_FSCRITICAL()
pfi = inoroot;
OS_RELEASE_FSCRITICAL()
}
else
{
OS_CLAIM_FSCRITICAL()
pfi = pfi->pnext;
OS_RELEASE_FSCRITICAL()
}
}
}
RTFS_FILE(freei.c, pc_freei)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/*****************************************************************************
PC_FREEI - Release an inode from service
Description
If the FINODE structure is only being used by one file or DROBJ, unlink it
from the internal active inode list and return it to the heap; otherwise
reduce its open count.
Returns
Nothing
****************************************************************************/
void pc_freei( FINODE *pfi) /*__fn__*/
{
if (!pfi)
{
return;
}
OS_CLAIM_FSCRITICAL()
if (pfi->opencount)
{
if (--pfi->opencount) /* Decrement opencount and return if non zero */
{
OS_RELEASE_FSCRITICAL()
return;
}
else
{
if (pfi->pprev) /* Pont the guy behind us at the guy in front*/
{
pfi->pprev->pnext = pfi->pnext;
}
else
{
inoroot = pfi->pnext; /* No prev, we were at the front so
make the next guy the front */
}
if (pfi->pnext) /* Make the next guy point behind */
{
pfi->pnext->pprev = pfi->pprev;
}
}
}
OS_RELEASE_FSCRITICAL()
/* release the core */
pc_memory_finode(pfi);
}
RTFS_FILE(freeobj.c, pc_freeobj)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/***************************************************************************
PC_FREEOBJ - Free a DROBJ structure
Description
Return a drobj structure to the heap. Calls pc_freei to reduce the
open count of the finode structure it points to and return it to the
heap if appropriate.
Returns
Nothing
****************************************************************************/
void pc_freeobj( DROBJ *pobj) /*__fn__*/
{
if (pobj)
{
pc_freei(pobj->finode);
/* Release the core */
pc_memory_drobj(pobj);
}
}
RTFS_FILE(dos2inod.c, pc_dos2inode)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/***************************************************************************
PC_DOS2INODE - Convert a dos disk entry to an in memory inode.
Description
Take the data from pbuff which is a raw disk directory entry and copy
it to the inode at pdir. The data goes from INTEL byte ordering to
native during the transfer.
Returns
Nothing
****************************************************************************/
/* Convert a dos inode to in mem form. */
void pc_dos2inode (FINODE *pdir, DOSINODE *pbuff) /*__fn__*/
{
copybuff(&pdir->fname[0],&pbuff->fname[0],8); /*X*/
copybuff(&pdir->fext[0],&pbuff->fext[0],3); /*X*/
pdir->fattribute = pbuff->fattribute; /*X*/
#if (FAT32)
copybuff(&pdir->resarea[0],&pbuff->resarea[0], 8); /*X*/
#else
copybuff(&pdir->resarea[0],&pbuff->resarea[0], 10); /*X*/
#endif
#if (!KS_LITTLE_ENDIAN)
pdir->ftime = to_WORD((byte *) &pbuff->ftime); /*X*/
pdir->fdate = to_WORD((byte *) &pbuff->fdate); /*X*/
#if (FAT32)
pdir->fclusterhi = to_WORD((byte *) &pbuff->fclusterhi); /*X*/
#endif
pdir->fcluster = to_WORD((byte *) &pbuff->fcluster); /*X*/
pdir->fsize = to_DWORD((byte *) &pbuff->fsize); /*X*/
#else
pdir->ftime = pbuff->ftime; /*X*/
pdir->fdate = pbuff->fdate; /*X*/
#if (FAT32)
pdir->fclusterhi = pbuff->fclusterhi; /*X*/
#endif
pdir->fcluster = pbuff->fcluster; /*X*/
pdir->fsize = pbuff->fsize; /*X*/
#endif
}
RTFS_FILE(initinod.c, pc_init_inode)
#ifndef __PCDISK__ /* This allows us to build the lib with subroutines split */
#include <pcdisk.h>
#endif
/**************************************************************************
PC_INIT_INODE - Load an in memory inode up with user supplied values.
Description
Take an uninitialized inode (pdir) and fill in some fields. No other
processing is done. This routine simply copies the arguments into the
FINODE structure.
Note: filename & fileext do not need null termination.
Returns
Nothing
****************************************************************************/
#if (RTFS_WRITE)
/* Load an in memory inode up with user supplied values */
void pc_init_inode(FINODE *pdir, KS_CONSTANT char *filename, /*__fn__*/
KS_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -