📄 dosfslib.c
字号:
/* dosFsLib.c - MS-DOS media-compatible file system library *//* Copyright 1984-1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------03l,16mar99,dgp doc: revised dosFsVolUnmount()/usrFdConfig() note (SPR 22068)03k,14mar99,jdi doc: removed refs to config.h and/or configAll.h (SPR 25663).03j,23feb99,dgp add note not to use dosFsVolUnmount() with usrFdConfig()03i,21feb99,jdi listed errnos.03h,30sep98,ms removed calls to DOS_DEBUG_MSG03g,29sep98,lrn checked-in md3's and previous SPR fixes into T2.0 view05f,17sep98,md3 spr22406: race in dosFs mem management, changed dosFsMemPartId options to MEM_BLOCK_ERROR_LOG_FLAG. Added dosFsMemPartIdOptions, dosFsMemPartInitSize, dosFsMemPartGrowSize, dosFsMemPartCap. Added calls to DOS_DEBUG_MSG, macro in dosFsLib.h.05e,11sep98,md3 spr22318: workAround for SPR22354, memPartFindMax.05d,31jul98,jkf official patch release fixes SPRs: 21475, 9465, 4061, 8721, 9057, 9224, 5282, and 8038. Also provides partial relief for SPRs 20683 and 9911, only for customers NOT NFS exporting the file system.05c,31jul98,jkf added (USHORT *)'s to dosFsVolMount() to fix SPR#9224.05b,17may98,lrn added local memory pool to fight fragmentation (SPR# 9465), fixed USWAB[SL] for aligned LE marchitecture (SPR#21475)05a,07oct97,wil added call to the block device ioctl routine with 'FIOFLUSH' command when an user issues a 'FIOFLUSH' or 'FIOSYNC' ioctl command to the DosFsLib (SPR 4061); fixed dosFsDevInit() makes memPartFree error (SPR 8721); fixed dosFsRename( dir -> dir ) (SPR 9057); fixed bug of 255 sectors-per-cluster (SPR 5282); fixed bug of double inserting of directory into hash. (SPR 8038)04f,05mar98,yp conditionalized reserved field usage to EXPORT_ENABLED so that it only happens if nfsd is active. This provides partial relief for SPRs 20683 and 9911, only for customers NOT exporting the FS. 04e,28feb97,tam fixed dosFsIoctl(FIOTIMESET) (SPR 8080).04d,21feb97,tam fixed dosFsRename() if renaming entry to another dir.(SPR 8038)04c,10oct96,kdl use UINT8 for secPerClust (SPR 4284); use localtime_r() in dosFsTimeAnsiToDos() (SPR 4443); use unsigned format in dosFsConfigShow() (SPR 4472); don't count deleted root entries (SPR 4624, 4873); handle large clusters in dosFsClustInit() (SPR 4672); maintain free clust count in vol desc (SPR 4708); initialize hash key name (SPR 4791); zero out alloc'd contig clusters (SPR 5030); replace hash entries during contig alloc (SPR 5520); mount disk during dosFsConfigGet() and ioctl(FIONFREE) (SPR 5598); check for single-cluster file during FIOTRUNC (SPR 5781); prevent search past end of fatModTbl in dosFsFatFlush() (SPR 7253).04b,16oct95,jdi doc: FIORENAME now supports renaming directories (SPR 4345).04a,06apr95,kdl fix memory leak in dosFsDirFlush (SPR 4203).03z,29mar95,kdl removed obsolete stat structure fields; made secPerClust unsigned for dosFsConfigInit(); changed dosFsMode to dosFsFileMode; remove root entry from hash tbl during mount; added DOS_OPT_LOWERCASE; keep dosFsClustInit from overrunning area to init; invalidate fd buffer if needed when truncating file.03y,20mar95,jdi doc addition about DOS_OPT_LOWERCASE as per kdl.03x,27feb95,jdi doc: format tweaks.03w,27feb95,jdi doc: changed dosFsMode to dosFsFileMode (doc only) (SPR 4085).03v,16jan95,rhp add info to doc of FIOTRUNC ioctl03u,10dec94,kdl add DOS_OPT_EXPORT to dosFsConfigShow() (SPR 3839).03t,05dec94,kdl modify subdirectory entries when renaming directory (SPR 3832).03s,03dec94,kdl fixed loss of subdir contents when renamed to new dir SPR 3832.03r,12nov94,kdl re-worked export initialization; added dosFsDevInitOptionsSet() made dosFsClustClustFind() only init new cluters if req'd; made FIONFREE code use stored count; free file buffer earlier during close; prevent useless reads in dosFsClustNew(); prevent dosFsVolInit() on write-protected disk; don't alloc 2 FAT buffers at once during VolInit; free cluster chain during failed alloc; allow extension in dir names; check for null BLK_DEV in dosFsMkfs(); free fd if dosFsCreate malloc fails; made fd position ptrs unsigned; allow std names starting with "."; removed DOS_MAX_SEC_SIZE; allow rename of directory.03m,27jul94,jmm directory names can now have extensions (spr 2263)03l,25jul94,jmm added check for NULL ptr to dosFsMkfs03q,08sep94,jmm final NFS changes03p,01jun94,jmm Roland's doc changes03o,19may94,jmm fixed file truncation problem03n,27apr94,jmm NFS documentation added; user-selected file modes added Parent directories now have timestamp incremented by 2 when files created or deleted03m,20apr94,jmm creating a file now increments the directory time03l,19apr94,jmm added support for NFS to dos file system03k,31aug93,kdl changed to use ANSI date/time format (SPR #2498).03j,31aug93,kdl added check for same device during dosFsDirMake() (SPR #2371).03i,30aug93,kdl changed FIOSYNC to re-read buffered cluster (SPR #2494).03h,13aug93,kdl clear root dir ptr if dosFsDirLoad() fails (SPR #1796).03g,08jul93,kdl fixed clobbering of data if root directory full (SPR #2104).03f,27feb93,kdl fixed bug which prevented files starting w/ "." (SPR #2023); improved checks for invalid disk when mounting (SPR #2043).03e,10feb93,jdi more documentation cleanup for 5.1.03d,08feb93,kdl consolidated option fields in DOS_VOL_CONFIG and DOS_VOL_DESC; added dosFsVolOptionsGet(), dosFsVolOptionsSet(), dosFsMkfsOptionsSet() (SPR #1871); made dosFsRename() delete existing file if renaming to another dir (SPR #1812); minor changes to dosFsConfigShow() display format.03c,01feb93,jdi documentation cleanup for 5.1. added third param to ioctl examples.03b,15oct92,kdl fixed incorrect semGive if trying to truncate read-only file (SPR #1649).03a,03oct92,kdl removed NOMANUAL for dosFsConfigGet(), dosFsConfigShow(); added free space and max contig space to dosFsConfigShow().02z,02oct92,srh added ioctl(FIOGETFL) to return file's open mode02y,30sep92,kdl removed check for 8086 jump instr in boot sector during mount.02x,16sep92,kdl made disk clusters be correctly read in for files opened O_WRONLY (SPR 963,1591); added S_dosFsLib_WRITE_ONLY.02w,07sep92,smb added blksize and blocks to the stat structure initialisation.02v,31aug92,kdl made FAT be flushed during FIOSYNC (SPR 1586); zero-out new file clusters when allocated due to seek (SPR 1478); don't return error if asked to read zero bytes (SPR 1544).02u,30jul92,kdl added missing semGive in dosFsDirRead() error handling.02t,22jul92,kdl changed from 4.0.2-style semaphores to mutexes; ansi cleanup.02s,18jul92,smb Changed errno.h to errnoLib.h.02r,30jun92,kdl allow specification of max available when allocating contiguous space; add ioctl(FIONCONTIG) to report max available contig space; allow file truncation via FIOTRUNC.02q,23jun92,kdl added long filename support; fixed dosFsVolInit to make sure entire FAT is written out; misc. error handling fixes.02p,26may92,rrr the tree shuffle02o,05may92,kdl restored 02m changes clobbered by 02n checkin; fixed mod hist.02n,05may92,kdl added selective FAT sector flushing.02m,22apr92,yao changed BYTE_ORDER to _BYTE_ORDER, BIG/LITTLE_ENDIAN to _BIG/LITTLE_ENDIAN. changed if CPUs to if _DYNAMIC_BUS_SIZING.02l,10dec91,gae added includes for ANSI.02k,19nov91,rrr shut up some ansi warnings.02j,15oct91,caf added MC68000 and MC68010 to USWAB category.02i,10oct91,rrr fixed syntax error!!!!!!!!!!02h,09oct91,ajm placed mips into USWAB catagory, was just SPARC, and made line 7120 in dosFsVolMount USWAB as it should be02g,04oct91,rrr passed through the ansification filter -changed functions to ansi style -changed includes to have absolute path from h/ -fixed #else and #endif -changed TINY and UTINY to INT8 and UINT8 -changed READ, WRITE and UPDATE to O_RDONLY O_WRONLY and ... -changed VOID to void -changed copyright notice02f,24jul91,jcc fixed byte-swapping macros for little endian machines.02e,20jul91,del added USAWB macros as per ajm for MIPS/SPARC. Added little endian byte swapping macros. Integrated kdl's first pass at type casting structure elements.02d,13jun91,kdl made memory be freed properly when deleting directory.02c,30may91,wmd enabled byte swapping macros for SPARC.02b,22may91,jdi documentation tweaks.02a,26apr91,hdn added defines and macros for TRON architecture.01z,05apr91,jdi documentation -- removed header parens and x-ref numbers; doc review by kdl.01y,25mar91,del added I960 defines for SWABx.01x,13feb91,jaa documented ioctl functions.01w,23jan91,kdl removed unnecessary \'s in printf formatting string.01v,23jan91,jaa documentation.01u,25oct90,kdl fixed problems with reading root dir larger than 1 sector; made dosFsConfigShow() display default device name if used.01t,19oct90,kdl changed dosFsConfigInit() to return STATUS; made changes to set/handle archive bit in attribute byte for volume label; added validation of config data during dosFsDevInit(); made dosFsMkfs() calculate cluster size; added dosFsConfigGet() and dosFsConfigShow(), both NOMANUAL.01s,18sep90,kdl removed blank lines after mod history, for mangen.01r,10aug90,kdl added forward declarations for functions returning void.01q,09aug90,kdl changed name from msdosLib to dosFsLib.01p,24jul90,kdl made error handling in msdosDevInit call iosDevDelete.01o,19jul90,kdl mangen fixes.01n,19jul90,kdl fixed possible null pointer problems in msdosDevInit.01m,19jul90,kdl made msdosDevInit mount disk if no volume configuration given.01l,12jul90,kdl made root dir be read from disk when listing dir; added BLK_DEV statusChk routine hook.01k,26jun90,jcf changed semTake () calling sequeunce to clean up lint.01j,22jun90,kdl added msdosConfigInit; documentation clean-up.01i,14jun90,kdl made msdosCreate ignore only file-not-found error when deleting existing file. Added FIOUNMOUNT.01h,10may90,kdl fixed msdosFdFree and msdosInit to set cluster field to NONE for free Fd's; fixed problem in linkage for first root entry; made various routines use pathCondense to avoid ".." problems; added S_msdosLib_BAD_SEEK.01g,07may90,kdl added POSIX directory handling, added BLK_DEV fields (bd_mode and bd_readyChanged), fixed FIONFREE, fixed FIOSEEK, lint.01f,03apr90,kdl made msdosRead read all requested bytes, made FIOFLUSH and FIOSYNC the same, pathParse changes.01e,23mar90,kdl lint, changed BLK_DEV field names, made msdosMkfs calculate FAT size.01d,20mar90,kdl added new driver scheme, DOS 4.0 compatibility, time routine hook, direct I/O for large transfers, file descriptor locking.01c,20feb90,kdl created autoSync and changeNoWarn options to reduce disk I/O, made ready-change internal, added support for contiguous files.01b,07nov89,kdl misc. fixes and cleanup01a,04oct89,kdl written*//*INTERNAL: MS-DOS is a registered trademark of Microsoft Corporation.DESCRIPTIONThis library provides services for file-oriented device drivers to use theMS-DOS\(rg file standard. This module takes care of all necessarybuffering, directory maintenance, and file system details.USING THIS LIBRARYThe various routines provided by the VxWorks DOS file system (dosFs) may beseparated into three broad groups: general initialization, deviceinitialization, and file system operation.The dosFsInit() routine is the principal initialization function; it needonly be called once, regardless of how many dosFs devices are to be used. Inaddition, dosFsDateTimeInstall() (if used) will typically be called onlyonce, prior to performing any actual file operations, to install auser-supplied routine which provides the current date and time.Other dosFs functions are used for device initialization. For each dosFsdevice, either dosFsDevInit() or dosFsMkfs() must be called to install thedevice and define its configuration. The dosFsConfigInit() routine isprovided to easily initialize the data structure used during deviceinitialization; however, its use is optional.Several routines are provided to inform the file system of changesin the system environment. The dosFsDateSet() and dosFsTimeSet() routinesare used to set the current date and time; these are normally used only ifno user routine has been installed via dosFsDateTimeInstall(). ThedosFsModeChange() call may be used to modify the readability orwritability of a particular device. The dosFsReadyChange() routine isused to inform the file system that a disk may have been swapped, and thatthe next disk operation should first remount the disk. Finally,dosFsVolUnmount() informs the file system that a particular device shouldbe synchronized and unmounted, generally in preparation for a diskchange.More detailed information on all of these routines is discussed in thefollowing sections.INITIALIZING DOSFSLIBBefore any other routines in dosFsLib can be used, the routine dosFsInit() mustbe called to initialize this library. This call specifies themaximum number of dosFs files that can be open simultaneously.Attempts to open more dosFs files than the specified maximum will resultin errors from open() and creat().This initialization is enabled when the configuration macro INCLUDE_DOSFS isdefined; dosFsInit() is then called from the root task, usrRoot(),in usrConfig.c.DEFINING A DOSFS DEVICETo use this library for a particular device, the device descriptorstructure used by the device driver must contain, as the very first item,a block device description structure (BLK_DEV). This must be initializedbefore calling dosFsDevInit(). In the BLK_DEV structure, the driverincludes the addresses of five routines which it must supply: one thatreads one or more sectors, one that writes one or more sectors, one thatperforms I/O control on the device (using ioctl()), one that checks thestatus of the device, and one that resets the device. These routines aredescribed below. The BLK_DEV structure also contains fields whichdescribe the physical configuration of the device. For more informationabout defining block devices, see the .I "VxWorks Programmer's Guide: I/O System."The dosFsDevInit() routine associates a device with the dosFsLibfunctions. It expects three parameters:.IP "(1)" 4A pointer to a name string, to be used to identify the device.This will be part of the pathname for I/O operations which operate on thedevice. This name will appear in the I/O system device table, which may bedisplayed using the iosDevShow() routine..IP "(2)"A pointer to the BLK_DEV structure which describes the device and contains theaddresses of the five required functions. The fields in this structuremust have been initialized before the call to dosFsDevInit()..IP "(3)"A pointer to a volume configuration structure (DOS_VOL_CONFIG). Thisstructure contains configuration data for the volume which are specific tothe dosFs file system. (See "Changes in Volume Configuration", below, for moreinformation.) The fields in this structure must have been initialized beforethe call to dosFsDevInit(). The DOS_VOL_CONFIG structure may be initializedby using the dosFsConfigInit() routine..LPAs an example:.CS dosFsDevInit ( char *volName, /@ name to be used for volume @/ BLK_DEV *pBlkDev, /@ pointer to device descriptor @/ DOS_VOL_CONFIG *pVolConfig /@ pointer to vol config data @/ ).CE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -