[PATCH] add imacfb documentation and detection
[linux/fpc-iii.git] / fs / udf / directory.c
blobfe751a2a0e478d5debb692a7ae23d0c1dc750b6a
1 /*
2 * directory.c
4 * PURPOSE
5 * Directory related functions
7 * COPYRIGHT
8 * This file is distributed under the terms of the GNU General Public
9 * License (GPL). Copies of the GPL can be obtained from:
10 * ftp://prep.ai.mit.edu/pub/gnu/GPL
11 * Each contributing author retains all rights to their own work.
14 #include "udfdecl.h"
15 #include "udf_i.h"
17 #include <linux/fs.h>
18 #include <linux/string.h>
19 #include <linux/buffer_head.h>
21 #if 0
22 static uint8_t *
23 udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size,
24 kernel_lb_addr fe_loc, int *pos, int *offset,
25 struct buffer_head **bh, int *error)
27 int loffset = *offset;
28 int block;
29 uint8_t *ad;
30 int remainder;
32 *error = 0;
34 ad = (uint8_t *)(*bh)->b_data + *offset;
35 *offset += ad_size;
37 if (!ad)
39 udf_release_data(*bh);
40 *error = 1;
41 return NULL;
44 if (*offset == dir->i_sb->s_blocksize)
46 udf_release_data(*bh);
47 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
48 if (!block)
49 return NULL;
50 if (!(*bh = udf_tread(dir->i_sb, block)))
51 return NULL;
53 else if (*offset > dir->i_sb->s_blocksize)
55 ad = tmpad;
57 remainder = dir->i_sb->s_blocksize - loffset;
58 memcpy((uint8_t *)ad, (*bh)->b_data + loffset, remainder);
60 udf_release_data(*bh);
61 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
62 if (!block)
63 return NULL;
64 if (!((*bh) = udf_tread(dir->i_sb, block)))
65 return NULL;
67 memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder);
68 *offset = ad_size - remainder;
70 return ad;
72 #endif
74 struct fileIdentDesc *
75 udf_fileident_read(struct inode *dir, loff_t *nf_pos,
76 struct udf_fileident_bh *fibh,
77 struct fileIdentDesc *cfi,
78 kernel_lb_addr *bloc, uint32_t *extoffset,
79 kernel_lb_addr *eloc, uint32_t *elen,
80 uint32_t *offset, struct buffer_head **bh)
82 struct fileIdentDesc *fi;
83 int i, num, block;
84 struct buffer_head * tmp, * bha[16];
86 fibh->soffset = fibh->eoffset;
88 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
90 fi = udf_get_fileident(UDF_I_DATA(dir) -
91 (UDF_I_EFE(dir) ?
92 sizeof(struct extendedFileEntry) :
93 sizeof(struct fileEntry)),
94 dir->i_sb->s_blocksize, &(fibh->eoffset));
96 if (!fi)
97 return NULL;
99 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
101 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
103 return fi;
106 if (fibh->eoffset == dir->i_sb->s_blocksize)
108 int lextoffset = *extoffset;
110 if (udf_next_aext(dir, bloc, extoffset, eloc, elen, bh, 1) !=
111 (EXT_RECORDED_ALLOCATED >> 30))
113 return NULL;
116 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
118 (*offset) ++;
120 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
121 *offset = 0;
122 else
123 *extoffset = lextoffset;
125 udf_release_data(fibh->sbh);
126 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block)))
127 return NULL;
128 fibh->soffset = fibh->eoffset = 0;
130 if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9))-1)))
132 i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
133 if (i+*offset > (*elen >> dir->i_sb->s_blocksize_bits))
134 i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset;
135 for (num=0; i>0; i--)
137 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset+i);
138 tmp = udf_tgetblk(dir->i_sb, block);
139 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp))
140 bha[num++] = tmp;
141 else
142 brelse(tmp);
144 if (num)
146 ll_rw_block(READA, num, bha);
147 for (i=0; i<num; i++)
148 brelse(bha[i]);
152 else if (fibh->sbh != fibh->ebh)
154 udf_release_data(fibh->sbh);
155 fibh->sbh = fibh->ebh;
158 fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize,
159 &(fibh->eoffset));
161 if (!fi)
162 return NULL;
164 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
166 if (fibh->eoffset <= dir->i_sb->s_blocksize)
168 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
170 else if (fibh->eoffset > dir->i_sb->s_blocksize)
172 int lextoffset = *extoffset;
174 if (udf_next_aext(dir, bloc, extoffset, eloc, elen, bh, 1) !=
175 (EXT_RECORDED_ALLOCATED >> 30))
177 return NULL;
180 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
182 (*offset) ++;
184 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
185 *offset = 0;
186 else
187 *extoffset = lextoffset;
189 fibh->soffset -= dir->i_sb->s_blocksize;
190 fibh->eoffset -= dir->i_sb->s_blocksize;
192 if (!(fibh->ebh = udf_tread(dir->i_sb, block)))
193 return NULL;
195 if (sizeof(struct fileIdentDesc) > - fibh->soffset)
197 int fi_len;
199 memcpy((uint8_t *)cfi, (uint8_t *)fi, - fibh->soffset);
200 memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data,
201 sizeof(struct fileIdentDesc) + fibh->soffset);
203 fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent +
204 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
206 *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2);
207 fibh->eoffset = fibh->soffset + fi_len;
209 else
211 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
214 return fi;
217 struct fileIdentDesc *
218 udf_get_fileident(void * buffer, int bufsize, int * offset)
220 struct fileIdentDesc *fi;
221 int lengthThisIdent;
222 uint8_t * ptr;
223 int padlen;
225 if ( (!buffer) || (!offset) ) {
226 udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, offset);
227 return NULL;
230 ptr = buffer;
232 if ( (*offset > 0) && (*offset < bufsize) ) {
233 ptr += *offset;
235 fi=(struct fileIdentDesc *)ptr;
236 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID)
238 udf_debug("0x%x != TAG_IDENT_FID\n",
239 le16_to_cpu(fi->descTag.tagIdent));
240 udf_debug("offset: %u sizeof: %lu bufsize: %u\n",
241 *offset, (unsigned long)sizeof(struct fileIdentDesc), bufsize);
242 return NULL;
244 if ( (*offset + sizeof(struct fileIdentDesc)) > bufsize )
246 lengthThisIdent = sizeof(struct fileIdentDesc);
248 else
249 lengthThisIdent = sizeof(struct fileIdentDesc) +
250 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
252 /* we need to figure padding, too! */
253 padlen = lengthThisIdent % UDF_NAME_PAD;
254 if (padlen)
255 lengthThisIdent += (UDF_NAME_PAD - padlen);
256 *offset = *offset + lengthThisIdent;
258 return fi;
261 #if 0
262 static extent_ad *
263 udf_get_fileextent(void * buffer, int bufsize, int * offset)
265 extent_ad * ext;
266 struct fileEntry *fe;
267 uint8_t * ptr;
269 if ( (!buffer) || (!offset) )
271 printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n");
272 return NULL;
275 fe = (struct fileEntry *)buffer;
277 if ( le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE )
279 udf_debug("0x%x != TAG_IDENT_FE\n",
280 le16_to_cpu(fe->descTag.tagIdent));
281 return NULL;
284 ptr=(uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr);
286 if ( (*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)) )
288 ptr += *offset;
291 ext = (extent_ad *)ptr;
293 *offset = *offset + sizeof(extent_ad);
294 return ext;
296 #endif
298 short_ad *
299 udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, int inc)
301 short_ad *sa;
303 if ( (!ptr) || (!offset) )
305 printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n");
306 return NULL;
309 if ( (*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset) )
310 return NULL;
311 else if ((sa = (short_ad *)ptr)->extLength == 0)
312 return NULL;
314 if (inc)
315 *offset += sizeof(short_ad);
316 return sa;
319 long_ad *
320 udf_get_filelongad(uint8_t *ptr, int maxoffset, int * offset, int inc)
322 long_ad *la;
324 if ( (!ptr) || (!offset) )
326 printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n");
327 return NULL;
330 if ( (*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset) )
331 return NULL;
332 else if ((la = (long_ad *)ptr)->extLength == 0)
333 return NULL;
335 if (inc)
336 *offset += sizeof(long_ad);
337 return la;