⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dosfslib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 5 页
字号:
IOCTL FUNCTIONSThe dosFs file system supports the following ioctl() functions.  Thefunctions listed are defined in the header ioLib.h.  Unless statedotherwise, the file descriptor used for these functions may be any filedescriptor which is opened to a file or directory on the volume or to the volume itself.There are some ioctl() commands, that expect a 32-bit integer result(FIONFREE, FIOWHERE, etc.).However, disks and files with are grater than 4GB are supported.In order to solve this problem, new ioctl() functions have been addedto support 64-bit integer results.They have the same name as basic functions, but with suffix .I 64,namely: FIONFREE64, FIOWHERE64 and so on. These commandsexpect a pointer to a 64-bit integer, i.e.:.CSlong long *arg ;.CEas the 3rd argument to the ioctl() function.If a value which is requested with a 32-bit ioctl() command istoo large to be represented in the 32-bit variable, ioctl() will returnERROR, and <errno> will be set to S_dosFsLib_32BIT_OVERFLOW..iP "FIODISKINIT"Reinitializes a DOS file system on the disk volume.This function calls dosFsVolFormat() to format the volume,so dosFsFmtLib must be installed for this to work.Third argument of ioctl() is passed as argument <opt> todosFsVolFormat() routine.This routine does not perform a low level format,the physical media is expected to be already formatted.If DOS file system device has not been created yet for a particular device,only direct call to dosFsVolFormat() can be used..CS    fd = open ("DEV1:", O_WRONLY);    status = ioctl (fd, FIODISKINIT, DOS_OPT_BLANK);.CE.iP "FIODISKCHANGE"Announces a media change. No buffers flushing is performed.This function may be called from interrupt level:.CS    status = ioctl (fd, FIODISKCHANGE, 0);.CE.iP "FIOUNMOUNT"Unmounts a disk volume.  It performs the same function as dosFsVolUnmount().This function must not be called from interrupt level:.CS    status = ioctl (fd, FIOUNMOUNT, 0);.CE.iP "FIOGETNAME"Gets the file name of the file descriptor and copies it to the buffer <nameBuf>.Note that <nameBuf> must be large enough to contain the largest possiblepath name, which requires at least 256 bytes..CS    status = ioctl (fd, FIOGETNAME, &nameBuf );.CE.iP "FIORENAME"Renames the file or directory to the string <newname>:.CS    fd = open( "oldname", O_RDONLY, 0 );    status = ioctl (fd, FIORENAME, "newname");.CE.iP "FIOSEEK"Sets the current byte offset in the file to the position specified by<newOffset>. This function supports offsets in 32-bit value range.Use FIOSEEK64 for larger position values:.CS    status = ioctl (fd, FIOSEEK, newOffset);.CE.iP "FIOSEEK64"Sets the current byte offset in the file to the position specified by<newOffset>. This function supports offsets in 64-bit value range:.CS    long long	newOffset;    status = ioctl (fd, FIOSEEK64, (int) & newOffset);.CE.iP "FIOWHERE"Returns the current byte position in the file.  This is thebyte offset ofthe next byte to be read or written.  This function returns a 32-bit value.It takes no additional argument:.CS    position = ioctl (fd, FIOWHERE, 0);.CE.iP "FIOWHERE64"Returns the current byte position in the file.  This is thebyte offset ofthe next byte to be read or written.  This function returns a 64-bitvalue in <position>:.CS    long long	position;    status = ioctl (fd, FIOWHERE64, (int) & position);.CE.iP "FIOFLUSH"Flushes disk cache buffers.  It guarantees that any output that hasbeen requested is actually written to the device:.CS    status = ioctl (fd, FIOFLUSH, 0);.CE.iP "FIOSYNC"Flushes and invalidates disk cache buffers.  It guaranteesthat any output that hasbeen requested is actually written to the device and a subsequent I/O operation will get data directly from the physical medium:.CS    status = ioctl (fd, FIOSYNC, 0);.CE.iP "FIOTRUNC"Truncates the specified file's length to <newLength> bytes.  Any diskclusters which had been allocated to the file but are now unused aredeallocated, and the directory entry for the file is updated to reflectthe new length.  Only regular files may be truncated; attempts to useFIOTRUNC on directories will return an error.FIOTRUNC may only be used to make files shorter; attempting to specifya <newLength> larger than the current size of the file produces anerror (setting errno to S_dosFsLib_INVALID_NUMBER_OF_BYTES)..CS    status = ioctl (fd, FIOTRUNC, newLength);.CE.iP "FIOTRUNC64"Similar to FIOTRUNC, but can be used for files lager, than 4GB..CS    long long newLength = .....;    status = ioctl (fd, FIOTRUNC, (int) & newLength);.CE  .iP "FIONREAD"Copies to <unreadCount> the number of unread bytes in the file:.CS    unsigned long unreadCount;    status = ioctl (fd, FIONREAD, &unreadCount);.CE.iP "FIONREAD64"Copies to <unreadCount> the number of unread bytes in the file.This function returns a 64-bit integer value:.CS    long long unreadCount;    status = ioctl (fd, FIONREAD64, &unreadCount);.CE.iP "FIONFREE"Copies to <freeCount> the amount of free space, in bytes, on the volume:.CS   unsigned long freeCount;   status = ioctl (fd, FIONFREE, &freeCount);.CE.iP "FIONFREE64"Copies to <freeCount> the amount of free space, in bytes, on the volume.This function can return value in 64-bit range:.CS   long long freeCount;   status = ioctl (fd, FIONFREE64, &freeCount);.CE.iP "FIOMKDIR"Creates a new directory with the name specified as <dirName>:.CS    status = ioctl (fd, FIOMKDIR, "dirName");.CE.iP "FIORMDIR"Removes the directory whose name is specified as <dirName>:.CS    status = ioctl (fd, FIORMDIR, "dirName");.CE.iP "FIOLABELGET"Gets the volume label (located in root directory) and copies the string to<labelBuffer>. If the label contains DOS_VOL_LABEL_LEN significantcharacters, resulting string  is not NULL terminated:.CS    char	labelBuffer [DOS_VOL_LABEL_LEN];    status = ioctl (fd, FIOLABELGET, (int)labelBuffer);.CE.iP "FIOLABELSET"Sets the volume label to the string specified as <newLabel>.  The string mayconsist of up to eleven ASCII characters:.CS    status = ioctl (fd, FIOLABELSET, (int)"newLabel");.CE.iP "FIOATTRIBSET"Sets the file attribute byte in the DOS directory entry to the new value<newAttrib>.  The file descriptor refers to the file whose entry is to be modified:.CS    status = ioctl (fd, FIOATTRIBSET, newAttrib);.CE.iP "FIOCONTIG"Allocates contiguous disk space for a file or directory.  The number ofbytes of requested space is specified in <bytesRequested>.  In general,contiguous space should be allocated immediately after the file iscreated:.CS    status = ioctl (fd, FIOCONTIG, bytesRequested);.CE.iP "FIOCONTIG64"Allocates contiguous disk space for a file or directory.  The number ofbytes of requested space is specified in <bytesRequested>.  In general,contiguous space should be allocated immediately after the file iscreated. This function accepts a 64-bit value:.CS    long long bytesRequested;    status = ioctl (fd, FIOCONTIG64, &bytesRequested);.CE.iP "FIONCONTIG"Copies to <maxContigBytes> the size of the largest contiguous free space, in bytes, on the volume:.CS    status = ioctl (fd, FIONCONTIG, &maxContigBytes);.CE.iP "FIONCONTIG64"Copies to <maxContigBytes> the size of the largest contiguous free space,in bytes, on the volume. This function returns a 64-bit value:.CS    long long maxContigBytes;    status = ioctl (fd, FIONCONTIG64, &maxContigBytes);.CE.iP "FIOREADDIR"Reads the next directory entry.  The argument <dirStruct> is a DIRdirectory descriptor.  Normally, the readdir() routine is used to read adirectory, rather than using the FIOREADDIR function directly.  See dirLib..CS    DIR dirStruct;    fd = open ("directory", O_RDONLY);    status = ioctl (fd, FIOREADDIR, &dirStruct);.CE.iP "FIOFSTATGET"Gets file status information (directory entry data).  The argument<statStruct> is a pointer to a stat structure that is filled with datadescribing the specified file.  Normally, the stat() or fstat() routine isused to obtain file information, rather than using the FIOFSTATGETfunction directly.  See dirLib..CS    struct stat statStruct;    fd = open ("file", O_RDONLY);    status = ioctl (fd, FIOFSTATGET, (int)&statStruct);.CE.iP "FIOTIMESET"Update time on a file.   <arg> shall be a pointer to a utimbuf structure, see utime.h.  If <arg> is value NULL, the current system time is used forboth actime and modtime members.  If <arg> is not NULL then the utimbuf structure members actime and modtime are used as passed.  If actime is zero value, the file access time is not updated (the operation is ignored).  If modtime is zero, the file modification time is not updated (the operation is ignored).   See also utime()..CS    struct utimbuf newTimeBuf;;    newTimeBuf.modtime = newTimeBuf.actime = fileNewTime;    fd = open ("file", O_RDONLY);    status = ioctl (fd, FIOTIMESET, (int)&newTimeBuf);.CE.iP "FIOCHKDSK"This function invokes the integral consistency checking.During the test, the file system will be blocked from application codeaccess, and will emit messages describing any inconsistencies found onthe disk, as well as some statistics, depending on the verbositylevel in the <flags> argument.Depending on the repair permission value in <flags> argument,the inconsistencies will be repaired, and changes written to diskor only reported.Argument <flags> should be composed of bitwise or-edverbosity level value and repair permission value.Possible repair levels are:.RS.iP "DOS_CHK_ONLY (1)"Only report errors, do not modify disk..iP "DOS_CHK_REPAIR (2)"Repair any errors found..LPPossible verbosity levels are:.iP "DOS_CHK_VERB_SILENT (0xff00)"Do not emit any messages, except errors encountered..iP "DOS_CHK_VERB_1 (0x0100)"Display some volume statistics when done testing, as well.iP "DOS_CHK_VERB_2 (0x0200)"In addition to the above option, display path of every file, while itis being checked. This option may significantly slow down the testprocess.  as errors encountered during the test..IP "NOTE"In environments with reduced RAM size check disk uses reservedFAT copy as temporary buffer, it can cause respectively longtime of execution on a slow CPU architectures...LP.RESee also the reference manual usrFsLib for the chkdsk() user levelutility which may be used to invoke the FIOCHKDSK ioctl().The volume root directory should be opened, and the resulting filedescriptor should be used:.CS    int fd = open (device_name, O_RDONLY, 0);    status = ioctl (fd, FIOCHKDSK, DOS_CHK_REPAIR | DOS_CHK_VERB_1);    close (fd);.CE.LPAny other ioctl() function codes are passed to the underlying.I CBIOmodules for handling.INCLUDE FILES: dosFsLib.hSEE ALSO:ioLib, iosLib, dirLib, usrFsLib, dcacheCbio, dpartCbio, dosFsFmtLib,dosChkLib.I "Microsoft MS-DOS Programmer's Reference"(Microsoft Press),.I "Advanced MS-DOS Programming"(Ray Duncan, Microsoft Press),.I "VxWorks Programmer's Guide: I/O System, Local File Systems"INTERNAL:Note:  To represent a backslash in documentation use "\e", not "\\".The double backslash sometimes works, but results may be unpredictable.*//* includes */#include "vxWorks.h"#include "stat.h"#include "time.h"#include "dirent.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "taskLib.h"#include "tickLib.h"#include "semLib.h"#include "logLib.h"#include "errnoLib.h"#include "private/semLibP.h"#include "memLib.h"#include "utime.h"#include "private/print64Lib.h"#include "private/dosFsLibP.h"#include "private/dosDirLibP.h"/* defines */#if FALSE#   undef FAT_ALLOC_ONE#   define FAT_ALLOC_ONE        (FAT_ALLOC | 8)#endif /* FALSE *//* macros */#undef DBG_MSG#undef ERR_MSG#undef NDEBUG#ifdef DEBUG#   undef LOCAL#   define LOCAL#   undef ERR_SET_SELF#   define ERR_SET_SELF#   define DBG_MSG( lvl, fmt, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8 )	\	{ if( (lvl) <= dosFsDebug )					\	    printErr( "%s : %d : " fmt,				\	               __FILE__, __LINE__, arg1,arg2,	\		       arg3,arg4,arg5,arg6,arg7,arg8 ); }#   define ERR_MSG( lvl, fmt, a1,a2,a3,a4,a5,a6 )		\        { logMsg( __FILE__ " : " fmt, (int)(a1), (int)(a2),	\		  (int)(a3), (int)(a4), (int)(a5), (int)(a6) ); }#else	/* NO DEBUG */#   define NDEBUG#   define DBG_MSG(lvl,fmt,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) 	{}#   define ERR_MSG( lvl, fmt, a1,a2,a3,a4,a5,a6 )		\	{ if( (lvl) <= dosFsDebug ) 				\            logMsg( __FILE__ " : " fmt, (int)(a1), (int)(a2),	\		  (int)(a3), (int)(a4), (int)(a5), (int)(a6) ); }#endif /* DEBUG */#ifdef ASSERT_SUSP#include "assertAltern.h"#else#include "assert.h"#endif /* ASSERT_SUSP */#ifdef ERR_SET_SELF#   define errnoSet( err ) errnoSetOut( __FILE__, __LINE__, #err, (err) )#endif /* ERR_SET_SELF *//* typedefs *//* globals */int	dosFsDrvNum = ERROR; /* dosFs number in vxWorks driver table */u_int	dosFsDebug = 1;/* handlers lists */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -