aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/directory.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf/directory.c')
-rw-r--r--fs/udf/directory.c207
1 files changed, 99 insertions, 108 deletions
diff --git a/fs/udf/directory.c b/fs/udf/directory.c
index 198caa33027a..8adc77c1d579 100644
--- a/fs/udf/directory.c
+++ b/fs/udf/directory.c
@@ -19,10 +19,10 @@
19#include <linux/buffer_head.h> 19#include <linux/buffer_head.h>
20 20
21#if 0 21#if 0
22static uint8_t * 22static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
23udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size, 23 uint8_t ad_size, kernel_lb_addr fe_loc,
24 kernel_lb_addr fe_loc, int *pos, int *offset, 24 int *pos, int *offset, struct buffer_head **bh,
25 struct buffer_head **bh, int *error) 25 int *error)
26{ 26{
27 int loffset = *offset; 27 int loffset = *offset;
28 int block; 28 int block;
@@ -31,31 +31,27 @@ udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size,
31 31
32 *error = 0; 32 *error = 0;
33 33
34 ad = (uint8_t *)(*bh)->b_data + *offset; 34 ad = (uint8_t *) (*bh)->b_data + *offset;
35 *offset += ad_size; 35 *offset += ad_size;
36 36
37 if (!ad) 37 if (!ad) {
38 {
39 brelse(*bh); 38 brelse(*bh);
40 *error = 1; 39 *error = 1;
41 return NULL; 40 return NULL;
42 } 41 }
43 42
44 if (*offset == dir->i_sb->s_blocksize) 43 if (*offset == dir->i_sb->s_blocksize) {
45 {
46 brelse(*bh); 44 brelse(*bh);
47 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); 45 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
48 if (!block) 46 if (!block)
49 return NULL; 47 return NULL;
50 if (!(*bh = udf_tread(dir->i_sb, block))) 48 if (!(*bh = udf_tread(dir->i_sb, block)))
51 return NULL; 49 return NULL;
52 } 50 } else if (*offset > dir->i_sb->s_blocksize) {
53 else if (*offset > dir->i_sb->s_blocksize)
54 {
55 ad = tmpad; 51 ad = tmpad;
56 52
57 remainder = dir->i_sb->s_blocksize - loffset; 53 remainder = dir->i_sb->s_blocksize - loffset;
58 memcpy((uint8_t *)ad, (*bh)->b_data + loffset, remainder); 54 memcpy((uint8_t *) ad, (*bh)->b_data + loffset, remainder);
59 55
60 brelse(*bh); 56 brelse(*bh);
61 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); 57 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
@@ -64,56 +60,56 @@ udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size,
64 if (!((*bh) = udf_tread(dir->i_sb, block))) 60 if (!((*bh) = udf_tread(dir->i_sb, block)))
65 return NULL; 61 return NULL;
66 62
67 memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder); 63 memcpy((uint8_t *) ad + remainder, (*bh)->b_data,
64 ad_size - remainder);
68 *offset = ad_size - remainder; 65 *offset = ad_size - remainder;
69 } 66 }
70 return ad; 67 return ad;
71} 68}
72#endif 69#endif
73 70
74struct fileIdentDesc * 71struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
75udf_fileident_read(struct inode *dir, loff_t *nf_pos, 72 struct udf_fileident_bh *fibh,
76 struct udf_fileident_bh *fibh, 73 struct fileIdentDesc *cfi,
77 struct fileIdentDesc *cfi, 74 struct extent_position *epos,
78 struct extent_position *epos, 75 kernel_lb_addr * eloc, uint32_t * elen,
79 kernel_lb_addr *eloc, uint32_t *elen, 76 sector_t * offset)
80 sector_t *offset)
81{ 77{
82 struct fileIdentDesc *fi; 78 struct fileIdentDesc *fi;
83 int i, num, block; 79 int i, num, block;
84 struct buffer_head * tmp, * bha[16]; 80 struct buffer_head *tmp, *bha[16];
85 81
86 fibh->soffset = fibh->eoffset; 82 fibh->soffset = fibh->eoffset;
87 83
88 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 84 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
89 {
90 fi = udf_get_fileident(UDF_I_DATA(dir) - 85 fi = udf_get_fileident(UDF_I_DATA(dir) -
91 (UDF_I_EFE(dir) ? 86 (UDF_I_EFE(dir) ?
92 sizeof(struct extendedFileEntry) : 87 sizeof(struct extendedFileEntry) :
93 sizeof(struct fileEntry)), 88 sizeof(struct fileEntry)),
94 dir->i_sb->s_blocksize, &(fibh->eoffset)); 89 dir->i_sb->s_blocksize,
90 &(fibh->eoffset));
95 91
96 if (!fi) 92 if (!fi)
97 return NULL; 93 return NULL;
98 94
99 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 95 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
100 96
101 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc)); 97 memcpy((uint8_t *) cfi, (uint8_t *) fi,
98 sizeof(struct fileIdentDesc));
102 99
103 return fi; 100 return fi;
104 } 101 }
105 102
106 if (fibh->eoffset == dir->i_sb->s_blocksize) 103 if (fibh->eoffset == dir->i_sb->s_blocksize) {
107 {
108 int lextoffset = epos->offset; 104 int lextoffset = epos->offset;
109 105
110 if (udf_next_aext(dir, epos, eloc, elen, 1) != 106 if (udf_next_aext(dir, epos, eloc, elen, 1) !=
111 (EXT_RECORDED_ALLOCATED >> 30)) 107 (EXT_RECORDED_ALLOCATED >> 30))
112 return NULL; 108 return NULL;
113 109
114 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); 110 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
115 111
116 (*offset) ++; 112 (*offset)++;
117 113
118 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) 114 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
119 *offset = 0; 115 *offset = 0;
@@ -125,57 +121,57 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos,
125 return NULL; 121 return NULL;
126 fibh->soffset = fibh->eoffset = 0; 122 fibh->soffset = fibh->eoffset = 0;
127 123
128 if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9))-1))) 124 if (!
125 (*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1)))
129 { 126 {
130 i = 16 >> (dir->i_sb->s_blocksize_bits - 9); 127 i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
131 if (i+*offset > (*elen >> dir->i_sb->s_blocksize_bits)) 128 if (i + *offset >
132 i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; 129 (*elen >> dir->i_sb->s_blocksize_bits))
133 for (num=0; i>0; i--) 130 i = (*elen >> dir->i_sb->s_blocksize_bits) -
134 { 131 *offset;
135 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset+i); 132 for (num = 0; i > 0; i--) {
133 block =
134 udf_get_lb_pblock(dir->i_sb, *eloc,
135 *offset + i);
136 tmp = udf_tgetblk(dir->i_sb, block); 136 tmp = udf_tgetblk(dir->i_sb, block);
137 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) 137 if (tmp && !buffer_uptodate(tmp)
138 && !buffer_locked(tmp))
138 bha[num++] = tmp; 139 bha[num++] = tmp;
139 else 140 else
140 brelse(tmp); 141 brelse(tmp);
141 } 142 }
142 if (num) 143 if (num) {
143 {
144 ll_rw_block(READA, num, bha); 144 ll_rw_block(READA, num, bha);
145 for (i=0; i<num; i++) 145 for (i = 0; i < num; i++)
146 brelse(bha[i]); 146 brelse(bha[i]);
147 } 147 }
148 } 148 }
149 } 149 } else if (fibh->sbh != fibh->ebh) {
150 else if (fibh->sbh != fibh->ebh)
151 {
152 brelse(fibh->sbh); 150 brelse(fibh->sbh);
153 fibh->sbh = fibh->ebh; 151 fibh->sbh = fibh->ebh;
154 } 152 }
155 153
156 fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize, 154 fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize,
157 &(fibh->eoffset)); 155 &(fibh->eoffset));
158 156
159 if (!fi) 157 if (!fi)
160 return NULL; 158 return NULL;
161 159
162 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 160 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
163 161
164 if (fibh->eoffset <= dir->i_sb->s_blocksize) 162 if (fibh->eoffset <= dir->i_sb->s_blocksize) {
165 { 163 memcpy((uint8_t *) cfi, (uint8_t *) fi,
166 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc)); 164 sizeof(struct fileIdentDesc));
167 } 165 } else if (fibh->eoffset > dir->i_sb->s_blocksize) {
168 else if (fibh->eoffset > dir->i_sb->s_blocksize)
169 {
170 int lextoffset = epos->offset; 166 int lextoffset = epos->offset;
171 167
172 if (udf_next_aext(dir, epos, eloc, elen, 1) != 168 if (udf_next_aext(dir, epos, eloc, elen, 1) !=
173 (EXT_RECORDED_ALLOCATED >> 30)) 169 (EXT_RECORDED_ALLOCATED >> 30))
174 return NULL; 170 return NULL;
175 171
176 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); 172 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
177 173
178 (*offset) ++; 174 (*offset)++;
179 175
180 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) 176 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
181 *offset = 0; 177 *offset = 0;
@@ -188,62 +184,62 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos,
188 if (!(fibh->ebh = udf_tread(dir->i_sb, block))) 184 if (!(fibh->ebh = udf_tread(dir->i_sb, block)))
189 return NULL; 185 return NULL;
190 186
191 if (sizeof(struct fileIdentDesc) > - fibh->soffset) 187 if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
192 {
193 int fi_len; 188 int fi_len;
194 189
195 memcpy((uint8_t *)cfi, (uint8_t *)fi, - fibh->soffset); 190 memcpy((uint8_t *) cfi, (uint8_t *) fi, -fibh->soffset);
196 memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, 191 memcpy((uint8_t *) cfi - fibh->soffset,
197 sizeof(struct fileIdentDesc) + fibh->soffset); 192 fibh->ebh->b_data,
193 sizeof(struct fileIdentDesc) + fibh->soffset);
198 194
199 fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + 195 fi_len =
200 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; 196 (sizeof(struct fileIdentDesc) +
197 cfi->lengthFileIdent +
198 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
201 199
202 *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); 200 *nf_pos +=
201 ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2);
203 fibh->eoffset = fibh->soffset + fi_len; 202 fibh->eoffset = fibh->soffset + fi_len;
204 } 203 } else {
205 else 204 memcpy((uint8_t *) cfi, (uint8_t *) fi,
206 { 205 sizeof(struct fileIdentDesc));
207 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
208 } 206 }
209 } 207 }
210 return fi; 208 return fi;
211} 209}
212 210
213struct fileIdentDesc * 211struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
214udf_get_fileident(void * buffer, int bufsize, int * offset)
215{ 212{
216 struct fileIdentDesc *fi; 213 struct fileIdentDesc *fi;
217 int lengthThisIdent; 214 int lengthThisIdent;
218 uint8_t * ptr; 215 uint8_t *ptr;
219 int padlen; 216 int padlen;
220 217
221 if ( (!buffer) || (!offset) ) { 218 if ((!buffer) || (!offset)) {
222 udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, offset); 219 udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer,
220 offset);
223 return NULL; 221 return NULL;
224 } 222 }
225 223
226 ptr = buffer; 224 ptr = buffer;
227 225
228 if ( (*offset > 0) && (*offset < bufsize) ) { 226 if ((*offset > 0) && (*offset < bufsize)) {
229 ptr += *offset; 227 ptr += *offset;
230 } 228 }
231 fi=(struct fileIdentDesc *)ptr; 229 fi = (struct fileIdentDesc *)ptr;
232 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) 230 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) {
233 {
234 udf_debug("0x%x != TAG_IDENT_FID\n", 231 udf_debug("0x%x != TAG_IDENT_FID\n",
235 le16_to_cpu(fi->descTag.tagIdent)); 232 le16_to_cpu(fi->descTag.tagIdent));
236 udf_debug("offset: %u sizeof: %lu bufsize: %u\n", 233 udf_debug("offset: %u sizeof: %lu bufsize: %u\n",
237 *offset, (unsigned long)sizeof(struct fileIdentDesc), bufsize); 234 *offset, (unsigned long)sizeof(struct fileIdentDesc),
235 bufsize);
238 return NULL; 236 return NULL;
239 } 237 }
240 if ( (*offset + sizeof(struct fileIdentDesc)) > bufsize ) 238 if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) {
241 {
242 lengthThisIdent = sizeof(struct fileIdentDesc); 239 lengthThisIdent = sizeof(struct fileIdentDesc);
243 } 240 } else
244 else
245 lengthThisIdent = sizeof(struct fileIdentDesc) + 241 lengthThisIdent = sizeof(struct fileIdentDesc) +
246 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); 242 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
247 243
248 /* we need to figure padding, too! */ 244 /* we need to figure padding, too! */
249 padlen = lengthThisIdent % UDF_NAME_PAD; 245 padlen = lengthThisIdent % UDF_NAME_PAD;
@@ -255,56 +251,53 @@ udf_get_fileident(void * buffer, int bufsize, int * offset)
255} 251}
256 252
257#if 0 253#if 0
258static extent_ad * 254static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
259udf_get_fileextent(void * buffer, int bufsize, int * offset)
260{ 255{
261 extent_ad * ext; 256 extent_ad *ext;
262 struct fileEntry *fe; 257 struct fileEntry *fe;
263 uint8_t * ptr; 258 uint8_t *ptr;
264 259
265 if ( (!buffer) || (!offset) ) 260 if ((!buffer) || (!offset)) {
266 {
267 printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n"); 261 printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n");
268 return NULL; 262 return NULL;
269 } 263 }
270 264
271 fe = (struct fileEntry *)buffer; 265 fe = (struct fileEntry *)buffer;
272 266
273 if ( le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE ) 267 if (le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE) {
274 {
275 udf_debug("0x%x != TAG_IDENT_FE\n", 268 udf_debug("0x%x != TAG_IDENT_FE\n",
276 le16_to_cpu(fe->descTag.tagIdent)); 269 le16_to_cpu(fe->descTag.tagIdent));
277 return NULL; 270 return NULL;
278 } 271 }
279 272
280 ptr=(uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr); 273 ptr =
274 (uint8_t *) (fe->extendedAttr) +
275 le32_to_cpu(fe->lengthExtendedAttr);
281 276
282 if ( (*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)) ) 277 if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) {
283 {
284 ptr += *offset; 278 ptr += *offset;
285 } 279 }
286 280
287 ext = (extent_ad *)ptr; 281 ext = (extent_ad *) ptr;
288 282
289 *offset = *offset + sizeof(extent_ad); 283 *offset = *offset + sizeof(extent_ad);
290 return ext; 284 return ext;
291} 285}
292#endif 286#endif
293 287
294short_ad * 288short_ad *udf_get_fileshortad(uint8_t * ptr, int maxoffset, int *offset,
295udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, int inc) 289 int inc)
296{ 290{
297 short_ad *sa; 291 short_ad *sa;
298 292
299 if ( (!ptr) || (!offset) ) 293 if ((!ptr) || (!offset)) {
300 {
301 printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n"); 294 printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n");
302 return NULL; 295 return NULL;
303 } 296 }
304 297
305 if ( (*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset) ) 298 if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset))
306 return NULL; 299 return NULL;
307 else if ((sa = (short_ad *)ptr)->extLength == 0) 300 else if ((sa = (short_ad *) ptr)->extLength == 0)
308 return NULL; 301 return NULL;
309 302
310 if (inc) 303 if (inc)
@@ -312,20 +305,18 @@ udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, int inc)
312 return sa; 305 return sa;
313} 306}
314 307
315long_ad * 308long_ad *udf_get_filelongad(uint8_t * ptr, int maxoffset, int *offset, int inc)
316udf_get_filelongad(uint8_t *ptr, int maxoffset, int * offset, int inc)
317{ 309{
318 long_ad *la; 310 long_ad *la;
319 311
320 if ( (!ptr) || (!offset) ) 312 if ((!ptr) || (!offset)) {
321 {
322 printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n"); 313 printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n");
323 return NULL; 314 return NULL;
324 } 315 }
325 316
326 if ( (*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset) ) 317 if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset))
327 return NULL; 318 return NULL;
328 else if ((la = (long_ad *)ptr)->extLength == 0) 319 else if ((la = (long_ad *) ptr)->extLength == 0)
329 return NULL; 320 return NULL;
330 321
331 if (inc) 322 if (inc)