xref: /haiku/src/add-ons/kernel/file_systems/iso9660/iso9660.h (revision fc1ca2da5cfcb00ffdf791606d5ae97fdd58a638)
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 	fs_volume		*volume;			// volume passed fo fs_mount
169 	dev_t			id;
170 	int				fd;				// File descriptor
171 	int				fdOfSession;	// File descriptor of the (mounted) session
172 	//unsigned int 	blockSize;  	// usually need this, but it's part of ISO
173 	void                            *fBlockCache;
174 
175 	char			devicePath[127];
176 	//off_t			numBlocks;		// May need this, but it's part of ISO
177 
178 	// End of members other drivers will definitely want.
179 
180 	// attribute extensions
181 	int32			readAttributes;
182 	attrfilemap 	*attrFileMap;
183 	ino_t			attributesID;
184 
185 	// JOLIET extension: joliet_level for this volume
186 	uint8			joliet_level;
187 
188 	// All this stuff comes straight from ISO primary volume
189 	// descriptor structure.
190 	uint8			volDescType;		// Volume Descriptor type								byte1
191 	char			stdIDString[6];		// Standard ID, 1 extra for null						byte2-6
192 	uint8			volDescVersion;		// Volume Descriptor version							byte7
193 																			// 8th byte unused
194 	char			systemIDString[33];	// System ID, 1 extra for null							byte9-40
195 	char			volIDString[33];	// Volume ID, 1 extra for null							byte41-72
196 																			// bytes 73-80 unused
197 	uint32			volSpaceSize[2];	// #logical blocks, lsb and msb									byte81-88
198 																		// bytes 89-120 unused
199 	uint16			volSetSize[2];		// Assigned Volume Set Size of Vol						byte121-124
200 	uint16			volSeqNum[2];		// Ordinal number of volume in Set						byte125-128
201 	uint16			logicalBlkSize[2];	// Logical blocksize, usually 2048						byte129-132
202 	uint32			pathTblSize[2];		// Path table size										byte133-149
203 	uint16			lPathTblLoc[2];		// Loc (Logical block #) of "Type L" path table		byte141-144
204 	uint16			optLPathTblLoc[2];	// Loc (Logical block #) of optional Type L path tbl		byte145-148
205 	uint16			mPathTblLoc[2];		// Loc (Logical block #) of "Type M" path table		byte149-152
206 	uint16			optMPathTblLoc[2];		// Loc (Logical block #) of optional Type M path tbl	byte153-156
207 	vnode			rootDirRec;			// Directory record for root directory					byte157-190
208 	char			volSetIDString[29];	// Name of multi-volume set where vol is member		byte191-318
209 	char			pubIDString[129];	// Name of publisher									byte319-446
210 	char			dataPreparer[129];	// Name of data preparer								byte447-574
211 	char			appIDString[129];	// Identifies data fomrat								byte575-702
212 	char			copyright[38];		// Copyright string										byte703-739
213 	char			abstractFName[38];	// Name of file in root that has abstract				byte740-776
214 	char			biblioFName[38];	// Name of file in root that has biblio				byte777-813
215 
216 	ISOVolDate		createDate;			// Creation date										byte
217 	ISOVolDate		modDate;			// Modification date
218 	ISOVolDate		expireDate;			// Data expiration date
219 	ISOVolDate		effectiveDate;		// Data effective data
220 
221 	uint8			fileStructVers;		// File structure version								byte882
222 } nspace;
223 
224 #ifdef __cplusplus
225 extern "C" {
226 #endif
227 
228 int ISOMount(const char *path, const int flags, nspace** newVolume,
229 	bool allowJoliet);
230 int	ISOReadDirEnt(nspace* ns, dircookie* cookie, struct dirent* buffer,
231 	size_t bufferSize);
232 int	InitNode(vnode* rec, char* buf, int* bytesRead, uint8 jolietLevel);
233 int	ConvertRecDate(ISORecDate* inDate, time_t* outDate);
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 
239 #endif	/* ISO_9660_H */
240