📄 cdromfslib.c
字号:
/* cdromFsLib.c - ISO 9660 CD-ROM read-only file system library *//* Copyright 1989-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------07o,05dec02,tkj cdromFs joliet code review changes.07n,30oct02,tkj 1. Fix failure of cdcompat on multi-extent files. 2. Move cdromFsVersion.h to target/h/private. 3. Make multi-session support conditional.07m,15oct02,tkj First release candiidate of the Joliet project. 1. Finish removing translation from Joliet to ASCII. 2. Fix endian bug in reading TOC from CD. 3. Make MODE_AUTO combination of directories conditional upon CDROMFS_MODE_AUTO_COMBINE_VOLUME_DESCRIPTORS. 4. Make ioctl() to get multi-session TOC conditional upon CDROMFS_MULTI_SESSION_ATAPI_IOCTL 5. Revise refgen output. Convert refgen to new mark-up style. 6. Change name of cdromFs ioct() defines07l,10oct02,tkj 1. Code cleanup: Remove debugging code, Improve refgen output. 2. cdromFsLib.h split into cdromFsLib.h and cdromFsLibP.h.07k,03oct02,tkj 1. Remove translation from Unicode to ASCII. 2. Fix SPR#79162 - It had a bug that showed up in llr() before. 3. Fix SPR#80396 - It was not fixed before.07j,01oct02,tkj Fix SPR#78416 Handles .. wrong. Accepts path xx/../yy even if xx does not exist.07i,17sep02,tkj 1. Add enhancement SPR#78709 Get volume descriptor. 2. Modify enhancement SPR#78687 Get version number.07h,28aug02,tkj Fix compilation problem with DEBUG off.07g,28aug02,tkj Changes since last ClearCase checkin 07c: Finished since 07b: Current status of Productize Joliet extensions project. Enhancements done in 07g (now): SPR#79162. Enhancements not done yet: SPR#78208, SPR#78687, SPR#78709. Bugs fixed in 07g (now): SPR#34659/SPR#34826, SPR#75766, SPR#80396, SPR#80424. Bugs fixed in 07b: SPR#32715, SPR#70072, SPR#78415, SPR#78452, SPR#78454, SPR#78455, SPR#78456. Bugs not fixed yet: SPR#78416.07f,21aug02,smz Solved bug regarding the recursive listing of a Joliet directory which is more then 3 blocks long. Not checked into ClearCase.07e,19aug02,tkj More work on SPR#78208 - Productice Joliet extensions. Not checked into ClearCase.07d,12aug02,smz Added cdromFsTocRead function for simulated reading of table of contents when the ioctl call to the block device driver fails. Not checked into ClearCase.07c,27jun02,tkj More work on SPR#78208 - Productice Joliet extensions.07b,26jun02,tkj Enchancememts: SPR#78208 - Productice Joliet extensions. Bug fixes: SPR#32715/SPR#34826, SPR#78415, SPR#78452, SPR#78454, SPR#78455, SPR#78456, SPR#79162. Bugs not fixed yet: SPR#34659, SPR#75766, SPR#78416, SPR#79162.07a,26jun02,tkj Checkin cdromFsLib Joliet extensions as received from Wind River Services in the Netherlands. It needs work to be productized.06c,19Mrz02,mbl added multisession for Joliet06b,07Mrz02,mbl remove all warnings and tested all Joliet functionalitys.06a,26Feb02,mbl added new functionality to support Joliet extensions.05a,03jun99,pfl fixed directory and file month entries (SPR# 26756)04r,15nov98,jdi added instructions on modifying BSP to include cdromFS.04e,14jul98,cn added prototype for cdromFsWrite().04d,10jul98,cn updated documentation, changed cdromFS to cdromFsLib (SPR# 21732). Also removed every reference to Rock Ridge extensions support (SPR# 21590). Moved cdromFsInit() to the beginning of the file.04c,08apr98,kbw made minor man page edits04b,30apr97,jdi doc: cleanup.04a,10apr97,dds SPR#7538: add CDROM file system support to vxWorks.03f,17jul96,rst productized for release.03e,25jun96,vld file was compiled with "Tornado". All warnings were fixed up.03c,25jun96,vld new functionality: uppercase names may be reached via case insensitive path string.03b,23jun96,leo the bug in cdromFsFixPos() was fixed up (type of second argument was changed to long).03a,23jun96,leo the bug in cdromFsFindFileInDir() was fixed up (the bug came from ASCI order, wwhere ';' > '.').02a,23jan96,vld the new interpretation of ISO_DIR_REC_EAR_LEN and ISO_PT_REC_EAR_LEN: it is assumed now that the length of EAR is counted in logical blocks. Data always starts from LB bound.01e,23jan96,vld the bug in cdromFsFixPos was fixed up01d,12oct95,rst FCS release, ported to 5.201c,03jul95,rst Beta release, code revew.01b,10apr95,rst alex, vlad total revision of the joined text01a,22feb95,rst initial version*//*DESCRIPTIONThis library defines cdromFsLib, a utility that lets you use standard POSIXI/O calls to read data from a CD-ROM, CD-R, or CD-RW formatted according tothe ISO 9660 standard file system.It provides access to CD file systems using any standardBLOCK_DEV structure (that is, a disk-type driver).The basic initialization sequence is similar to installing a DOS file systemon a SCSI device.1. Initialize the cdrom file system library(preferably in sysScsiConfig() in sysScsi.c):\cs cdromFsInit ();\ce2. Locate and create a SCSI physical device:\cs pPhysDev=scsiPhysDevCreate (pSysScsiCtrl,0,0,0,NONE,1,0,0);\ce3. Create a SCSI block device on the physical device:\cs pBlkDev = (SCSI_BLK_DEV *) scsiBlkDevCreate (pPhysDev, 0, 0);\ce4. Create a CD file system on the block device:\cs cdVolDesc = cdromFsDevCreate ("cdrom:", (BLK_DEV *) pBlkDev);\ceCall cdromFsDevCreate() once for each CD drive attached to your target.After the successful completion of cdromFsDevCreate(), the CDfile system will be available like any DOS file system, andyou can access data on the named CD device using open(), close(), read(),ioctl(), readdir(), and stat(). A write() always returns an error.The cdromFsLib utility supports multiple drives, concurrent access frommultiple tasks, and multiple open files.ISO 9660 FILE AND DIRECTORY NAMINGThe strict ISO 9660 specification allows only uppercase file namesconsisting of 8 characters plus a 3 character suffix.To accommodate users familiar with MS-DOS, cdromFsLib lets you use lowercasename arguments to access files with names consisting entirely of uppercasecharacters. Mixed-case file and directory names are accessible only if youspecify their exact case-correct names.JOLIET EXTENSIONS FILE AND DIRECTORY NAMINGThe Joliet extensions to the ISO 9660 specification are designed to handlelong file names up to 340 characters long.File names must be case correct. The above use of lowercase characters toaccess files named entirely with uppercase characters is not supported.cdromFs with Joliet extensions does not support Unicode file names. Thefile names on the CD are stored in 16 bit Unicode characters.However, they are converted to 8 bit characters inside cdromFs by droppingthe most significant byte of each 16 bit character.FILE AND DIRECTORY NAMING COMMON TO ISO 9660 AND THE JOLIET EXTENSIONSTo support multipleversions of the same file, the ISO 9660 specification also supports versionnumbers. When specifying a file name in an open() call, you can select thefile version by appending the file name with a semicolon (;) followed by adecimal number indicating the file version. If you omit the version number,cdromFsLib opens the latest version of the file.For the time being, cdromFsLib further accommodates MS-DOS users byallowing "\/" (backslash) instead of "/" in pathnames. However, the useof the backslash is discouraged because it may not be supported infuture versions of cdromFsLib.Finally, cdromFsLib uses an 8-bit clean implementation of ISO 9660. Thus,cdromFsLib is compatible with CDs using either Latin or Asian charactersin the file names.IOCTL CODES SUPPORTED\is\i `FIOGETNAME'Returns the file name for a specific file descriptor.\i `FIOLABELGET'Retrieves the volume label. This code can be used to verify that aparticular volume has been inserted into the drive.\i `FIOWHERE'Determines the current file position.\i `FIOWHERE64'Determines the current file position. This is the 64 bit version.\i `FIOSEEK'Changes the current file position.\i `FIOSEEK64'Changes the current file position. This is the 64 bit version.\i `FIONREAD'Tells you the number of bytes between the current location and the end ofthis file.\i `FIONREAD64'Tells you the number of bytes between the current location and the end ofthis file. This is the 64 bit version.\i `FIOREADDIR'Reads the next directory entry.\i `FIODISKCHANGE'Announces that a disk has been replaced (in case the block driver isnot able to provide this indication).\i `FIOUNMOUNT'Announces that the a disk has been removed (all currently open filedescriptors are invalidated).\i `FIOFSTATGET'Gets the file status information (directory entry data).\i `CDROMFS_DIR_MODE_SET'This is part of the Joliet extensions. It sets the directory mode to theioctl() arg value. That controls whether a file is opened with or withoutthe Joliet extensions. Settings MODE_ISO9660, MODE_JOLIET, and MODE_AUTOdo not use Joliet, use Joliet, or try opening the directory first withoutJoliet and then with Joliet, respectively.This ioctl() unmounts the file system. Thus any open file descriptors aremarked obsolete.\i `CDROMFS_DIR_MODE_GET'This is part of the Joliet extensions. It gets and returns the directorymode set by CDROMFS_DIR_MODE_SET.\i `CDROMFS_STRIP_SEMICOLON'This sets the readdir() strip semicolon setting to FALSE if arg is 0, andTRUE otherwise. If TRUE, readdir() removes the semicolon and followingversion number from the directory entries returned.\i `CDROMFS_GET_VOL_DESC'This returns the primary or supplementary volume descriptor by which thevolume is mouned in arg. arg must be type T_ISO_PVD_SVD_ID as defined incdromFsLib.h. The result is the volume descriptor adjusted for theendianness of the processor, not the raw volume descriptor from the CD.The result is directly usable by the processor. The result also includessome information not in the volume descriptor, for example which volumedescriptor is in-use.\ieINTERNALAdd the following to the \is list above, without the conditional or thelist start/stop, if the macro CDROMFS_MULTI_SESSION_SUPPORT is defined incdromFsLibP.h. Note, the issues explained in the comment in cdromFsLibP.hmust be resolved.\is\i `CDROMFS_SESSION_NUMBER_SET'This is part of multi-session support. CD-Rs and CD-RWs can be written inmultiple sessions, or all at once. If multiple sessions are used, eachsession updates the previous session. Only the changes from the previoussession are stored. Files that are not changed are reused, not storedagain. The last session on the disk gives the current state of the disk.The earlier sessions are normally not accessed. If accessed they giveearlier states of the disk.This ioctl() function sets which session is accessed. Normally the lastsession is accessed, and this ioctl() is not used. Sessions are numberedstarting with 1. Session value 100, i.e. DEFAULT_SESSION, means the lastsession on the CD.Multi-session support prefers that the physical disk driver support theioctl() function FIOREADTOCINFO 0xf8 to read the CD volume table ofcontents. If the disk driver does not support FIOCREADTOCINFO, cdromFsdetermines the CD volume table of contents itself. However, this is bothslower than asking the driver, and does not work for every combination ofCD drive and CD.This ioctl() unmounts the file system. Thus any open file descriptors aremarked obsolete.\i `CDROMFS_SESSION_NUMBER_GET'This is part of multi-session support. It gets and returns the sessionnumber set by CDROMFS_SESSION_NUMBER_SET.\i `CDROMFS_MAX_SESSION_NUMBER_GET'This is part of multi-session support. It gets and returns the maximumsession on the CD.\ieMODIFYING A BSP TO USE CDROMFS IN VXWORKS AE\ml\m 1.Add the component "INCLUDE_CDROMFS" to your kernel domain project. Thiswill bring in the CDROMFS library modules and initialize them.\m 2.Continue with step 3 underneath "Modify the definition of sysScsiInit() toinclude the following:" in section MODIFYING A BSP TO USE CDROMFS INVXWORKS.\meMODIFYING A BSP TO USE CDROMFS IN VXWORKSThe following example describes mounting cdromFS on a SCSI device.Edit your BSP's config.h to make the following changes:\ml\m 1.Insert the following macro definition:\cs #define INCLUDE_CDROMFS\ce\m 2.Change FALSE to TRUE in the section under the following comment:\cs /@ change FALSE to TRUE for SCSI interface @/\ce\meMake the following changes in sysScsi.c(or sysLib.c if your BSP has no sysScsi.c):\ml\m 1.Add the following declaration to the top of the file:\cs #ifdef INCLUDE_CDROMFS #include "cdromFsLib.h" STATUS cdromFsInit (void); #endif\ce\m 2.Modify the definition of sysScsiInit() to include the following:\cs #ifdef INCLUDE_CDROMFS cdromFsInit (); #endif\ceThe call to cdromFsInit() initializes cdromFS. This call mustbe made only once and must complete successfully before you cancall any other cdromFsLib routines, such as cdromFsDevCreate().Typically, you make the cdromFSInit() call at system startup.Because cdromFS is used with SCSI CD devices, it is naturalto call cdromFSInit() from within sysScsiInit().\m 3.Modify the definition of sysScsiConfig() (if included in your BSP)to include the following:\cs/@ configure a SCSI CDROM at busId 6, LUN = 0 @/#ifdef INCLUDE_CDROMFSif ((pSpd60 = scsiPhysDevCreate (pSysScsiCtrl, 6, 0, 0, NONE, 0, 0, 0)) == (SCSI_PHYS_DEV *) NULL) { SCSI_DEBUG_MSG ("sysScsiConfig: scsiPhysDevCreate failed for CDROM.\n", 0, 0, 0, 0, 0, 0); return (ERROR); }else if ((pSbdCd = scsiBlkDevCreate (pSpd60, 0, 0) ) == NULL) { SCSI_DEBUG_MSG ("sysScsiConfig: scsiBlkDevCreate failed for CDROM.\n", 0, 0, 0, 0, 0, 0); return (ERROR); }/@ * Create an instance of a CD device in the I/O system. * A block device must already have been created. Internally, * cdromFsDevCreate() calls iosDrvInstall(), which enters the * appropriate driver routines in the I/O driver table. @/if ((cdVolDesc = cdromFsDevCreate ("cdrom:", (BLK_DEV *) pSbdCd )) == NULL) { return (ERROR); }#endif /@ end of #ifdef INCLUDE_CDROMFS @/\ce\m 4.Before the definition of sysScsiConfig(), declare the followingglobal variables used in the above code fragment:\cs SCSI_PHYS_DEV *pSpd60; BLK_DEV *pSbdCd; CDROM_VOL_DESC_ID cdVolDesc;\ce\meThe main goal of the above code fragment is to call cdromFsDevCreate().As input, cdromFsDevCreate() expects a pointer to a block device.In the example above, the scsiPhysDevCreate() and scsiBlkDevCreate()calls set up a block device interface for a SCSI CD device.After the successful completion of cdromFsDevCreate(), the device called"cdrom" is accessible using the standard open(), close(), read(), ioctl(),readdir(), and stat() calls.INCLUDE FILES: cdromFsLib.hCAVEATSThe cdromFsLib utility does not support CD sets containing multiple disks.SEE ALSO: ioLib, ISO 9660 Specification, Joliet extension Specification*//* * Note: Only the following routines have man output: cdromFsInit(), * cdromFsVolConfigShow(), cdromFsVersionDisplay(), cdromFsDevCreate(), * cdromFsVersionNumGet(). *//* includes */#include <vxWorks.h>#include <ctype.h>#include <dirent.h>#include <errnoLib.h>#include <in.h>#include <iosLib.h>#include <memLib.h>#include <memPartLib.h> /* KHEAP_ALLOC, KHEAP_FREE */#include <netinet/in.h> /* htonl, ntohl */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sysLib.h>#include <usrLib.h>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -