From eb77916297d1108126b2e0e56f76f5dc8c6149f8 Mon Sep 17 00:00:00 2001
From: Gediminas Jarulaitis <beos.zealot@gmail.com>
Date: Sun, 3 Mar 2013 20:12:52 +0200
Subject: [PATCH] iso9660 fs driver bugfix + code refactoring
---
.../kernel/file_systems/iso9660/iso9660.cpp | 141 +++++++++++---------
src/add-ons/kernel/file_systems/iso9660/iso9660.h | 25 ++--
2 files changed, 94 insertions(+), 72 deletions(-)
diff --git a/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp b/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp
index 039c57d..8012b87 100644
a
|
b
|
sanitize_iso_name(iso9660_inode* node, bool removeTrailingPoints)
|
144 | 144 | static int |
145 | 145 | init_volume_date(ISOVolDate *date, char *buffer) |
146 | 146 | { |
147 | | memcpy(date, buffer, 17); |
| 147 | memcpy(date, buffer, ISO_VOL_DATE_SIZE); |
148 | 148 | return 0; |
149 | 149 | } |
150 | 150 | |
… |
… |
init_volume_date(ISOVolDate *date, char *buffer)
|
152 | 152 | static int |
153 | 153 | init_node_date(ISORecDate *date, char *buffer) |
154 | 154 | { |
155 | | memcpy(date, buffer, 7); |
| 155 | memcpy(date, buffer, sizeof(struct ISORecDate)); |
156 | 156 | return 0; |
157 | 157 | } |
158 | 158 | |
… |
… |
InitVolDesc(iso9660_volume *volume, char *buffer)
|
162 | 162 | { |
163 | 163 | TRACE(("InitVolDesc - ENTER\n")); |
164 | 164 | |
165 | | volume->volDescType = *(uint8 *)buffer++; |
166 | | |
167 | | volume->stdIDString[5] = '\0'; |
168 | | strncpy(volume->stdIDString, buffer, 5); |
169 | | buffer += 5; |
| 165 | volume->volDescType = *(uint8 *)buffer; |
| 166 | buffer += sizeof(volume->volDescType); |
| 167 | |
| 168 | const size_t kStdIDStringLen = sizeof(volume->stdIDString) - 1; |
| 169 | volume->stdIDString[kStdIDStringLen] = '\0'; |
| 170 | strncpy(volume->stdIDString, buffer, kStdIDStringLen); |
| 171 | buffer += kStdIDStringLen; |
170 | 172 | |
171 | 173 | volume->volDescVersion = *(uint8 *)buffer; |
172 | | buffer += 2; // 8th byte unused |
173 | | |
174 | | volume->systemIDString[32] = '\0'; |
175 | | strncpy(volume->systemIDString, buffer, 32); |
176 | | buffer += 32; |
| 174 | buffer += sizeof(volume->volDescVersion); |
| 175 | |
| 176 | buffer += sizeof(volume->unused1); // skip unused 8th byte |
| 177 | |
| 178 | const size_t kSystemIDStringLen = sizeof(volume->systemIDString) - 1; |
| 179 | volume->systemIDString[kSystemIDStringLen] = '\0'; |
| 180 | strncpy(volume->systemIDString, buffer, kSystemIDStringLen); |
| 181 | buffer += kSystemIDStringLen; |
177 | 182 | TRACE(("InitVolDesc - system id string is %s\n", volume->systemIDString)); |
178 | | |
179 | | volume->volIDString[32] = '\0'; |
180 | | strncpy(volume->volIDString, buffer, 32); |
181 | | buffer += (32 + 80-73 + 1); // bytes 80-73 unused |
| 183 | |
| 184 | const size_t kVolIDStringLen = sizeof(volume->volIDString) - 1; |
| 185 | volume->volIDString[kVolIDStringLen] = '\0'; |
| 186 | strncpy(volume->volIDString, buffer, kVolIDStringLen); |
| 187 | buffer += kVolIDStringLen; |
182 | 188 | TRACE(("InitVolDesc - volume id string is %s\n", volume->volIDString)); |
183 | 189 | |
| 190 | buffer += sizeof(volume->unused2) - 1; // skip unused 73-80 bytes |
| 191 | |
184 | 192 | volume->volSpaceSize[LSB_DATA] = *(uint32 *)buffer; |
185 | | buffer += 4; |
| 193 | buffer += sizeof(volume->volSpaceSize[LSB_DATA]); |
186 | 194 | volume->volSpaceSize[MSB_DATA] = *(uint32 *)buffer; |
187 | | buffer+= (4 + 120-89 + 1); // bytes 120-89 unused |
188 | | |
| 195 | buffer += sizeof(volume->volSpaceSize[MSB_DATA]); |
| 196 | |
| 197 | buffer += sizeof(volume->unused3) - 1; // skip unused 89-120 bytes |
| 198 | |
189 | 199 | volume->volSetSize[LSB_DATA] = *(uint16*)buffer; |
190 | | buffer += 2; |
| 200 | buffer += sizeof(volume->volSetSize[LSB_DATA]); |
191 | 201 | volume->volSetSize[MSB_DATA] = *(uint16*)buffer; |
192 | | buffer += 2; |
| 202 | buffer += sizeof(volume->volSetSize[MSB_DATA]); |
193 | 203 | |
194 | 204 | volume->volSeqNum[LSB_DATA] = *(uint16*)buffer; |
195 | | buffer += 2; |
| 205 | buffer += sizeof(volume->volSeqNum[LSB_DATA]); |
196 | 206 | volume->volSeqNum[MSB_DATA] = *(uint16*)buffer; |
197 | | buffer += 2; |
| 207 | buffer += sizeof(volume->volSeqNum[MSB_DATA]); |
198 | 208 | |
199 | 209 | volume->logicalBlkSize[LSB_DATA] = *(uint16*)buffer; |
200 | | buffer += 2; |
| 210 | buffer += sizeof(volume->logicalBlkSize[LSB_DATA]); |
201 | 211 | volume->logicalBlkSize[MSB_DATA] = *(uint16*)buffer; |
202 | | buffer += 2; |
| 212 | buffer += sizeof(volume->logicalBlkSize[MSB_DATA]); |
203 | 213 | |
204 | 214 | volume->pathTblSize[LSB_DATA] = *(uint32*)buffer; |
205 | | buffer += 4; |
| 215 | buffer += sizeof(volume->pathTblSize[LSB_DATA]); |
206 | 216 | volume->pathTblSize[MSB_DATA] = *(uint32*)buffer; |
207 | | buffer += 4; |
| 217 | buffer += sizeof(volume->pathTblSize[MSB_DATA]); |
208 | 218 | |
209 | 219 | volume->lPathTblLoc[LSB_DATA] = *(uint16*)buffer; |
210 | | buffer += 2; |
| 220 | buffer += sizeof(volume->lPathTblLoc[LSB_DATA]); |
211 | 221 | volume->lPathTblLoc[MSB_DATA] = *(uint16*)buffer; |
212 | | buffer += 2; |
| 222 | buffer += sizeof(volume->lPathTblLoc[MSB_DATA]); |
213 | 223 | |
214 | 224 | volume->optLPathTblLoc[LSB_DATA] = *(uint16*)buffer; |
215 | | buffer += 2; |
| 225 | buffer += sizeof(volume->optLPathTblLoc[LSB_DATA]); |
216 | 226 | volume->optLPathTblLoc[MSB_DATA] = *(uint16*)buffer; |
217 | | buffer += 2; |
| 227 | buffer += sizeof(volume->optLPathTblLoc[MSB_DATA]); |
218 | 228 | |
219 | 229 | volume->mPathTblLoc[LSB_DATA] = *(uint16*)buffer; |
220 | | buffer += 2; |
| 230 | buffer += sizeof(volume->mPathTblLoc[LSB_DATA]); |
221 | 231 | volume->mPathTblLoc[MSB_DATA] = *(uint16*)buffer; |
222 | | buffer += 2; |
| 232 | buffer += sizeof(volume->mPathTblLoc[MSB_DATA]); |
223 | 233 | |
224 | 234 | volume->optMPathTblLoc[LSB_DATA] = *(uint16*)buffer; |
225 | | buffer += 2; |
| 235 | buffer += sizeof(volume->optMPathTblLoc[LSB_DATA]); |
226 | 236 | volume->optMPathTblLoc[MSB_DATA] = *(uint16*)buffer; |
227 | | buffer += 2; |
| 237 | buffer += sizeof(volume->optMPathTblLoc[MSB_DATA]); |
228 | 238 | |
229 | 239 | // Fill in directory record. |
230 | 240 | volume->joliet_level = 0; |
231 | 241 | InitNode(volume, &volume->rootDirRec, buffer, NULL); |
232 | 242 | |
233 | 243 | volume->rootDirRec.id = ISO_ROOTNODE_ID; |
234 | | buffer += 34; |
235 | | |
236 | | volume->volSetIDString[128] = '\0'; |
237 | | strncpy(volume->volSetIDString, buffer, 128); |
238 | | buffer += 128; |
| 244 | buffer += ISO_ROOT_DIR_REC_SIZE; |
| 245 | |
| 246 | const size_t kVolSetIDStringLen = sizeof(volume->volSetIDString) - 1; |
| 247 | volume->volSetIDString[kVolSetIDStringLen] = '\0'; |
| 248 | strncpy(volume->volSetIDString, buffer, kVolSetIDStringLen); |
| 249 | buffer += kVolSetIDStringLen; |
239 | 250 | TRACE(("InitVolDesc - volume set id string is %s\n", volume->volSetIDString)); |
240 | 251 | |
241 | | volume->pubIDString[128] = '\0'; |
242 | | strncpy(volume->pubIDString, buffer, 128); |
243 | | buffer += 128; |
| 252 | const size_t kPubIDStringLen = sizeof(volume->pubIDString) - 1; |
| 253 | volume->pubIDString[kPubIDStringLen] = '\0'; |
| 254 | strncpy(volume->pubIDString, buffer, kPubIDStringLen); |
| 255 | buffer += kPubIDStringLen; |
244 | 256 | TRACE(("InitVolDesc - volume pub id string is %s\n", volume->pubIDString)); |
245 | 257 | |
246 | | volume->dataPreparer[128] = '\0'; |
247 | | strncpy(volume->dataPreparer, buffer, 128); |
248 | | buffer += 128; |
| 258 | const size_t kDataPreparerLen = sizeof(volume->dataPreparer) - 1; |
| 259 | volume->dataPreparer[kDataPreparerLen] = '\0'; |
| 260 | strncpy(volume->dataPreparer, buffer, kDataPreparerLen); |
| 261 | buffer += kDataPreparerLen; |
249 | 262 | TRACE(("InitVolDesc - volume dataPreparer string is %s\n", volume->dataPreparer)); |
250 | 263 | |
251 | | volume->appIDString[128] = '\0'; |
252 | | strncpy(volume->appIDString, buffer, 128); |
253 | | buffer += 128; |
| 264 | const size_t kAppIDStringLen = sizeof(volume->appIDString) - 1; |
| 265 | volume->appIDString[kAppIDStringLen] = '\0'; |
| 266 | strncpy(volume->appIDString, buffer, kAppIDStringLen); |
| 267 | buffer += kAppIDStringLen; |
254 | 268 | TRACE(("InitVolDesc - volume app id string is %s\n", volume->appIDString)); |
255 | 269 | |
256 | | volume->copyright[38] = '\0'; |
257 | | strncpy(volume->copyright, buffer, 38); |
258 | | buffer += 38; |
| 270 | const size_t kCopyrightLen = sizeof(volume->copyright) - 1; |
| 271 | volume->copyright[kCopyrightLen] = '\0'; |
| 272 | strncpy(volume->copyright, buffer, kCopyrightLen); |
| 273 | buffer += kCopyrightLen; |
259 | 274 | TRACE(("InitVolDesc - copyright is %s\n", volume->copyright)); |
260 | 275 | |
261 | | volume->abstractFName[38] = '\0'; |
262 | | strncpy(volume->abstractFName, buffer, 38); |
263 | | buffer += 38; |
| 276 | const size_t kAbstractFNameLen = sizeof(volume->abstractFName) - 1; |
| 277 | volume->abstractFName[kAbstractFNameLen] = '\0'; |
| 278 | strncpy(volume->abstractFName, buffer, kAbstractFNameLen); |
| 279 | buffer += kAbstractFNameLen; |
264 | 280 | |
265 | | volume->biblioFName[38] = '\0'; |
266 | | strncpy(volume->biblioFName, buffer, 38); |
267 | | buffer += 38; |
| 281 | const size_t kBiblioFNameLen = sizeof(volume->biblioFName) - 1; |
| 282 | volume->biblioFName[kBiblioFNameLen] = '\0'; |
| 283 | strncpy(volume->biblioFName, buffer, kBiblioFNameLen); |
| 284 | buffer += kBiblioFNameLen; |
268 | 285 | |
269 | 286 | init_volume_date(&volume->createDate, buffer); |
270 | | buffer += 17; |
| 287 | buffer += ISO_VOL_DATE_SIZE; |
271 | 288 | |
272 | 289 | init_volume_date(&volume->modDate, buffer); |
273 | | buffer += 17; |
| 290 | buffer += ISO_VOL_DATE_SIZE; |
274 | 291 | |
275 | 292 | init_volume_date(&volume->expireDate, buffer); |
276 | | buffer += 17; |
| 293 | buffer += ISO_VOL_DATE_SIZE; |
277 | 294 | |
278 | 295 | init_volume_date(&volume->effectiveDate, buffer); |
279 | | buffer += 17; |
| 296 | buffer += ISO_VOL_DATE_SIZE; |
280 | 297 | |
281 | 298 | volume->fileStructVers = *(uint8*)buffer; |
282 | 299 | return B_OK; |
diff --git a/src/add-ons/kernel/file_systems/iso9660/iso9660.h b/src/add-ons/kernel/file_systems/iso9660/iso9660.h
index 32da4d8..a98c6d8 100644
a
|
b
|
typedef struct ISOVolDate {
|
56 | 56 | int8 offsetGMT; |
57 | 57 | } ISOVolDate; |
58 | 58 | |
| 59 | // Size of volume date and time data |
| 60 | #define ISO_VOL_DATE_SIZE 17 |
| 61 | |
59 | 62 | typedef struct ISORecDate { |
60 | 63 | uint8 year; // Year - 1900 |
61 | 64 | uint8 month; |
… |
… |
struct iso9660_volume {
|
183 | 186 | uint8 volDescType; // Volume Descriptor type byte1 |
184 | 187 | char stdIDString[6]; // Standard ID, 1 extra for null byte2-6 |
185 | 188 | uint8 volDescVersion; // Volume Descriptor version byte7 |
186 | | // 8th byte unused |
| 189 | uint8 unused1; // Unused Field byte8 |
187 | 190 | char systemIDString[33]; // System ID, 1 extra for null byte9-40 |
188 | 191 | 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 | char unused2[9]; // Unused Field byte73-80 |
| 193 | uint32 volSpaceSize[2]; // #logical blocks, lsb and msb byte81-88 |
| 194 | char unused3[33]; // Unused Field byte89-120 |
192 | 195 | uint16 volSetSize[2]; // Assigned Volume Set Size of Vol byte121-124 |
193 | 196 | uint16 volSeqNum[2]; // Ordinal number of volume in Set byte125-128 |
194 | 197 | uint16 logicalBlkSize[2]; // Logical blocksize, usually 2048 byte129-132 |
195 | 198 | 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 |
| 199 | uint16 lPathTblLoc[2]; // Loc (Logical block #) of "Type L" path table byte141-144 |
| 200 | uint16 optLPathTblLoc[2]; // Loc (Logical block #) of optional Type L path tbl byte145-148 |
| 201 | uint16 mPathTblLoc[2]; // Loc (Logical block #) of "Type M" path table byte149-152 |
| 202 | uint16 optMPathTblLoc[2]; // Loc (Logical block #) of optional Type M path tbl byte153-156 |
| 203 | iso9660_inode rootDirRec; // Directory record for root directory byte157-190 |
201 | 204 | char volSetIDString[129]; // Name of multi-volume set where vol is member byte191-318 |
202 | 205 | char pubIDString[129]; // Name of publisher byte319-446 |
203 | 206 | char dataPreparer[129]; // Name of data preparer byte447-574 |
204 | 207 | char appIDString[129]; // Identifies data fomrat byte575-702 |
205 | 208 | char copyright[38]; // Copyright string byte703-739 |
206 | 209 | 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 |
| 210 | char biblioFName[38]; // Name of file in root that has biblio byte777-813 |
208 | 211 | |
209 | 212 | ISOVolDate createDate; // Creation date byte |
210 | 213 | ISOVolDate modDate; // Modification date |
… |
… |
struct iso9660_volume {
|
214 | 217 | uint8 fileStructVers; // File structure version byte882 |
215 | 218 | }; |
216 | 219 | |
| 220 | // Size of root directory record |
| 221 | #define ISO_ROOT_DIR_REC_SIZE 34 |
217 | 222 | |
218 | 223 | status_t ISOMount(const char *path, uint32 flags, iso9660_volume** _newVolume, |
219 | 224 | bool allowJoliet); |