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