2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* directory.c
|
|
|
|
*
|
|
|
|
* PURPOSE
|
|
|
|
* Directory related functions
|
|
|
|
*
|
|
|
|
* COPYRIGHT
|
|
|
|
* This file is distributed under the terms of the GNU General Public
|
|
|
|
* License (GPL). Copies of the GPL can be obtained from:
|
|
|
|
* ftp://prep.ai.mit.edu/pub/gnu/GPL
|
|
|
|
* Each contributing author retains all rights to their own work.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "udfdecl.h"
|
|
|
|
#include "udf_i.h"
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
|
|
|
|
#if 0
|
2008-02-08 13:20:36 +01:00
|
|
|
static uint8_t *udf_filead_read(struct inode *dir, uint8_t *tmpad,
|
2007-07-19 10:47:43 +02:00
|
|
|
uint8_t ad_size, kernel_lb_addr fe_loc,
|
|
|
|
int *pos, int *offset, struct buffer_head **bh,
|
|
|
|
int *error)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
int loffset = *offset;
|
|
|
|
int block;
|
|
|
|
uint8_t *ad;
|
|
|
|
int remainder;
|
|
|
|
|
|
|
|
*error = 0;
|
|
|
|
|
2007-07-21 13:37:18 +02:00
|
|
|
ad = (uint8_t *)(*bh)->b_data + *offset;
|
2005-04-17 00:20:36 +02:00
|
|
|
*offset += ad_size;
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if (!ad) {
|
2007-05-08 09:35:16 +02:00
|
|
|
brelse(*bh);
|
2005-04-17 00:20:36 +02:00
|
|
|
*error = 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if (*offset == dir->i_sb->s_blocksize) {
|
2007-05-08 09:35:16 +02:00
|
|
|
brelse(*bh);
|
2005-04-17 00:20:36 +02:00
|
|
|
block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
|
|
|
|
if (!block)
|
|
|
|
return NULL;
|
2008-02-08 13:20:36 +01:00
|
|
|
*bh = udf_tread(dir->i_sb, block);
|
|
|
|
if (!*bh)
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
2007-07-19 10:47:43 +02:00
|
|
|
} else if (*offset > dir->i_sb->s_blocksize) {
|
2005-04-17 00:20:36 +02:00
|
|
|
ad = tmpad;
|
|
|
|
|
|
|
|
remainder = dir->i_sb->s_blocksize - loffset;
|
2007-07-21 13:37:18 +02:00
|
|
|
memcpy((uint8_t *)ad, (*bh)->b_data + loffset, remainder);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-05-08 09:35:16 +02:00
|
|
|
brelse(*bh);
|
2005-04-17 00:20:36 +02:00
|
|
|
block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
|
|
|
|
if (!block)
|
|
|
|
return NULL;
|
2008-02-08 13:20:36 +01:00
|
|
|
(*bh) = udf_tread(dir->i_sb, block);
|
|
|
|
if (!*bh)
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
memcpy((uint8_t *)ad + remainder, (*bh)->b_data,
|
|
|
|
ad_size - remainder);
|
2005-04-17 00:20:36 +02:00
|
|
|
*offset = ad_size - remainder;
|
|
|
|
}
|
2007-07-21 13:37:18 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return ad;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
|
2007-07-19 10:47:43 +02:00
|
|
|
struct udf_fileident_bh *fibh,
|
|
|
|
struct fileIdentDesc *cfi,
|
|
|
|
struct extent_position *epos,
|
2008-02-08 13:20:36 +01:00
|
|
|
kernel_lb_addr *eloc, uint32_t *elen,
|
|
|
|
sector_t *offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct fileIdentDesc *fi;
|
|
|
|
int i, num, block;
|
2007-07-19 10:47:43 +02:00
|
|
|
struct buffer_head *tmp, *bha[16];
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
fibh->soffset = fibh->eoffset;
|
|
|
|
|
2008-02-08 13:20:42 +01:00
|
|
|
if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
|
|
|
|
fi = udf_get_fileident(UDF_I(dir)->i_ext.i_data -
|
|
|
|
(UDF_I(dir)->i_efe ?
|
2007-07-19 10:47:43 +02:00
|
|
|
sizeof(struct extendedFileEntry) :
|
|
|
|
sizeof(struct fileEntry)),
|
2008-02-08 13:20:36 +01:00
|
|
|
dir->i_sb->s_blocksize,
|
|
|
|
&(fibh->eoffset));
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!fi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
|
|
|
|
|
2007-07-21 13:37:18 +02:00
|
|
|
memcpy((uint8_t *)cfi, (uint8_t *)fi,
|
2007-07-19 10:47:43 +02:00
|
|
|
sizeof(struct fileIdentDesc));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return fi;
|
|
|
|
}
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if (fibh->eoffset == dir->i_sb->s_blocksize) {
|
2007-05-08 09:35:14 +02:00
|
|
|
int lextoffset = epos->offset;
|
2008-02-08 13:20:36 +01:00
|
|
|
unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-05-08 09:35:14 +02:00
|
|
|
if (udf_next_aext(dir, epos, eloc, elen, 1) !=
|
2007-07-19 10:47:43 +02:00
|
|
|
(EXT_RECORDED_ALLOCATED >> 30))
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
(*offset)++;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
if ((*offset << blocksize_bits) >= *elen)
|
2005-04-17 00:20:36 +02:00
|
|
|
*offset = 0;
|
|
|
|
else
|
2007-05-08 09:35:14 +02:00
|
|
|
epos->offset = lextoffset;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-05-08 09:35:16 +02:00
|
|
|
brelse(fibh->sbh);
|
2008-02-08 13:20:36 +01:00
|
|
|
fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
|
|
|
|
if (!fibh->sbh)
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
fibh->soffset = fibh->eoffset = 0;
|
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) {
|
|
|
|
i = 16 >> (blocksize_bits - 9);
|
|
|
|
if (i + *offset > (*elen >> blocksize_bits))
|
|
|
|
i = (*elen >> blocksize_bits)-*offset;
|
2007-07-19 10:47:43 +02:00
|
|
|
for (num = 0; i > 0; i--) {
|
2008-02-08 13:20:36 +01:00
|
|
|
block = udf_get_lb_pblock(dir->i_sb, *eloc,
|
|
|
|
*offset + i);
|
2005-04-17 00:20:36 +02:00
|
|
|
tmp = udf_tgetblk(dir->i_sb, block);
|
2008-02-08 13:20:36 +01:00
|
|
|
if (tmp && !buffer_uptodate(tmp) &&
|
|
|
|
!buffer_locked(tmp))
|
2005-04-17 00:20:36 +02:00
|
|
|
bha[num++] = tmp;
|
|
|
|
else
|
|
|
|
brelse(tmp);
|
|
|
|
}
|
2007-07-19 10:47:43 +02:00
|
|
|
if (num) {
|
2005-04-17 00:20:36 +02:00
|
|
|
ll_rw_block(READA, num, bha);
|
2007-07-19 10:47:43 +02:00
|
|
|
for (i = 0; i < num; i++)
|
2005-04-17 00:20:36 +02:00
|
|
|
brelse(bha[i]);
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 10:47:43 +02:00
|
|
|
} else if (fibh->sbh != fibh->ebh) {
|
2007-05-08 09:35:16 +02:00
|
|
|
brelse(fibh->sbh);
|
2005-04-17 00:20:36 +02:00
|
|
|
fibh->sbh = fibh->ebh;
|
|
|
|
}
|
|
|
|
|
|
|
|
fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize,
|
2007-07-19 10:47:43 +02:00
|
|
|
&(fibh->eoffset));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (!fi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if (fibh->eoffset <= dir->i_sb->s_blocksize) {
|
2007-07-21 13:37:18 +02:00
|
|
|
memcpy((uint8_t *)cfi, (uint8_t *)fi,
|
2007-07-19 10:47:43 +02:00
|
|
|
sizeof(struct fileIdentDesc));
|
|
|
|
} else if (fibh->eoffset > dir->i_sb->s_blocksize) {
|
2007-05-08 09:35:14 +02:00
|
|
|
int lextoffset = epos->offset;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-05-08 09:35:14 +02:00
|
|
|
if (udf_next_aext(dir, epos, eloc, elen, 1) !=
|
2007-07-19 10:47:43 +02:00
|
|
|
(EXT_RECORDED_ALLOCATED >> 30))
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
(*offset)++;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
|
|
|
|
*offset = 0;
|
|
|
|
else
|
2007-05-08 09:35:14 +02:00
|
|
|
epos->offset = lextoffset;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
fibh->soffset -= dir->i_sb->s_blocksize;
|
|
|
|
fibh->eoffset -= dir->i_sb->s_blocksize;
|
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
fibh->ebh = udf_tread(dir->i_sb, block);
|
|
|
|
if (!fibh->ebh)
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
|
2005-04-17 00:20:36 +02:00
|
|
|
int fi_len;
|
|
|
|
|
2007-07-21 13:37:18 +02:00
|
|
|
memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset);
|
2008-02-08 13:20:36 +01:00
|
|
|
memcpy((uint8_t *)cfi - fibh->soffset,
|
|
|
|
fibh->ebh->b_data,
|
2007-07-19 10:47:43 +02:00
|
|
|
sizeof(struct fileIdentDesc) + fibh->soffset);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
fi_len = (sizeof(struct fileIdentDesc) +
|
|
|
|
cfi->lengthFileIdent +
|
2007-07-21 13:37:18 +02:00
|
|
|
le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
*nf_pos += (fi_len - (fibh->eoffset - fibh->soffset))
|
|
|
|
>> 2;
|
2005-04-17 00:20:36 +02:00
|
|
|
fibh->eoffset = fibh->soffset + fi_len;
|
2007-07-19 10:47:43 +02:00
|
|
|
} else {
|
2007-07-21 13:37:18 +02:00
|
|
|
memcpy((uint8_t *)cfi, (uint8_t *)fi,
|
2007-07-19 10:47:43 +02:00
|
|
|
sizeof(struct fileIdentDesc));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return fi;
|
|
|
|
}
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct fileIdentDesc *fi;
|
|
|
|
int lengthThisIdent;
|
2007-07-19 10:47:43 +02:00
|
|
|
uint8_t *ptr;
|
2005-04-17 00:20:36 +02:00
|
|
|
int padlen;
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if ((!buffer) || (!offset)) {
|
|
|
|
udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer,
|
|
|
|
offset);
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = buffer;
|
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
if ((*offset > 0) && (*offset < bufsize))
|
2005-04-17 00:20:36 +02:00
|
|
|
ptr += *offset;
|
2007-07-19 10:47:43 +02:00
|
|
|
fi = (struct fileIdentDesc *)ptr;
|
2008-02-08 13:20:41 +01:00
|
|
|
if (fi->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
udf_debug("0x%x != TAG_IDENT_FID\n",
|
2007-07-19 10:47:43 +02:00
|
|
|
le16_to_cpu(fi->descTag.tagIdent));
|
2005-04-17 00:20:36 +02:00
|
|
|
udf_debug("offset: %u sizeof: %lu bufsize: %u\n",
|
2007-07-19 10:47:43 +02:00
|
|
|
*offset, (unsigned long)sizeof(struct fileIdentDesc),
|
|
|
|
bufsize);
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-08 13:20:36 +01:00
|
|
|
if ((*offset + sizeof(struct fileIdentDesc)) > bufsize)
|
2005-04-17 00:20:36 +02:00
|
|
|
lengthThisIdent = sizeof(struct fileIdentDesc);
|
2008-02-08 13:20:36 +01:00
|
|
|
else
|
2005-04-17 00:20:36 +02:00
|
|
|
lengthThisIdent = sizeof(struct fileIdentDesc) +
|
2007-07-21 13:37:18 +02:00
|
|
|
fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* we need to figure padding, too! */
|
|
|
|
padlen = lengthThisIdent % UDF_NAME_PAD;
|
|
|
|
if (padlen)
|
|
|
|
lengthThisIdent += (UDF_NAME_PAD - padlen);
|
|
|
|
*offset = *offset + lengthThisIdent;
|
|
|
|
|
|
|
|
return fi;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2007-07-19 10:47:43 +02:00
|
|
|
static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-07-19 10:47:43 +02:00
|
|
|
extent_ad *ext;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct fileEntry *fe;
|
2007-07-19 10:47:43 +02:00
|
|
|
uint8_t *ptr;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if ((!buffer) || (!offset)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fe = (struct fileEntry *)buffer;
|
|
|
|
|
2008-02-08 13:20:41 +01:00
|
|
|
if (fe->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FE)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
udf_debug("0x%x != TAG_IDENT_FE\n",
|
2007-07-19 10:47:43 +02:00
|
|
|
le16_to_cpu(fe->descTag.tagIdent));
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
ptr = (uint8_t *)(fe->extendedAttr) +
|
|
|
|
le32_to_cpu(fe->lengthExtendedAttr);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-02-08 13:20:36 +01:00
|
|
|
if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)))
|
2005-04-17 00:20:36 +02:00
|
|
|
ptr += *offset;
|
|
|
|
|
2007-07-21 13:37:18 +02:00
|
|
|
ext = (extent_ad *)ptr;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
*offset = *offset + sizeof(extent_ad);
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-21 13:37:18 +02:00
|
|
|
short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset,
|
2007-07-19 10:47:43 +02:00
|
|
|
int inc)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
short_ad *sa;
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if ((!ptr) || (!offset)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset))
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
2008-02-08 13:20:36 +01:00
|
|
|
else {
|
|
|
|
sa = (short_ad *)ptr;
|
|
|
|
if (sa->extLength == 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (inc)
|
|
|
|
*offset += sizeof(short_ad);
|
|
|
|
return sa;
|
|
|
|
}
|
|
|
|
|
2007-07-21 13:37:18 +02:00
|
|
|
long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
long_ad *la;
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if ((!ptr) || (!offset)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-19 10:47:43 +02:00
|
|
|
if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset))
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
2008-02-08 13:20:36 +01:00
|
|
|
else {
|
|
|
|
la = (long_ad *)ptr;
|
|
|
|
if (la->extLength == 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (inc)
|
|
|
|
*offset += sizeof(long_ad);
|
|
|
|
return la;
|
|
|
|
}
|