📄 dosfslib.c
字号:
#endif /* _BYTE_ORDER == _BIG_ENDIAN *//* Macros to set and get inode numbers for DOS files (used by NFS) */ /* Get a cluster number from an inode # */#define INODE_TO_CLUSTER(x) ((x) & 0x0000ffff) /* Get a generation number from an inode # */#define INODE_TO_GENERATION(x) (((x) >> 16) & 0x0000ffff) /* Get a generation number from a dir entry */#define GENERATION_GET(pDirEnt) (*((int *) & ((pDirEnt)->dosde_reserved)) \ & 0x0000ffff) /* Set a generation number for a dir entry */#define GENERATION_SET(pDirEnt, newVal) (*((int *) ((pDirEnt)->dosde_reserved))\ = ((newVal) & 0x0000ffff))/* to turn off warnings related to local implementation of malloc() etc. */#define malloc malloc_lfn#define calloc calloc_lfn#define free free_lfn/* DATA STRUCTURES *//* dosFs file descriptor */typedef struct /* DOS_FILE_DESC */ { NODE dosfd_node; /* linked list node info */ SEM_ID dosfd_semId; /* semaphore for this file descriptor */ short dosfd_status; /* file descriptor status (see below) */ DOS_VOL_DESC *dosfd_vdptr; /* ptr to dosFs volume descriptor */ int dosfd_cluster; /* number of first cluster in file */ short dosfd_mode; /* mode: O_RDONLY, O_WRONLY, O_RDWR */ DOS_DIR_ENT *dosfd_pDirEnt; /* ptr to dir entry for this file */ UINT dosfd_curptr; /* file byte ptr of I/O buffer byte 0 */ UINT dosfd_newptr; /* file byte ptr for new read/writes */ UINT dosfd_endptr; /* file byte ptr to end of file */ BOOL dosfd_rawMode; /* TRUE = Fd describes raw disk */ BOOL dosfd_contig; /* TRUE = contiguous file */ BOOL dosfd_modified; /* TRUE = buffer has been modified */ BOOL dosfd_changed; /* TRUE = file modified while open */ char *dosfd_buffer; /* pointer to read/write buffer area */ int dosfd_bufClust; /* number of cluster in I/O buffer */ int dosfd_bufSec; /* number of sector in buffer (root) */ } DOS_FILE_DESC;/* File descriptor status values */#define DOSFD_AVAILABLE -1 /* file descriptor available */#define DOSFD_IN_USE 0 /* file descriptor in-use */#define DOSFD_OBSOLETE 1 /* file descriptor obsolete */#define DOSFD_DELETED 2 /* file or dir was deleted while open *//* GLOBALS */int dosFsDrvNum = ERROR; /* driver number assigned to dosFsLib */char *dosFsSysId = "VXDOS4.0"; /* ID put in boot sector during formatting */char *dosFsExtSysId = "VXEXT1.0"; /* ID string if using extended names */ /* default mutex options */int dosFsVolMutexOptions = (SEM_Q_PRIORITY | SEM_DELETE_SAFE);int dosFsFdListMutexOptions = (SEM_Q_PRIORITY | SEM_DELETE_SAFE);int dosFsFdMutexOptions = (SEM_Q_PRIORITY | SEM_DELETE_SAFE);int dosFsUserId = 65534; /* owner id for files */int dosFsGroupId = 65534;int dosFsFileMode = DOS_DEFAULT_MODE;int dosFsHashTblSize = DOS_DEFAULT_HASH_SIZE; /* size of hashtable */int dosFsClustInitBytesMax = 0x4000; /* max buffer during clustInit*//* The following are used in dosFsLib's internal memory management. * dosFsMemPartIdOptions is used to initialize the error handling * strategy employed by memPartLib. dosFsMemPartInitSize sets the * starting size of the dosFs memory pool. dosFsMemPartGrowSize is used * to set the minimum size dosFs will grow the pool by when allocation * errors occur. Both dosFsMemPartInitSize and dosFsMemPartGrowSize are * adjusted for memPartLib internal overhead. The global dosFsMemPartCap * is used to limit how large dosFsMemPart is alowed to grow, in bytes. * -1 means no cap limit. */PART_ID dosFsMemPartId = NULL ; /* where to get memory */UINT dosFsMemPartIdOptions = MEM_BLOCK_ERROR_LOG_FLAG; /* SPR22406 */ /* only log free errors */int dosFsMemPartInitSize = 8*1024; /* start with 8 k */int dosFsMemPartGrowSize = 4 * 1024; /* add this on failures */UINT dosFsMemPartCap = -1; /* no cap *//* LOCALS */LOCAL FUNCPTR dosDateTimeFunc = NULL; /* user's date/time routine */LOCAL LIST dosFsFdActiveList; /* linked list of in-use Fd's */LOCAL LIST dosFsFdFreeList; /* linked list of avail. Fd's */LOCAL SEM_ID dosFsFdSemId; /* file descr list semaphore */LOCAL UINT dosFsMkfsOptions = DEFAULT_OPTIONS; /* options to use during mkfs */LOCAL UINT dosFsDevInitOptions = DEFAULT_OPTIONS; /* options during devInit */LOCAL char *pDotPadded = DOT_PADDED;LOCAL char *pDotDotPadded = DOTDOT_PADDED;LOCAL DOS_DATE_TIME dosFsDateTime = { 1980, /* year, default = 1980 */ 1, /* month, default = 1 (Jan.) */ 1, /* day, default = 1 */ 0, /* hour, default is 0 */ 0, /* minute, default is 0 */ 0 /* second, default is 0 */ };/* forward LOCAL functions */LOCAL STATUS dosFsClose (DOS_FILE_DESC *pDosFd);LOCAL int dosFsClustAdd (DOS_VOL_DESC *vdptr, int curClust);LOCAL void dosFsClustChainFree (DOS_VOL_DESC *vdptr, int cluster);LOCAL int dosFsClustContigCnt (DOS_VOL_DESC *vdptr, int startClust);LOCAL int dosFsClustContigFind (DOS_VOL_DESC *vdptr, int totalClusts, int initClust);LOCAL int dosFsClustContigMax (DOS_VOL_DESC *vdptr, UINT *pCount,int initClust);LOCAL int dosFsClustFind (DOS_FILE_DESC *pDosFd, int startClust, int clustOffset, BOOL doAlloc, BOOL doInit);LOCAL void dosFsClustFree (DOS_VOL_DESC *vdptr, int cluster);LOCAL int dosFsClustGet (DOS_VOL_DESC *vdptr, int curClust);LOCAL STATUS dosFsClustInit (DOS_VOL_DESC * vdptr, int startClust, int numClusts);LOCAL int dosFsClustNew (DOS_FILE_DESC *pDosFd, int access);LOCAL int dosFsClustNext (DOS_VOL_DESC *vdptr, int cluster);LOCAL STATUS dosFsClustRd (DOS_VOL_DESC *vdptr, int startClust, int numClusts, char *pBuf);LOCAL STATUS dosFsClustWrt (DOS_VOL_DESC *vdptr, int startClust, int numClusts, char *pBuf);LOCAL DOS_FILE_DESC *dosFsCreate (DOS_VOL_DESC *vdptr, char *fullName, int flags);LOCAL int dosFsDate (int year, int month, int day);LOCAL void dosFsDateTimeFill (DOS_DIR_ENT *pDirEnt);LOCAL STATUS dosFsDelete (DOS_VOL_DESC *vdptr, char *name);LOCAL BOOL dosFsFileCmp (DOS_DIR_ENT * entry1, DOS_DIR_ENT * entry2);LOCAL int dosFsInodeHash (int elements, DOS_DIR_ENT * pDirEnt, int seed);LOCAL DOS_FILE_DESC *dosFsDirCreate (DOS_VOL_DESC *vdptr, char *name);LOCAL STATUS dosFsDirEntAdd (DOS_VOL_DESC *vdptr, DOS_DIR_ENT *pNewEnt, DOS_DIR_ENT *pParent);LOCAL STATUS dosFsDirEntInit (DOS_DIR_ENT *pDirEnt, char *name, int clustNum, UINT8 attrib, BOOL longNames, BOOL lowerCase);LOCAL STATUS dosFsDirFlush (DOS_VOL_DESC *vdptr, DOS_DIR_ENT *pDir);LOCAL STATUS dosFsDirFree (DOS_VOL_DESC *vdptr, DOS_DIR_ENT *pDir);LOCAL STATUS dosFsDirLoad (DOS_VOL_DESC *vdptr, DOS_DIR_ENT *pDir);LOCAL DOS_DIR_ENT *dosFsDirMake (DOS_VOL_DESC *vdptr, char *name, BOOL nameExpanded);LOCAL STATUS dosFsDirRead (DOS_FILE_DESC *pDosFd, DIR *pDir);LOCAL void dosFsDiskEntryGet (DOS_DISK_DIR_ENT *pDiskEnt, DOS_DIR_ENT *pDirEnt, BOOL longNames);LOCAL void dosFsDiskEntryPut (DOS_DIR_ENT *pDirEnt, DOS_DISK_DIR_ENT *pDiskEnt, BOOL longNames);LOCAL DOS_DIR_ENT *dosFsEntryFind (DOS_VOL_DESC *vdptr, char *name, DOS_DIR_ENT *pParent);LOCAL int dosFsFatEntGet (DOS_VOL_DESC *vdptr, int cluster);LOCAL void dosFsFatEntPut (DOS_VOL_DESC *vdptr, int cluster, int value);LOCAL STATUS dosFsFatFlush (DOS_VOL_DESC *vdptr);LOCAL STATUS dosFsFatRd (DOS_VOL_DESC *vdptr);LOCAL void dosFsFdFree (DOS_FILE_DESC *pDosFd);LOCAL DOS_FILE_DESC *dosFsFdGet (void);LOCAL STATUS dosFsFileAttribSet (DOS_FILE_DESC *pDosFd, UINT8 newAttrib);LOCAL STATUS dosFsFileContigAlloc (DOS_FILE_DESC *pDosFd, int reqBytes);LOCAL DOS_DIR_ENT *dosFsFileCreate (DOS_VOL_DESC *vdptr, DOS_FILE_DESC *pDosFd, char *fullName);LOCAL STATUS dosFsFileDelete (DOS_VOL_DESC *vdptr, char *name);LOCAL DOS_DIR_ENT *dosFsFileFind (DOS_VOL_DESC *vdptr, char *pathName);LOCAL STATUS dosFsFileFlush (DOS_FILE_DESC *pDosFd);LOCAL int dosFsFileRead (DOS_FILE_DESC *pDosFd, char *pBuf, int maxBytes);LOCAL STATUS dosFsFileStatGet (DOS_FILE_DESC *pDosFd, struct stat *pStat);LOCAL STATUS dosFsFSStatGet (DOS_FILE_DESC *pDosFd, struct statfs *pStat);LOCAL STATUS dosFsFileTrunc (DOS_FILE_DESC *pDosFd, int newLength);LOCAL STATUS dosFsFlush (DOS_FILE_DESC *pDosFd);LOCAL UINT dosFsFreeCountGet (DOS_VOL_DESC *vdptr);LOCAL STATUS dosFsIoctl (DOS_FILE_DESC *pDosFd, int function, int arg);LOCAL STATUS dosFsName (char *fullName, UINT8 *nameOnly, UINT8 *extOnly, BOOL longNames, BOOL lowerCase);LOCAL void dosFsNameGet (char *pName, char *nameBuf, BOOL longNames);LOCAL DOS_FILE_DESC *dosFsOpen (DOS_VOL_DESC *vdptr, char *name, int flags, int mode);LOCAL int dosFsRead (DOS_FILE_DESC *pDosFd, char *pBuf, int maxBytes);LOCAL STATUS dosFsRename (DOS_FILE_DESC *pDosFd, char *newName);LOCAL STATUS dosFsReset (DOS_VOL_DESC *vdptr);LOCAL STATUS dosFsSecRd (DOS_VOL_DESC *vdptr, int startSec, UINT numSecs, char *pBuf);LOCAL STATUS dosFsSecWrt (DOS_VOL_DESC *vdptr, int startSec, UINT numSecs, char *pBuf);LOCAL STATUS dosFsSeek (DOS_FILE_DESC *pDosFd, int position);LOCAL STATUS dosFsSync (DOS_FILE_DESC *pDosFd);LOCAL int dosFsTime (int hour, int minute, int second);LOCAL time_t dosFsTimeDosToAnsi (USHORT dosTime, USHORT dosDate);LOCAL USHORT dosFsTimeAnsiToDos (time_t ansiTime, USHORT * dosTime, USHORT * dosDate);LOCAL void dosFsParentTimeIncrement (DOS_DIR_ENT * pDirEnt);LOCAL STATUS dosFsVolCheck (DOS_VOL_DESC *vdptr, BOOL doMount);LOCAL void dosFsVolDescFill (DOS_VOL_DESC *vdptr);LOCAL STATUS dosFsVolFlush (DOS_VOL_DESC *vdptr);LOCAL STATUS dosFsVolInit (DOS_VOL_DESC *vdptr);LOCAL DOS_DIR_ENT *dosFsVolLabelFind (DOS_VOL_DESC *vdptr);LOCAL STATUS dosFsVolLabelGet (DOS_VOL_DESC *vdptr, char *pBuf);LOCAL STATUS dosFsVolLabelSet (DOS_VOL_DESC *vdptr, char *pString);LOCAL STATUS dosFsVolMount (DOS_VOL_DESC *vdptr);LOCAL int dosFsWhere (DOS_FILE_DESC *pDosFd);LOCAL int dosFsWrite (DOS_FILE_DESC *pDosFd, char *pBuf, int maxBytes);LOCAL DOS_DIR_ENT * dosFsFindByInode (DOS_VOL_DESC * vdptr, DOS_DIR_ENT * pDir, ULONG inode);LOCAL STATUS dosFsDirentToStr (DOS_DIR_ENT * pDir, DOS_VOL_DESC * vdptr, char * fileName);LOCAL int dosFsGenerationGet (DOS_VOL_DESC * vdptr);/********************************************************************************* malloc_lfn - local substitute for this ANSI function** This local function is substantially the same as its ANSI counterpart* except that it uses a private memory partition to manage its memory* needs, in order to minimize fragmentation.* If the private partition does not have sufficient free memory,* then additional memory will be added into this partition from* the general system partition.**/LOCAL void * malloc_lfn(size_t size ) { void * ptr ; size_t addSize ; /* mem part mutex is needed to avoid race condition */ semTake (&dosFsMemPartId->sem, WAIT_FOREVER); /* spr22406 */ /* allocated, test for error and handle error - spr 22406 */ if ( ((ptr = memPartAlloc( dosFsMemPartId, size )) == NULL ) && ((UINT)( (int)(dosFsMemPartId->totalWords * 2)) < (UINT) (dosFsMemPartCap)) ) { /* Add more memory to private partition; alloc from * sysMemPool, add to ours, and handle errors. */ addSize = max( size + 64, dosFsMemPartGrowSize + 64 ); ptr = memPartAlloc( memSysPartId, addSize ); if( ptr != NULL ) { if( memPartAddToPool( dosFsMemPartId, ptr, addSize ) != ERROR ) { if ((ptr = memPartAlloc( dosFsMemPartId, size )) != NULL) errno = OK; } else { memPartFree( memSysPartId, ptr ); ptr = NULL ; } } } semGive (&dosFsMemPartId->sem); /* spr22406 */ return( ptr ); }/************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -