1 /* 2 * Copyright 1999, Be Incorporated. All Rights Reserved. 3 * This file may be used under the terms of the Be Sample Code License. 4 * 5 * Copyright 2001, pinc Software. All Rights Reserved. 6 */ 7 #ifndef ISO_9660_H 8 #define ISO_9660_H 9 10 11 #include "lock.h" 12 13 #include <fs_interface.h> 14 #include <SupportDefs.h> 15 16 #include <stdio.h> 17 #include <sys/types.h> 18 #include <time.h> 19 #include <endian.h> 20 21 22 // Size of primary volume descriptor for ISO9660 23 #define ISO_PVD_SIZE 882 24 25 // ISO structure has both msb and lsb first data. These let you do a 26 // compile-time switch for different platforms. 27 28 enum { 29 LSB_DATA = 0, 30 MSB_DATA 31 }; 32 33 // This defines the data format for the platform we are compiling 34 // for. 35 #if BYTE_ORDER == __LITTLE_ENDIAN 36 # define FS_DATA_FORMAT LSB_DATA 37 #else 38 # define FS_DATA_FORMAT MSB_DATA 39 #endif 40 41 // ISO pdf file spec I read appears to be WRONG about the date format. See 42 // www.alumni.caltech.edu/~pje/iso9660.html, definition there seems 43 // to match. 44 typedef struct ISOVolDate { 45 char year[5]; 46 char month[3]; 47 char day[3]; 48 char hour[3]; 49 char minute[3]; 50 char second[3]; 51 char hunSec[3]; 52 int8 offsetGMT; 53 } ISOVolDate; 54 55 typedef struct ISORecDate { 56 uint8 year; // Year - 1900 57 uint8 month; 58 uint8 date; 59 uint8 hour; 60 uint8 minute; 61 uint8 second; 62 int8 offsetGMT; 63 } ISORecDate; 64 65 /* This next section is data structure to hold the data found in the rock ridge extensions. */ 66 typedef struct RRAttr { 67 char* slName; 68 struct stat stat[2]; 69 uint8 nmVer; 70 uint8 pxVer; 71 uint8 slVer; 72 } RRAttr; 73 74 /* For each item on the disk (directory, file, etc), your filesystem should allocate a vnode struct and 75 pass it back to the kernel when fs_read_vnode is called. This struct is then passed back in to 76 your file system by functions that reference an item on the disk. You'll need to be able to 77 create a vnode from a vnode id, either by hashing the id number or encoding the information needed 78 to create the vnode in the vnode id itself. Vnode ids are assigned by your file system when the 79 filesystem walk function is called. For this driver, the block number is encoded in the upper bits 80 of the vnode id, and the offset within the block in the lower, allowing me to just read the info 81 to fill in the vnode struct from the disk. When the kernel is done with a vnode, it will call 82 fs_write_vnode (somewhat of a misnomer) where you should deallocate the struct. 83 */ 84 85 typedef struct vnode { 86 /* Most drivers will probably want the first things defined here. */ 87 ino_t id; 88 ino_t parID; // parent vnode ID. 89 void *cache; // for file cache 90 91 // End of members other drivers will definitely want. 92 93 /* The rest of this struct is very ISO-specific. You should replace the rest of this 94 definition with the stuff your file system needs. 95 */ 96 uint8 extAttrRecLen; // Length of extended attribute record. 97 uint32 startLBN[2]; // Logical block # of start of file/directory data 98 uint32 dataLen[2]; // Length of file section in bytes 99 ISORecDate recordDate; // Date file was recorded. 100 101 // BIT MEANING 102 // --- ----------------------------- 103 uint8 flags; // 0 - is hidden 104 // 1 - is directory 105 // 2 - is "Associated File" 106 // 3 - Info is structed according to extended attr record 107 // 4 - Owner, group, ppermisssions are specified in the 108 // extended attr record 109 // 5 - Reserved 110 // 6 - Reserved 111 // 7 - File has more that one directory record 112 113 uint8 fileUnitSize; // Interleave only 114 uint8 interleaveGapSize; // Interleave only 115 uint32 volSeqNum; // Volume sequence number of volume 116 uint8 fileIDLen; // Length of volume "ID" (name) 117 char* fileIDString; // Volume "ID" (name) 118 119 // The rest is Rock Ridge extensions. I suggest www.leo.org for spec info. 120 RRAttr attr; 121 } vnode; 122 123 // These go with the flags member of the nspace struct. 124 enum { 125 ISO_ISHIDDEN = 0, 126 ISO_ISDIR = 2, 127 ISO_ISASSOCFILE = 4, 128 ISO_EXTATTR = 8, 129 ISO_EXTPERM = 16, 130 ISO_MOREDIRS = 128 131 }; 132 133 134 // Arbitrarily - selected root vnode id 135 #define ISO_ROOTNODE_ID 1 136 137 /* Structure used for directory "cookie". When you are asked 138 to open a directory, you are asked to create a cookie for it 139 and pass it back. The cookie should contain the information you 140 need to determine where you are at in reading the directory 141 entries, incremented every time readdir is called, until finally 142 the end is reached, when readdir returns NULL. */ 143 typedef struct dircookie { 144 off_t startBlock; 145 off_t block; // Current block 146 off_t pos; // Position within block. 147 off_t totalSize; // Size of directory file 148 off_t id; 149 } dircookie; 150 151 /* You may also need to define a cookie for files, which again is 152 allocated every time a file is opened and freed when the free 153 cookie function is called. For ISO, we didn't need one. 154 */ 155 156 typedef struct attrfilemap { 157 char *name; 158 off_t offset; 159 } attrfilemap; 160 161 /* This is the global volume nspace struct. When mount is called , this struct should 162 be allocated. It is passed back into the functions so that you can get at any 163 global information you need. You'll need to change this struct to suit your purposes. 164 */ 165 166 typedef struct nspace { 167 // Start of members other drivers will definitely want. 168 dev_t id; // ID passed in to fs_mount 169 int fd; // File descriptor 170 int fdOfSession; // File descriptor of the (mounted) session 171 //unsigned int blockSize; // usually need this, but it's part of ISO 172 void *fBlockCache; 173 174 char devicePath[127]; 175 //off_t numBlocks; // May need this, but it's part of ISO 176 177 // End of members other drivers will definitely want. 178 179 // attribute extensions 180 int32 readAttributes; 181 attrfilemap *attrFileMap; 182 ino_t attributesID; 183 184 // JOLIET extension: joliet_level for this volume 185 uint8 joliet_level; 186 187 // All this stuff comes straight from ISO primary volume 188 // descriptor structure. 189 uint8 volDescType; // Volume Descriptor type byte1 190 char stdIDString[6]; // Standard ID, 1 extra for null byte2-6 191 uint8 volDescVersion; // Volume Descriptor version byte7 192 // 8th byte unused 193 char systemIDString[33]; // System ID, 1 extra for null byte9-40 194 char volIDString[33]; // Volume ID, 1 extra for null byte41-72 195 // bytes 73-80 unused 196 uint32 volSpaceSize[2]; // #logical blocks, lsb and msb byte81-88 197 // bytes 89-120 unused 198 uint16 volSetSize[2]; // Assigned Volume Set Size of Vol byte121-124 199 uint16 volSeqNum[2]; // Ordinal number of volume in Set byte125-128 200 uint16 logicalBlkSize[2]; // Logical blocksize, usually 2048 byte129-132 201 uint32 pathTblSize[2]; // Path table size byte133-149 202 uint16 lPathTblLoc[2]; // Loc (Logical block #) of "Type L" path table byte141-144 203 uint16 optLPathTblLoc[2]; // Loc (Logical block #) of optional Type L path tbl byte145-148 204 uint16 mPathTblLoc[2]; // Loc (Logical block #) of "Type M" path table byte149-152 205 uint16 optMPathTblLoc[2]; // Loc (Logical block #) of optional Type M path tbl byte153-156 206 vnode rootDirRec; // Directory record for root directory byte157-190 207 char volSetIDString[29]; // Name of multi-volume set where vol is member byte191-318 208 char pubIDString[129]; // Name of publisher byte319-446 209 char dataPreparer[129]; // Name of data preparer byte447-574 210 char appIDString[129]; // Identifies data fomrat byte575-702 211 char copyright[38]; // Copyright string byte703-739 212 char abstractFName[38]; // Name of file in root that has abstract byte740-776 213 char biblioFName[38]; // Name of file in root that has biblio byte777-813 214 215 ISOVolDate createDate; // Creation date byte 216 ISOVolDate modDate; // Modification date 217 ISOVolDate expireDate; // Data expiration date 218 ISOVolDate effectiveDate; // Data effective data 219 220 uint8 fileStructVers; // File structure version byte882 221 } nspace; 222 223 #ifdef __cplusplus 224 extern "C" { 225 #endif 226 227 int ISOMount(const char *path, const int flags, nspace** newVolume, 228 bool allowJoliet); 229 int ISOReadDirEnt(nspace* ns, dircookie* cookie, struct dirent* buffer, 230 size_t bufferSize); 231 int InitNode(vnode* rec, char* buf, int* bytesRead, uint8 jolietLevel); 232 int ConvertRecDate(ISORecDate* inDate, time_t* outDate); 233 234 #ifdef __cplusplus 235 } 236 #endif 237 238 #endif /* ISO_9660_H */ 239