5 * Directory related functions
8 * E-mail regarding any portion of the Linux UDF file system should be
9 * directed to the development team mailing list (run by majordomo):
10 * linux_udf@hpesjro.fc.hp.com
13 * This file is distributed under the terms of the GNU General Public
14 * License (GPL). Copies of the GPL can be obtained from:
15 * ftp://prep.ai.mit.edu/pub/gnu/GPL
16 * Each contributing author retains all rights to their own work.
23 #include <linux/string.h>
24 #include <linux/buffer_head.h>
26 uint8_t * udf_filead_read(struct inode *dir, uint8_t *tmpad, uint8_t ad_size,
27 lb_addr fe_loc, int *pos, int *offset, struct buffer_head **bh, int *error)
29 int loffset = *offset;
36 ad = (uint8_t *)(*bh)->b_data + *offset;
41 udf_release_data(*bh);
46 if (*offset == dir->i_sb->s_blocksize)
48 udf_release_data(*bh);
49 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
52 if (!(*bh = udf_tread(dir->i_sb, block)))
55 else if (*offset > dir->i_sb->s_blocksize)
59 remainder = dir->i_sb->s_blocksize - loffset;
60 memcpy((uint8_t *)ad, (*bh)->b_data + loffset, remainder);
62 udf_release_data(*bh);
63 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
66 if (!((*bh) = udf_tread(dir->i_sb, block)))
69 memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder);
70 *offset = ad_size - remainder;
75 struct fileIdentDesc *
76 udf_fileident_read(struct inode *dir, loff_t *nf_pos,
77 struct udf_fileident_bh *fibh,
78 struct fileIdentDesc *cfi,
79 lb_addr *bloc, uint32_t *extoffset,
80 lb_addr *eloc, uint32_t *elen,
81 uint32_t *offset, struct buffer_head **bh)
83 struct fileIdentDesc *fi;
85 struct buffer_head * tmp, * bha[16];
87 fibh->soffset = fibh->eoffset;
89 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
91 fi = udf_get_fileident(UDF_I_DATA(dir) -
93 sizeof(struct extendedFileEntry) :
94 sizeof(struct fileEntry)),
95 dir->i_sb->s_blocksize, &(fibh->eoffset));
100 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
102 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
107 if (fibh->eoffset == dir->i_sb->s_blocksize)
109 int lextoffset = *extoffset;
111 if (udf_next_aext(dir, bloc, extoffset, eloc, elen, bh, 1) !=
112 (EXT_RECORDED_ALLOCATED >> 30))
117 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
121 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
124 *extoffset = lextoffset;
126 udf_release_data(fibh->sbh);
127 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block)))
129 fibh->soffset = fibh->eoffset = 0;
131 if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9))-1)))
133 i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
134 if (i+*offset > (*elen >> dir->i_sb->s_blocksize_bits))
135 i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset;
136 for (num=0; i>0; i--)
138 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset+i);
139 tmp = udf_tgetblk(dir->i_sb, block);
140 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp))
147 ll_rw_block(READA, num, bha);
148 for (i=0; i<num; i++)
153 else if (fibh->sbh != fibh->ebh)
155 udf_release_data(fibh->sbh);
156 fibh->sbh = fibh->ebh;
159 fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize,
165 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
167 if (fibh->eoffset <= dir->i_sb->s_blocksize)
169 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
171 else if (fibh->eoffset > dir->i_sb->s_blocksize)
173 int lextoffset = *extoffset;
175 if (udf_next_aext(dir, bloc, extoffset, eloc, elen, bh, 1) !=
176 (EXT_RECORDED_ALLOCATED >> 30))
181 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
185 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
188 *extoffset = lextoffset;
190 fibh->soffset -= dir->i_sb->s_blocksize;
191 fibh->eoffset -= dir->i_sb->s_blocksize;
193 if (!(fibh->ebh = udf_tread(dir->i_sb, block)))
196 if (sizeof(struct fileIdentDesc) > - fibh->soffset)
200 memcpy((uint8_t *)cfi, (uint8_t *)fi, - fibh->soffset);
201 memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data,
202 sizeof(struct fileIdentDesc) + fibh->soffset);
204 fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent +
205 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
207 *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2);
208 fibh->eoffset = fibh->soffset + fi_len;
212 memcpy((uint8_t *)cfi, (uint8_t *)fi, sizeof(struct fileIdentDesc));
218 struct fileIdentDesc *
219 udf_get_fileident(void * buffer, int bufsize, int * offset)
221 struct fileIdentDesc *fi;
226 if ( (!buffer) || (!offset) ) {
227 udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, offset);
233 if ( (*offset > 0) && (*offset < bufsize) ) {
236 fi=(struct fileIdentDesc *)ptr;
237 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID)
239 udf_debug("0x%x != TAG_IDENT_FID\n",
240 le16_to_cpu(fi->descTag.tagIdent));
241 udf_debug("offset: %u sizeof: %lu bufsize: %u\n",
242 *offset, (unsigned long)sizeof(struct fileIdentDesc), bufsize);
245 if ( (*offset + sizeof(struct fileIdentDesc)) > bufsize )
247 lengthThisIdent = sizeof(struct fileIdentDesc);
250 lengthThisIdent = sizeof(struct fileIdentDesc) +
251 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
253 /* we need to figure padding, too! */
254 padlen = lengthThisIdent % UDF_NAME_PAD;
256 lengthThisIdent += (UDF_NAME_PAD - padlen);
257 *offset = *offset + lengthThisIdent;
263 udf_get_fileextent(void * buffer, int bufsize, int * offset)
266 struct fileEntry *fe;
269 if ( (!buffer) || (!offset) )
271 printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n");
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));
284 ptr=(uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr);
286 if ( (*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)) )
291 ext = (extent_ad *)ptr;
293 *offset = *offset + sizeof(extent_ad);
298 udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, int inc)
302 if ( (!ptr) || (!offset) )
304 printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n");
308 if ( (*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset) )
310 else if ((sa = (short_ad *)ptr)->extLength == 0)
314 *offset += sizeof(short_ad);
319 udf_get_filelongad(uint8_t *ptr, int maxoffset, int * offset, int inc)
323 if ( (!ptr) || (!offset) )
325 printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n");
329 if ( (*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset) )
331 else if ((la = (long_ad *)ptr)->extLength == 0)
335 *offset += sizeof(long_ad);