| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: iso9660_rrip.c,v 1.4.20.1 2010/01/02 06:26:11 snj Exp $ */ | | 1 | /* $NetBSD: iso9660_rrip.c,v 1.4.20.2 2010/01/02 06:27:27 snj Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan | | 4 | * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan |
5 | * Perez-Rathke and Ram Vedam. All rights reserved. | | 5 | * Perez-Rathke and Ram Vedam. All rights reserved. |
6 | * | | 6 | * |
7 | * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, | | 7 | * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, |
8 | * Alan Perez-Rathke and Ram Vedam. | | 8 | * Alan Perez-Rathke and Ram Vedam. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or | | 10 | * Redistribution and use in source and binary forms, with or |
11 | * without modification, are permitted provided that the following | | 11 | * without modification, are permitted provided that the following |
12 | * conditions are met: | | 12 | * conditions are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -33,27 +33,27 @@ | | | @@ -33,27 +33,27 @@ |
33 | */ | | 33 | */ |
34 | /* This will hold all the function definitions | | 34 | /* This will hold all the function definitions |
35 | * defined in iso9660_rrip.h | | 35 | * defined in iso9660_rrip.h |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | #include "makefs.h" | | 38 | #include "makefs.h" |
39 | #include "cd9660.h" | | 39 | #include "cd9660.h" |
40 | #include "iso9660_rrip.h" | | 40 | #include "iso9660_rrip.h" |
41 | #include <sys/queue.h> | | 41 | #include <sys/queue.h> |
42 | #include <stdio.h> | | 42 | #include <stdio.h> |
43 | | | 43 | |
44 | #include <sys/cdefs.h> | | 44 | #include <sys/cdefs.h> |
45 | #if defined(__RCSID) && !defined(__lint) | | 45 | #if defined(__RCSID) && !defined(__lint) |
46 | __RCSID("$NetBSD: iso9660_rrip.c,v 1.4.20.1 2010/01/02 06:26:11 snj Exp $"); | | 46 | __RCSID("$NetBSD: iso9660_rrip.c,v 1.4.20.2 2010/01/02 06:27:27 snj Exp $"); |
47 | #endif /* !__lint */ | | 47 | #endif /* !__lint */ |
48 | | | 48 | |
49 | static void cd9660_rrip_initialize_inode(cd9660node *); | | 49 | static void cd9660_rrip_initialize_inode(cd9660node *); |
50 | static int cd9660_susp_handle_continuation(cd9660node *); | | 50 | static int cd9660_susp_handle_continuation(cd9660node *); |
51 | static int cd9660_susp_handle_continuation_common(cd9660node *, int); | | 51 | static int cd9660_susp_handle_continuation_common(cd9660node *, int); |
52 | | | 52 | |
53 | int | | 53 | int |
54 | cd9660_susp_initialize(cd9660node *node, cd9660node *parent, | | 54 | cd9660_susp_initialize(cd9660node *node, cd9660node *parent, |
55 | cd9660node *grandparent) | | 55 | cd9660node *grandparent) |
56 | { | | 56 | { |
57 | cd9660node *cn; | | 57 | cd9660node *cn; |
58 | int r; | | 58 | int r; |
59 | | | 59 | |
| @@ -190,56 +190,62 @@ cd9660_rrip_finalize_node(cd9660node *no | | | @@ -190,56 +190,62 @@ cd9660_rrip_finalize_node(cd9660node *no |
190 | cd9660_bothendian_dword( | | 190 | cd9660_bothendian_dword( |
191 | node->rr_real_parent->fileDataSector, | | 191 | node->rr_real_parent->fileDataSector, |
192 | (unsigned char *) | | 192 | (unsigned char *) |
193 | t->attr.rr_entry.PL.dir_loc); | | 193 | t->attr.rr_entry.PL.dir_loc); |
194 | break; | | 194 | break; |
195 | } | | 195 | } |
196 | } | | 196 | } |
197 | return 0; | | 197 | return 0; |
198 | } | | 198 | } |
199 | | | 199 | |
200 | static int | | 200 | static int |
201 | cd9660_susp_handle_continuation_common(cd9660node *node, int space) | | 201 | cd9660_susp_handle_continuation_common(cd9660node *node, int space) |
202 | { | | 202 | { |
203 | int ca_used, susp_used, working; | | 203 | int ca_used, susp_used, susp_used_last, working; |
204 | struct ISO_SUSP_ATTRIBUTES *temp, *last = NULL, *CE; | | 204 | struct ISO_SUSP_ATTRIBUTES *temp, *last = NULL, *CE; |
205 | | | 205 | |
206 | working = 254 - space; | | 206 | working = 254 - space; |
207 | /* printf("There are %i bytes to work with\n",working); */ | | 207 | /* printf("There are %i bytes to work with\n",working); */ |
208 | | | 208 | |
209 | susp_used = 0; | | 209 | susp_used = 0; |
210 | ca_used = 0; | | 210 | ca_used = 0; |
211 | TAILQ_FOREACH(temp, &node->head, rr_ll) { | | 211 | TAILQ_FOREACH(temp, &node->head, rr_ll) { |
212 | if (working < 0) | | 212 | if (working < 0) |
213 | break; | | 213 | break; |
214 | /* | | 214 | /* |
215 | * printf("SUSP Entry found, length is %i\n", | | 215 | * printf("SUSP Entry found, length is %i\n", |
216 | * CD9660_SUSP_ENTRY_SIZE(temp)); | | 216 | * CD9660_SUSP_ENTRY_SIZE(temp)); |
217 | */ | | 217 | */ |
218 | working -= CD9660_SUSP_ENTRY_SIZE(temp); | | 218 | working -= CD9660_SUSP_ENTRY_SIZE(temp); |
| | | 219 | if (working >= 0) |
| | | 220 | susp_used += CD9660_SUSP_ENTRY_SIZE(temp); |
219 | if (working >= 28) { | | 221 | if (working >= 28) { |
| | | 222 | /* |
| | | 223 | * Remember the last entry after which we |
| | | 224 | * could insert a "CE" entry. |
| | | 225 | */ |
220 | last = temp; | | 226 | last = temp; |
221 | susp_used += CD9660_SUSP_ENTRY_SIZE(temp); | | 227 | susp_used_last = susp_used; |
222 | } | | 228 | } |
223 | } | | 229 | } |
224 | | | 230 | |
225 | /* A CE entry is needed */ | | 231 | /* A CE entry is needed */ |
226 | if (working <= 0) { | | 232 | if (working <= 0) { |
227 | CE = cd9660node_susp_create_node(SUSP_TYPE_SUSP, | | 233 | CE = cd9660node_susp_create_node(SUSP_TYPE_SUSP, |
228 | SUSP_ENTRY_SUSP_CE, "CE", SUSP_LOC_ENTRY); | | 234 | SUSP_ENTRY_SUSP_CE, "CE", SUSP_LOC_ENTRY); |
229 | cd9660_susp_ce(CE, node); | | 235 | cd9660_susp_ce(CE, node); |
230 | /* This will automatically insert at the appropriate location */ | | 236 | /* This will automatically insert at the appropriate location */ |
231 | TAILQ_INSERT_AFTER(&node->head, last, CE, rr_ll); | | 237 | TAILQ_INSERT_AFTER(&node->head, last, CE, rr_ll); |
232 | susp_used += 28; | | 238 | susp_used = susp_used_last + 28; |
233 | | | 239 | |
234 | /* Count how much CA data is necessary */ | | 240 | /* Count how much CA data is necessary */ |
235 | for (temp = TAILQ_NEXT(CE, rr_ll); temp != NULL; | | 241 | for (temp = TAILQ_NEXT(CE, rr_ll); temp != NULL; |
236 | temp = TAILQ_NEXT(temp, rr_ll)) { | | 242 | temp = TAILQ_NEXT(temp, rr_ll)) { |
237 | ca_used += CD9660_SUSP_ENTRY_SIZE(temp); | | 243 | ca_used += CD9660_SUSP_ENTRY_SIZE(temp); |
238 | } | | 244 | } |
239 | } | | 245 | } |
240 | | | 246 | |
241 | node->susp_entry_size = susp_used; | | 247 | node->susp_entry_size = susp_used; |
242 | node->susp_entry_ce_length = ca_used; | | 248 | node->susp_entry_ce_length = ca_used; |
243 | | | 249 | |
244 | diskStructure.susp_continuation_area_size += ca_used; | | 250 | diskStructure.susp_continuation_area_size += ca_used; |
245 | return 1; | | 251 | return 1; |