xref: /haiku/src/add-ons/kernel/file_systems/iso9660/iso9660.h (revision a4ef4a49150f118d47324242917a596a3f8f8bd5)
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
66 // rock ridge extensions.
67 struct rock_ridge_attributes {
68 	char*			slName;
69 	struct stat		stat[2];
70 	uint8			nmVer;
71 	uint8			pxVer;
72 	uint8			slVer;
73 };
74 
75 struct iso9660_inode {
76 	/* Most drivers will probably want the first things defined here. */
77 	ino_t		id;
78 	ino_t	 	parID;		// parent vnode ID.
79 	void		*cache;		// for file cache
80 
81 	// End of members other drivers will definitely want.
82 
83 	/* The rest of this struct is very ISO-specific. You should replace the rest of this
84 		definition with the stuff your file system needs.
85 	*/
86 	uint8		extAttrRecLen;			// Length of extended attribute record.
87 	uint32		startLBN[2];			// Logical block # of start of file/directory data
88 	uint32		dataLen[2];				// Length of file section in bytes
89 	ISORecDate	recordDate;				// Date file was recorded.
90 
91 										// BIT MEANING
92 										// --- -----------------------------
93 	uint8		flags;					// 0 - is hidden
94 										// 1 - is directory
95 										// 2 - is "Associated File"
96 										// 3 - Info is structed according to extended attr record
97 										// 4 - Owner, group, ppermisssions are specified in the
98 										//		extended attr record
99 										// 5 - Reserved
100 										// 6 - Reserved
101 										// 7 - File has more that one directory record
102 
103 	uint8		fileUnitSize;			// Interleave only
104 	uint8		interleaveGapSize;		// Interleave only
105 	uint32		volSeqNum;				// Volume sequence number of volume
106 	char*		name;
107 	uint32		name_length;
108 
109 	// The rest is Rock Ridge extensions. I suggest www.leo.org for spec info.
110 	rock_ridge_attributes attr;
111 };
112 
113 // These go with the flags member of the iso9660_volume struct.
114 enum {
115 	ISO_ISHIDDEN	= 0,
116 	ISO_ISDIR		= 2,
117 	ISO_ISASSOCFILE	= 4,
118 	ISO_EXTATTR		= 8,
119 	ISO_EXTPERM		= 16,
120 	ISO_MOREDIRS	= 128
121 };
122 
123 
124 // Arbitrarily - selected root vnode id
125 #define ISO_ROOTNODE_ID 1
126 
127 /* Structure used for directory "cookie". When you are asked
128  	to open a directory, you are asked to create a cookie for it
129  	and pass it back. The cookie should contain the information you
130  	need to determine where you are at in reading the directory
131  	entries, incremented every time readdir is called, until finally
132  	the end is reached, when readdir returns NULL. */
133 typedef struct dircookie {
134 	off_t startBlock;
135 	off_t block;			// Current block
136 	off_t pos;				// Position within block.
137 	off_t totalSize;		// Size of directory file
138 	off_t id;
139 } dircookie;
140 
141 /* You may also need to define a cookie for files, which again is
142 	allocated every time a file is opened and freed when the free
143 	cookie function is called. For ISO, we didn't need one.
144 */
145 
146 typedef struct attrfilemap {
147 	char  *name;
148 	off_t offset;
149 } attrfilemap;
150 
151 // This is the global volume iso9660_volume struct.
152 struct iso9660_volume {
153 	// Start of members other drivers will definitely want.
154 	fs_volume		*volume;			// volume passed fo fs_mount
155 	dev_t			id;
156 	int				fd;				// File descriptor
157 	int				fdOfSession;	// File descriptor of the (mounted) session
158 	//unsigned int 	blockSize;  	// usually need this, but it's part of ISO
159 	void                            *fBlockCache;
160 
161 	char			devicePath[127];
162 	//off_t			numBlocks;		// May need this, but it's part of ISO
163 
164 	// End of members other drivers will definitely want.
165 
166 	// attribute extensions
167 	int32			readAttributes;
168 	attrfilemap 	*attrFileMap;
169 	ino_t			attributesID;
170 
171 	// JOLIET extension: joliet_level for this volume
172 	uint8			joliet_level;
173 
174 	// All this stuff comes straight from ISO primary volume
175 	// descriptor structure.
176 	uint8			volDescType;		// Volume Descriptor type								byte1
177 	char			stdIDString[6];		// Standard ID, 1 extra for null						byte2-6
178 	uint8			volDescVersion;		// Volume Descriptor version							byte7
179 																			// 8th byte unused
180 	char			systemIDString[33];	// System ID, 1 extra for null							byte9-40
181 	char			volIDString[33];	// Volume ID, 1 extra for null							byte41-72
182 																			// bytes 73-80 unused
183 	uint32			volSpaceSize[2];	// #logical blocks, lsb and msb									byte81-88
184 																		// bytes 89-120 unused
185 	uint16			volSetSize[2];		// Assigned Volume Set Size of Vol						byte121-124
186 	uint16			volSeqNum[2];		// Ordinal number of volume in Set						byte125-128
187 	uint16			logicalBlkSize[2];	// Logical blocksize, usually 2048						byte129-132
188 	uint32			pathTblSize[2];		// Path table size										byte133-149
189 	uint16			lPathTblLoc[2];		// Loc (Logical block #) of "Type L" path table		byte141-144
190 	uint16			optLPathTblLoc[2];	// Loc (Logical block #) of optional Type L path tbl		byte145-148
191 	uint16			mPathTblLoc[2];		// Loc (Logical block #) of "Type M" path table		byte149-152
192 	uint16			optMPathTblLoc[2];		// Loc (Logical block #) of optional Type M path tbl	byte153-156
193 	iso9660_inode			rootDirRec;			// Directory record for root directory					byte157-190
194 	char			volSetIDString[29];	// Name of multi-volume set where vol is member		byte191-318
195 	char			pubIDString[129];	// Name of publisher									byte319-446
196 	char			dataPreparer[129];	// Name of data preparer								byte447-574
197 	char			appIDString[129];	// Identifies data fomrat								byte575-702
198 	char			copyright[38];		// Copyright string										byte703-739
199 	char			abstractFName[38];	// Name of file in root that has abstract				byte740-776
200 	char			biblioFName[38];	// Name of file in root that has biblio				byte777-813
201 
202 	ISOVolDate		createDate;			// Creation date										byte
203 	ISOVolDate		modDate;			// Modification date
204 	ISOVolDate		expireDate;			// Data expiration date
205 	ISOVolDate		effectiveDate;		// Data effective data
206 
207 	uint8			fileStructVers;		// File structure version								byte882
208 };
209 
210 
211 status_t ISOMount(const char *path, uint32 flags, iso9660_volume** _newVolume,
212 	bool allowJoliet);
213 status_t ISOReadDirEnt(iso9660_volume* ns, dircookie* cookie,
214 	struct dirent* buffer, size_t bufferSize);
215 status_t InitNode(iso9660_inode* rec, char* buf, size_t* bytesRead,
216 	uint8 jolietLevel);
217 status_t ConvertRecDate(ISORecDate* inDate, time_t* outDate);
218 
219 #endif	/* ISO_9660_H */
220