Commit 4b11111a authored by Marcin Slusarz's avatar Marcin Slusarz Committed by Linus Torvalds

udf: fix coding style

fix coding style errors found by checkpatch:
- assignments in if conditions
- braces {} around single statement blocks
- no spaces after commas
- printks without KERN_*
- lines longer than 80 characters
- spaces between "type *" and variable name

before: 192 errors, 561 warnings, 8987 lines checked
after: 1 errors, 38 warnings, 9468 lines checked
Signed-off-by: default avatarMarcin Slusarz <marcin.slusarz@gmail.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bd45a420
This diff is collapsed.
...@@ -79,7 +79,7 @@ static uint16_t crc_table[256] = { ...@@ -79,7 +79,7 @@ static uint16_t crc_table[256] = {
* July 21, 1997 - Andrew E. Mileski * July 21, 1997 - Andrew E. Mileski
* Adapted from OSTA-UDF(tm) 1.50 standard. * Adapted from OSTA-UDF(tm) 1.50 standard.
*/ */
uint16_t udf_crc(uint8_t * data, uint32_t size, uint16_t crc) uint16_t udf_crc(uint8_t *data, uint32_t size, uint16_t crc)
{ {
while (size--) while (size--)
crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8); crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#if 0 #if 0
static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, static uint8_t *udf_filead_read(struct inode *dir, uint8_t *tmpad,
uint8_t ad_size, kernel_lb_addr fe_loc, uint8_t ad_size, kernel_lb_addr fe_loc,
int *pos, int *offset, struct buffer_head **bh, int *pos, int *offset, struct buffer_head **bh,
int *error) int *error)
...@@ -45,7 +45,8 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, ...@@ -45,7 +45,8 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
if (!block) if (!block)
return NULL; return NULL;
if (!(*bh = udf_tread(dir->i_sb, block))) *bh = udf_tread(dir->i_sb, block);
if (!*bh)
return NULL; return NULL;
} else if (*offset > dir->i_sb->s_blocksize) { } else if (*offset > dir->i_sb->s_blocksize) {
ad = tmpad; ad = tmpad;
...@@ -57,10 +58,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, ...@@ -57,10 +58,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
if (!block) if (!block)
return NULL; return NULL;
if (!((*bh) = udf_tread(dir->i_sb, block))) (*bh) = udf_tread(dir->i_sb, block);
if (!*bh)
return NULL; return NULL;
memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder); memcpy((uint8_t *)ad + remainder, (*bh)->b_data,
ad_size - remainder);
*offset = ad_size - remainder; *offset = ad_size - remainder;
} }
...@@ -68,12 +71,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, ...@@ -68,12 +71,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
} }
#endif #endif
struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
struct udf_fileident_bh *fibh, struct udf_fileident_bh *fibh,
struct fileIdentDesc *cfi, struct fileIdentDesc *cfi,
struct extent_position *epos, struct extent_position *epos,
kernel_lb_addr * eloc, uint32_t * elen, kernel_lb_addr *eloc, uint32_t *elen,
sector_t * offset) sector_t *offset)
{ {
struct fileIdentDesc *fi; struct fileIdentDesc *fi;
int i, num, block; int i, num, block;
...@@ -86,7 +89,8 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, ...@@ -86,7 +89,8 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
(UDF_I_EFE(dir) ? (UDF_I_EFE(dir) ?
sizeof(struct extendedFileEntry) : sizeof(struct extendedFileEntry) :
sizeof(struct fileEntry)), sizeof(struct fileEntry)),
dir->i_sb->s_blocksize, &(fibh->eoffset)); dir->i_sb->s_blocksize,
&(fibh->eoffset));
if (!fi) if (!fi)
return NULL; return NULL;
...@@ -100,6 +104,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, ...@@ -100,6 +104,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
if (fibh->eoffset == dir->i_sb->s_blocksize) { if (fibh->eoffset == dir->i_sb->s_blocksize) {
int lextoffset = epos->offset; int lextoffset = epos->offset;
unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits;
if (udf_next_aext(dir, epos, eloc, elen, 1) != if (udf_next_aext(dir, epos, eloc, elen, 1) !=
(EXT_RECORDED_ALLOCATED >> 30)) (EXT_RECORDED_ALLOCATED >> 30))
...@@ -109,24 +114,27 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, ...@@ -109,24 +114,27 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
(*offset)++; (*offset)++;
if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) if ((*offset << blocksize_bits) >= *elen)
*offset = 0; *offset = 0;
else else
epos->offset = lextoffset; epos->offset = lextoffset;
brelse(fibh->sbh); brelse(fibh->sbh);
if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
if (!fibh->sbh)
return NULL; return NULL;
fibh->soffset = fibh->eoffset = 0; fibh->soffset = fibh->eoffset = 0;
if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) {
i = 16 >> (dir->i_sb->s_blocksize_bits - 9); i = 16 >> (blocksize_bits - 9);
if (i + *offset > (*elen >> dir->i_sb->s_blocksize_bits)) if (i + *offset > (*elen >> blocksize_bits))
i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; i = (*elen >> blocksize_bits)-*offset;
for (num = 0; i > 0; i--) { for (num = 0; i > 0; i--) {
block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset + i); block = udf_get_lb_pblock(dir->i_sb, *eloc,
*offset + i);
tmp = udf_tgetblk(dir->i_sb, block); tmp = udf_tgetblk(dir->i_sb, block);
if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) if (tmp && !buffer_uptodate(tmp) &&
!buffer_locked(tmp))
bha[num++] = tmp; bha[num++] = tmp;
else else
brelse(tmp); brelse(tmp);
...@@ -172,20 +180,24 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, ...@@ -172,20 +180,24 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
fibh->soffset -= dir->i_sb->s_blocksize; fibh->soffset -= dir->i_sb->s_blocksize;
fibh->eoffset -= dir->i_sb->s_blocksize; fibh->eoffset -= dir->i_sb->s_blocksize;
if (!(fibh->ebh = udf_tread(dir->i_sb, block))) fibh->ebh = udf_tread(dir->i_sb, block);
if (!fibh->ebh)
return NULL; return NULL;
if (sizeof(struct fileIdentDesc) > -fibh->soffset) { if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
int fi_len; int fi_len;
memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset);
memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, memcpy((uint8_t *)cfi - fibh->soffset,
fibh->ebh->b_data,
sizeof(struct fileIdentDesc) + fibh->soffset); sizeof(struct fileIdentDesc) + fibh->soffset);
fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + fi_len = (sizeof(struct fileIdentDesc) +
cfi->lengthFileIdent +
le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
*nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); *nf_pos += (fi_len - (fibh->eoffset - fibh->soffset))
>> 2;
fibh->eoffset = fibh->soffset + fi_len; fibh->eoffset = fibh->soffset + fi_len;
} else { } else {
memcpy((uint8_t *)cfi, (uint8_t *)fi, memcpy((uint8_t *)cfi, (uint8_t *)fi,
...@@ -210,9 +222,8 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) ...@@ -210,9 +222,8 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
ptr = buffer; ptr = buffer;
if ((*offset > 0) && (*offset < bufsize)) { if ((*offset > 0) && (*offset < bufsize))
ptr += *offset; ptr += *offset;
}
fi = (struct fileIdentDesc *)ptr; fi = (struct fileIdentDesc *)ptr;
if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) { if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) {
udf_debug("0x%x != TAG_IDENT_FID\n", udf_debug("0x%x != TAG_IDENT_FID\n",
...@@ -222,12 +233,11 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) ...@@ -222,12 +233,11 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
bufsize); bufsize);
return NULL; return NULL;
} }
if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) { if ((*offset + sizeof(struct fileIdentDesc)) > bufsize)
lengthThisIdent = sizeof(struct fileIdentDesc); lengthThisIdent = sizeof(struct fileIdentDesc);
} else { else
lengthThisIdent = sizeof(struct fileIdentDesc) + lengthThisIdent = sizeof(struct fileIdentDesc) +
fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
}
/* we need to figure padding, too! */ /* we need to figure padding, too! */
padlen = lengthThisIdent % UDF_NAME_PAD; padlen = lengthThisIdent % UDF_NAME_PAD;
...@@ -258,11 +268,11 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset) ...@@ -258,11 +268,11 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
return NULL; return NULL;
} }
ptr = (uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr); ptr = (uint8_t *)(fe->extendedAttr) +
le32_to_cpu(fe->lengthExtendedAttr);
if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) { if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)))
ptr += *offset; ptr += *offset;
}
ext = (extent_ad *)ptr; ext = (extent_ad *)ptr;
...@@ -283,8 +293,11 @@ short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, ...@@ -283,8 +293,11 @@ short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset,
if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset)) if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset))
return NULL; return NULL;
else if ((sa = (short_ad *)ptr)->extLength == 0) else {
return NULL; sa = (short_ad *)ptr;
if (sa->extLength == 0)
return NULL;
}
if (inc) if (inc)
*offset += sizeof(short_ad); *offset += sizeof(short_ad);
...@@ -302,8 +315,11 @@ long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc) ...@@ -302,8 +315,11 @@ long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc)
if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset)) if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset))
return NULL; return NULL;
else if ((la = (long_ad *)ptr)->extLength == 0) else {
return NULL; la = (long_ad *)ptr;
if (la->extLength == 0)
return NULL;
}
if (inc) if (inc)
*offset += sizeof(long_ad); *offset += sizeof(long_ad);
......
...@@ -59,7 +59,8 @@ static int udf_adinicb_readpage(struct file *file, struct page *page) ...@@ -59,7 +59,8 @@ static int udf_adinicb_readpage(struct file *file, struct page *page)
return 0; return 0;
} }
static int udf_adinicb_writepage(struct page *page, struct writeback_control *wbc) static int udf_adinicb_writepage(struct page *page,
struct writeback_control *wbc)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
char *kaddr; char *kaddr;
...@@ -116,7 +117,8 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -116,7 +117,8 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
else else
pos = ppos; pos = ppos;
if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + if (inode->i_sb->s_blocksize <
(udf_file_entry_alloc_offset(inode) +
pos + count)) { pos + count)) {
udf_expand_file_adinicb(inode, pos + count, &err); udf_expand_file_adinicb(inode, pos + count, &err);
if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) { if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
...@@ -191,15 +193,19 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, ...@@ -191,15 +193,19 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
switch (cmd) { switch (cmd) {
case UDF_GETVOLIDENT: case UDF_GETVOLIDENT:
return copy_to_user((char __user *)arg, if (copy_to_user((char __user *)arg,
UDF_SB(inode->i_sb)->s_volume_ident, 32) ? -EFAULT : 0; UDF_SB(inode->i_sb)->s_volume_ident, 32))
return -EFAULT;
else
return 0;
case UDF_RELOCATE_BLOCKS: case UDF_RELOCATE_BLOCKS:
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
if (get_user(old_block, (long __user *)arg)) if (get_user(old_block, (long __user *)arg))
return -EFAULT; return -EFAULT;
if ((result = udf_relocate_blocks(inode->i_sb, result = udf_relocate_blocks(inode->i_sb,
old_block, &new_block)) == 0) old_block, &new_block);
if (result == 0)
result = put_user(new_block, (long __user *)arg); result = put_user(new_block, (long __user *)arg);
return result; return result;
case UDF_GETEASIZE: case UDF_GETEASIZE:
......
...@@ -82,7 +82,8 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) ...@@ -82,7 +82,8 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
UDF_I_NEXT_ALLOC_GOAL(inode) = 0; UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
UDF_I_STRAT4096(inode) = 0; UDF_I_STRAT4096(inode) = 0;
block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum, block = udf_new_block(dir->i_sb, NULL,
UDF_I_LOCATION(dir).partitionReferenceNum,
start, err); start, err);
if (*err) { if (*err) {
iput(inode); iput(inode);
...@@ -91,11 +92,15 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) ...@@ -91,11 +92,15 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
mutex_lock(&sbi->s_alloc_mutex); mutex_lock(&sbi->s_alloc_mutex);
if (sbi->s_lvid_bh) { if (sbi->s_lvid_bh) {
struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; struct logicalVolIntegrityDesc *lvid =
struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi); (struct logicalVolIntegrityDesc *)
sbi->s_lvid_bh->b_data;
struct logicalVolIntegrityDescImpUse *lvidiu =
udf_sb_lvidiu(sbi);
struct logicalVolHeaderDesc *lvhd; struct logicalVolHeaderDesc *lvhd;
uint64_t uniqueID; uint64_t uniqueID;
lvhd = (struct logicalVolHeaderDesc *)(lvid->logicalVolContentsUse); lvhd = (struct logicalVolHeaderDesc *)
(lvid->logicalVolContentsUse);
if (S_ISDIR(mode)) if (S_ISDIR(mode))
lvidiu->numDirs = lvidiu->numDirs =
cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1); cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1);
...@@ -119,7 +124,8 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) ...@@ -119,7 +124,8 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
} }
UDF_I_LOCATION(inode).logicalBlockNum = block; UDF_I_LOCATION(inode).logicalBlockNum = block;
UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; UDF_I_LOCATION(inode).partitionReferenceNum =
UDF_I_LOCATION(dir).partitionReferenceNum;
inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0); inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0);
inode->i_blocks = 0; inode->i_blocks = 0;
UDF_I_LENEATTR(inode) = 0; UDF_I_LENEATTR(inode) = 0;
...@@ -129,10 +135,14 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err) ...@@ -129,10 +135,14 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
UDF_I_EFE(inode) = 1; UDF_I_EFE(inode) = 1;
if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev) if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE; sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL); UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize -
sizeof(struct extendedFileEntry),
GFP_KERNEL);
} else { } else {
UDF_I_EFE(inode) = 0; UDF_I_EFE(inode) = 0;
UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL); UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize -
sizeof(struct fileEntry),
GFP_KERNEL);
} }
if (!UDF_I_DATA(inode)) { if (!UDF_I_DATA(inode)) {
iput(inode); iput(inode);
......
This diff is collapsed.
...@@ -70,71 +70,84 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size, ...@@ -70,71 +70,84 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
struct extendedAttrHeaderDesc *eahd; struct extendedAttrHeaderDesc *eahd;
eahd = (struct extendedAttrHeaderDesc *)ea; eahd = (struct extendedAttrHeaderDesc *)ea;
if (UDF_I_LENALLOC(inode)) { if (UDF_I_LENALLOC(inode))
memmove(&ad[size], ad, UDF_I_LENALLOC(inode)); memmove(&ad[size], ad, UDF_I_LENALLOC(inode));
}
if (UDF_I_LENEATTR(inode)) { if (UDF_I_LENEATTR(inode)) {
/* check checksum/crc */ /* check checksum/crc */
if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || if (le16_to_cpu(eahd->descTag.tagIdent) !=
le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) { TAG_IDENT_EAHD ||
le32_to_cpu(eahd->descTag.tagLocation) !=
UDF_I_LOCATION(inode).logicalBlockNum)
return NULL; return NULL;
}
} else { } else {
struct udf_sb_info *sbi = UDF_SB(inode->i_sb); struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
size -= sizeof(struct extendedAttrHeaderDesc); size -= sizeof(struct extendedAttrHeaderDesc);
UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc); UDF_I_LENEATTR(inode) +=
sizeof(struct extendedAttrHeaderDesc);
eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD); eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD);
if (sbi->s_udfrev >= 0x0200) if (sbi->s_udfrev >= 0x0200)
eahd->descTag.descVersion = cpu_to_le16(3); eahd->descTag.descVersion = cpu_to_le16(3);
else else
eahd->descTag.descVersion = cpu_to_le16(2); eahd->descTag.descVersion = cpu_to_le16(2);
eahd->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number); eahd->descTag.tagSerialNum =
eahd->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); cpu_to_le16(sbi->s_serial_number);
eahd->descTag.tagLocation = cpu_to_le32(
UDF_I_LOCATION(inode).logicalBlockNum);
eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF); eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF);
eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF); eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF);
} }
offset = UDF_I_LENEATTR(inode); offset = UDF_I_LENEATTR(inode);
if (type < 2048) { if (type < 2048) {
if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) { if (le32_to_cpu(eahd->appAttrLocation) <
uint32_t aal = le32_to_cpu(eahd->appAttrLocation); UDF_I_LENEATTR(inode)) {
uint32_t aal =
le32_to_cpu(eahd->appAttrLocation);
memmove(&ea[offset - aal + size], memmove(&ea[offset - aal + size],
&ea[aal], offset - aal); &ea[aal], offset - aal);
offset -= aal; offset -= aal;
eahd->appAttrLocation = cpu_to_le32(aal + size); eahd->appAttrLocation =
cpu_to_le32(aal + size);
} }
if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) { if (le32_to_cpu(eahd->impAttrLocation) <
uint32_t ial = le32_to_cpu(eahd->impAttrLocation); UDF_I_LENEATTR(inode)) {
uint32_t ial =
le32_to_cpu(eahd->impAttrLocation);
memmove(&ea[offset - ial + size], memmove(&ea[offset - ial + size],
&ea[ial], offset - ial); &ea[ial], offset - ial);
offset -= ial; offset -= ial;
eahd->impAttrLocation = cpu_to_le32(ial + size); eahd->impAttrLocation =
cpu_to_le32(ial + size);
} }
} else if (type < 65536) { } else if (type < 65536) {
if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) { if (le32_to_cpu(eahd->appAttrLocation) <
uint32_t aal = le32_to_cpu(eahd->appAttrLocation); UDF_I_LENEATTR(inode)) {
uint32_t aal =
le32_to_cpu(eahd->appAttrLocation);
memmove(&ea[offset - aal + size], memmove(&ea[offset - aal + size],
&ea[aal], offset - aal); &ea[aal], offset - aal);
offset -= aal; offset -= aal;
eahd->appAttrLocation = cpu_to_le32(aal + size); eahd->appAttrLocation =
cpu_to_le32(aal + size);
} }
} }
/* rewrite CRC + checksum of eahd */ /* rewrite CRC + checksum of eahd */
crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag);
eahd->descTag.descCRCLength = cpu_to_le16(crclen); eahd->descTag.descCRCLength = cpu_to_le16(crclen);
eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd +
sizeof(tag), crclen, 0)); sizeof(tag), crclen, 0));
eahd->descTag.tagChecksum = 0; eahd->descTag.tagChecksum = 0;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
if (i != 4) if (i != 4)
eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i]; eahd->descTag.tagChecksum +=
((uint8_t *)&(eahd->descTag))[i];
UDF_I_LENEATTR(inode) += size; UDF_I_LENEATTR(inode) += size;
return (struct genericFormat *)&ea[offset]; return (struct genericFormat *)&ea[offset];
} }
if (loc & 0x02) { if (loc & 0x02)
} ;
return NULL; return NULL;
} }
...@@ -153,10 +166,11 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, ...@@ -153,10 +166,11 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
eahd = (struct extendedAttrHeaderDesc *)ea; eahd = (struct extendedAttrHeaderDesc *)ea;
/* check checksum/crc */ /* check checksum/crc */
if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD || if (le16_to_cpu(eahd->descTag.tagIdent) !=
le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) { TAG_IDENT_EAHD ||
le32_to_cpu(eahd->descTag.tagLocation) !=
UDF_I_LOCATION(inode).logicalBlockNum)
return NULL; return NULL;
}
if (type < 2048) if (type < 2048)
offset = sizeof(struct extendedAttrHeaderDesc); offset = sizeof(struct extendedAttrHeaderDesc);
...@@ -167,7 +181,8 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, ...@@ -167,7 +181,8 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
while (offset < UDF_I_LENEATTR(inode)) { while (offset < UDF_I_LENEATTR(inode)) {
gaf = (struct genericFormat *)&ea[offset]; gaf = (struct genericFormat *)&ea[offset];
if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype) if (le32_to_cpu(gaf->attrType) == type &&
gaf->attrSubtype == subtype)
return gaf; return gaf;
else else
offset += le32_to_cpu(gaf->attrLength); offset += le32_to_cpu(gaf->attrLength);
...@@ -188,7 +203,7 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, ...@@ -188,7 +203,7 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
* Written, tested, and released. * Written, tested, and released.
*/ */
struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
uint32_t location, uint16_t * ident) uint32_t location, uint16_t *ident)
{ {
tag *tag_p; tag *tag_p;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
...@@ -213,7 +228,8 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, ...@@ -213,7 +228,8 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
if (location != le32_to_cpu(tag_p->tagLocation)) { if (location != le32_to_cpu(tag_p->tagLocation)) {
udf_debug("location mismatch block %u, tag %u != %u\n", udf_debug("location mismatch block %u, tag %u != %u\n",
block + sbi->s_session, le32_to_cpu(tag_p->tagLocation), location); block + sbi->s_session,
le32_to_cpu(tag_p->tagLocation), location);
goto error_out; goto error_out;
} }
...@@ -239,9 +255,9 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, ...@@ -239,9 +255,9 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
/* Verify the descriptor CRC */ /* Verify the descriptor CRC */
if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize ||
le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag), le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
le16_to_cpu(tag_p->descCRCLength), 0)) { le16_to_cpu(tag_p->descCRCLength), 0))
return bh; return bh;
}
udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", udf_debug("Crc failure block %d: crc = %d, crclen = %d\n",
block + sbi->s_session, le16_to_cpu(tag_p->descCRC), block + sbi->s_session, le16_to_cpu(tag_p->descCRC),
le16_to_cpu(tag_p->descCRCLength)); le16_to_cpu(tag_p->descCRCLength));
...@@ -252,7 +268,7 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, ...@@ -252,7 +268,7 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
} }
struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc, struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc,
uint32_t offset, uint16_t * ident) uint32_t offset, uint16_t *ident)
{ {
return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset), return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset),
loc.logicalBlockNum + offset, ident); loc.logicalBlockNum + offset, ident);
......
This diff is collapsed.
...@@ -34,8 +34,8 @@ inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block, ...@@ -34,8 +34,8 @@ inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block,
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct udf_part_map *map; struct udf_part_map *map;
if (partition >= sbi->s_partitions) { if (partition >= sbi->s_partitions) {
udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n", udf_debug("block=%d, partition=%d, offset=%d: "
block, partition, offset); "invalid partition\n", block, partition, offset);
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
map = &sbi->s_partmaps[partition]; map = &sbi->s_partmaps[partition];
...@@ -54,13 +54,15 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, ...@@ -54,13 +54,15 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
uint32_t loc; uint32_t loc;
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct udf_part_map *map; struct udf_part_map *map;
struct udf_virtual_data *vdata;
map = &sbi->s_partmaps[partition]; map = &sbi->s_partmaps[partition];
index = (sb->s_blocksize - map->s_type_specific.s_virtual.s_start_offset) / sizeof(uint32_t); vdata = &map->s_type_specific.s_virtual;
index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t);
if (block > map->s_type_specific.s_virtual.s_num_entries) { if (block > vdata->s_num_entries) {
udf_debug("Trying to access block beyond end of VAT (%d max %d)\n", udf_debug("Trying to access block beyond end of VAT "
block, map->s_type_specific.s_virtual.s_num_entries); "(%d max %d)\n", block, vdata->s_num_entries);
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
...@@ -70,12 +72,13 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, ...@@ -70,12 +72,13 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
index = block % (sb->s_blocksize / sizeof(uint32_t)); index = block % (sb->s_blocksize / sizeof(uint32_t));
} else { } else {
newblock = 0; newblock = 0;
index = map->s_type_specific.s_virtual.s_start_offset / sizeof(uint32_t) + block; index = vdata->s_start_offset / sizeof(uint32_t) + block;
} }
loc = udf_block_map(sbi->s_vat_inode, newblock); loc = udf_block_map(sbi->s_vat_inode, newblock);
if (!(bh = sb_bread(sb, loc))) { bh = sb_bread(sb, loc);
if (!bh) {
udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n",
sb, block, partition, loc, index); sb, block, partition, loc, index);
return 0xFFFFFFFF; return 0xFFFFFFFF;
...@@ -85,17 +88,19 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, ...@@ -85,17 +88,19 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
brelse(bh); brelse(bh);
if (UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum == partition) { if (UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum ==
partition) {
udf_debug("recursive call to udf_get_pblock!\n"); udf_debug("recursive call to udf_get_pblock!\n");
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
return udf_get_pblock(sb, loc, return udf_get_pblock(sb, loc,
UDF_I_LOCATION(sbi->s_vat_inode).partitionReferenceNum, UDF_I_LOCATION(sbi->s_vat_inode).
partitionReferenceNum,
offset); offset);
} }
inline uint32_t udf_get_pblock_virt20(struct super_block * sb, uint32_t block, inline uint32_t udf_get_pblock_virt20(struct super_block *sb, uint32_t block,
uint16_t partition, uint32_t offset) uint16_t partition, uint32_t offset)
{ {
return udf_get_pblock_virt15(sb, block, partition, offset); return udf_get_pblock_virt15(sb, block, partition, offset);
...@@ -109,27 +114,32 @@ uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, ...@@ -109,27 +114,32 @@ uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block,
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct udf_part_map *map; struct udf_part_map *map;
uint32_t packet; uint32_t packet;
struct udf_sparing_data *sdata;
map = &sbi->s_partmaps[partition]; map = &sbi->s_partmaps[partition];
packet = (block + offset) & ~(map->s_type_specific.s_sparing.s_packet_len - 1); sdata = &map->s_type_specific.s_sparing;
packet = (block + offset) & ~(sdata->s_packet_len - 1);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (map->s_type_specific.s_sparing.s_spar_map[i] != NULL) { if (sdata->s_spar_map[i] != NULL) {
st = (struct sparingTable *)map->s_type_specific.s_sparing.s_spar_map[i]->b_data; st = (struct sparingTable *)
sdata->s_spar_map[i]->b_data;
break; break;
} }
} }
if (st) { if (st) {
for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) { for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) {
if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0) { struct sparingEntry *entry = &st->mapEntry[i];
u32 origLoc = le32_to_cpu(entry->origLocation);
if (origLoc >= 0xFFFFFFF0)
break; break;
} else if (le32_to_cpu(st->mapEntry[i].origLocation) == packet) { else if (origLoc == packet)
return le32_to_cpu(st->mapEntry[i].mappedLocation) + return le32_to_cpu(entry->mappedLocation) +
((block + offset) & (map->s_type_specific.s_sparing.s_packet_len - 1)); ((block + offset) &
} else if (le32_to_cpu(st->mapEntry[i].origLocation) > packet) { (sdata->s_packet_len - 1));
else if (origLoc > packet)
break; break;
}
} }
} }
...@@ -144,63 +154,101 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) ...@@ -144,63 +154,101 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
uint32_t packet; uint32_t packet;
int i, j, k, l; int i, j, k, l;
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
u16 reallocationTableLen;
struct buffer_head *bh;
for (i = 0; i < sbi->s_partitions; i++) { for (i = 0; i < sbi->s_partitions; i++) {
struct udf_part_map *map = &sbi->s_partmaps[i]; struct udf_part_map *map = &sbi->s_partmaps[i];
if (old_block > map->s_partition_root && if (old_block > map->s_partition_root &&
old_block < map->s_partition_root + map->s_partition_len) { old_block < map->s_partition_root + map->s_partition_len) {
sdata = &map->s_type_specific.s_sparing; sdata = &map->s_type_specific.s_sparing;
packet = (old_block - map->s_partition_root) & ~(sdata->s_packet_len - 1); packet = (old_block - map->s_partition_root) &
~(sdata->s_packet_len - 1);
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++)
if (map->s_type_specific.s_sparing.s_spar_map[j] != NULL) { if (sdata->s_spar_map[j] != NULL) {
st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; st = (struct sparingTable *)
sdata->s_spar_map[j]->b_data;
break; break;
} }
}
if (!st) if (!st)
return 1; return 1;
for (k = 0; k < le16_to_cpu(st->reallocationTableLen); k++) { reallocationTableLen =
if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) { le16_to_cpu(st->reallocationTableLen);
for (k = 0; k < reallocationTableLen; k++) {
struct sparingEntry *entry = &st->mapEntry[k];
u32 origLoc = le32_to_cpu(entry->origLocation);
if (origLoc == 0xFFFFFFFF) {
for (; j < 4; j++) { for (; j < 4; j++) {
if (sdata->s_spar_map[j]) { int len;
st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; bh = sdata->s_spar_map[j];
st->mapEntry[k].origLocation = cpu_to_le32(packet); if (!bh)
udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); continue;
mark_buffer_dirty(sdata->s_spar_map[j]);
} st = (struct sparingTable *)
bh->b_data;
entry->origLocation =
cpu_to_le32(packet);
len =
sizeof(struct sparingTable) +
reallocationTableLen *
sizeof(struct sparingEntry);
udf_update_tag((char *)st, len);
mark_buffer_dirty(bh);
} }
*new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + *new_block = le32_to_cpu(
((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); entry->mappedLocation) +
((old_block -
map->s_partition_root) &
(sdata->s_packet_len - 1));
return 0; return 0;
} else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet) { } else if (origLoc == packet) {
*new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + *new_block = le32_to_cpu(
((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); entry->mappedLocation) +
((old_block -
map->s_partition_root) &
(sdata->s_packet_len - 1));
return 0; return 0;
} else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) { } else if (origLoc > packet)
break; break;
}
} }
for (l = k; l < le16_to_cpu(st->reallocationTableLen); l++) { for (l = k; l < reallocationTableLen; l++) {
if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) { struct sparingEntry *entry = &st->mapEntry[l];
for (; j < 4; j++) { u32 origLoc = le32_to_cpu(entry->origLocation);
if (sdata->s_spar_map[j]) {
st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; if (origLoc != 0xFFFFFFFF)
mapEntry = st->mapEntry[l]; continue;
mapEntry.origLocation = cpu_to_le32(packet);
memmove(&st->mapEntry[k + 1], &st->mapEntry[k], (l - k) * sizeof(struct sparingEntry)); for (; j < 4; j++) {
st->mapEntry[k] = mapEntry; bh = sdata->s_spar_map[j];
udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); if (!bh)
mark_buffer_dirty(sdata->s_spar_map[j]); continue;
}
} st = (struct sparingTable *)bh->b_data;
*new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + mapEntry = st->mapEntry[l];
((old_block - map->s_partition_root) & (sdata->s_packet_len - 1)); mapEntry.origLocation =
return 0; cpu_to_le32(packet);
memmove(&st->mapEntry[k + 1],
&st->mapEntry[k],
(l - k) *
sizeof(struct sparingEntry));
st->mapEntry[k] = mapEntry;
udf_update_tag((char *)st,
sizeof(struct sparingTable) +
reallocationTableLen *
sizeof(struct sparingEntry));
mark_buffer_dirty(bh);
} }
*new_block =
le32_to_cpu(
st->mapEntry[k].mappedLocation) +
((old_block - map->s_partition_root) &
(sdata->s_packet_len - 1));
return 0;
} }
return 1; return 1;
......
This diff is collapsed.
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include "udf_i.h" #include "udf_i.h"
static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen, char *to) static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen,
char *to)
{ {
struct pathComponent *pc; struct pathComponent *pc;
int elen = 0; int elen = 0;
......
...@@ -154,7 +154,8 @@ void udf_discard_prealloc(struct inode *inode) ...@@ -154,7 +154,8 @@ void udf_discard_prealloc(struct inode *inode)
extent_trunc(inode, &epos, eloc, etype, elen, 0); extent_trunc(inode, &epos, eloc, etype, elen, 0);
if (!epos.bh) { if (!epos.bh) {
UDF_I_LENALLOC(inode) = UDF_I_LENALLOC(inode) =
epos.offset - udf_file_entry_alloc_offset(inode); epos.offset -
udf_file_entry_alloc_offset(inode);
mark_inode_dirty(inode); mark_inode_dirty(inode);
} else { } else {
struct allocExtDesc *aed = struct allocExtDesc *aed =
...@@ -213,7 +214,8 @@ void udf_truncate_extents(struct inode *inode) ...@@ -213,7 +214,8 @@ void udf_truncate_extents(struct inode *inode)
else else
lenalloc -= sizeof(struct allocExtDesc); lenalloc -= sizeof(struct allocExtDesc);
while ((etype = udf_current_aext(inode, &epos, &eloc, &elen, 0)) != -1) { while ((etype = udf_current_aext(inode, &epos, &eloc,
&elen, 0)) != -1) {
if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
udf_write_aext(inode, &epos, neloc, nelen, 0); udf_write_aext(inode, &epos, neloc, nelen, 0);
if (indirect_ext_len) { if (indirect_ext_len) {
...@@ -225,35 +227,43 @@ void udf_truncate_extents(struct inode *inode) ...@@ -225,35 +227,43 @@ void udf_truncate_extents(struct inode *inode)
0, indirect_ext_len); 0, indirect_ext_len);
} else { } else {
if (!epos.bh) { if (!epos.bh) {
UDF_I_LENALLOC(inode) = lenalloc; UDF_I_LENALLOC(inode) =
lenalloc;
mark_inode_dirty(inode); mark_inode_dirty(inode);
} else { } else {
struct allocExtDesc *aed = struct allocExtDesc *aed =
(struct allocExtDesc *)(epos.bh->b_data); (struct allocExtDesc *)
(epos.bh->b_data);
int len =
sizeof(struct allocExtDesc);
aed->lengthAllocDescs = aed->lengthAllocDescs =
cpu_to_le32(lenalloc); cpu_to_le32(lenalloc);
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || if (!UDF_QUERY_FLAG(sb,
UDF_FLAG_STRICT) ||
sbi->s_udfrev >= 0x0201) sbi->s_udfrev >= 0x0201)
udf_update_tag(epos.bh->b_data, len += lenalloc;
lenalloc +
sizeof(struct allocExtDesc)); udf_update_tag(epos.bh->b_data,
else len);
udf_update_tag(epos.bh->b_data, mark_buffer_dirty_inode(
sizeof(struct allocExtDesc)); epos.bh, inode);
mark_buffer_dirty_inode(epos.bh, inode);
} }
} }
brelse(epos.bh); brelse(epos.bh);
epos.offset = sizeof(struct allocExtDesc); epos.offset = sizeof(struct allocExtDesc);
epos.block = eloc; epos.block = eloc;
epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, eloc, 0)); epos.bh = udf_tread(sb,
udf_get_lb_pblock(sb, eloc, 0));
if (elen) if (elen)
indirect_ext_len = (elen + sb->s_blocksize -1) >> indirect_ext_len =
(elen + sb->s_blocksize - 1) >>
sb->s_blocksize_bits; sb->s_blocksize_bits;
else else
indirect_ext_len = 1; indirect_ext_len = 1;
} else { } else {
extent_trunc(inode, &epos, eloc, etype, elen, 0); extent_trunc(inode, &epos, eloc, etype,
elen, 0);
epos.offset += adsize; epos.offset += adsize;
} }
} }
...@@ -274,10 +284,11 @@ void udf_truncate_extents(struct inode *inode) ...@@ -274,10 +284,11 @@ void udf_truncate_extents(struct inode *inode)
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) ||
sbi->s_udfrev >= 0x0201) sbi->s_udfrev >= 0x0201)
udf_update_tag(epos.bh->b_data, udf_update_tag(epos.bh->b_data,
lenalloc + sizeof(struct allocExtDesc)); lenalloc +
sizeof(struct allocExtDesc));
else else
udf_update_tag(epos.bh->b_data, udf_update_tag(epos.bh->b_data,
sizeof(struct allocExtDesc)); sizeof(struct allocExtDesc));
mark_buffer_dirty_inode(epos.bh, inode); mark_buffer_dirty_inode(epos.bh, inode);
} }
} }
...@@ -291,13 +302,16 @@ void udf_truncate_extents(struct inode *inode) ...@@ -291,13 +302,16 @@ void udf_truncate_extents(struct inode *inode)
* extending the file by 'offset' blocks. * extending the file by 'offset' blocks.
*/ */
if ((!epos.bh && if ((!epos.bh &&
epos.offset == udf_file_entry_alloc_offset(inode)) || epos.offset ==
(epos.bh && epos.offset == sizeof(struct allocExtDesc))) { udf_file_entry_alloc_offset(inode)) ||
(epos.bh && epos.offset ==
sizeof(struct allocExtDesc))) {
/* File has no extents at all or has empty last /* File has no extents at all or has empty last
* indirect extent! Create a fake extent... */ * indirect extent! Create a fake extent... */
extent.extLocation.logicalBlockNum = 0; extent.extLocation.logicalBlockNum = 0;
extent.extLocation.partitionReferenceNum = 0; extent.extLocation.partitionReferenceNum = 0;
extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; extent.extLength =
EXT_NOT_RECORDED_NOT_ALLOCATED;
} else { } else {
epos.offset -= adsize; epos.offset -= adsize;
etype = udf_next_aext(inode, &epos, etype = udf_next_aext(inode, &epos,
...@@ -306,7 +320,9 @@ void udf_truncate_extents(struct inode *inode) ...@@ -306,7 +320,9 @@ void udf_truncate_extents(struct inode *inode)
extent.extLength |= etype << 30; extent.extLength |= etype << 30;
} }
udf_extend_file(inode, &epos, &extent, udf_extend_file(inode, &epos, &extent,
offset + ((inode->i_size & (sb->s_blocksize - 1)) != 0)); offset +
((inode->i_size &
(sb->s_blocksize - 1)) != 0));
} }
} }
UDF_I_LENEXTENTS(inode) = inode->i_size; UDF_I_LENEXTENTS(inode) = inode->i_size;
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
/* /*
* dgb 10/02/98: ripped this from glibc source to help convert timestamps to unix time * dgb 10/02/98: ripped this from glibc source to help convert timestamps
* 10/04/98: added new table-based lookup after seeing how ugly the gnu code is * to unix time
* 10/04/98: added new table-based lookup after seeing how ugly
* the gnu code is
* blf 09/27/99: ripped out all the old code and inserted new table from * blf 09/27/99: ripped out all the old code and inserted new table from
* John Brockmeyer (without leap second corrections) * John Brockmeyer (without leap second corrections)
* rewrote udf_stamp_to_time and fixed timezone accounting in * rewrote udf_stamp_to_time and fixed timezone accounting in
...@@ -55,27 +57,27 @@ static const unsigned short int __mon_yday[2][13] = { ...@@ -55,27 +57,27 @@ static const unsigned short int __mon_yday[2][13] = {
#define MAX_YEAR_SECONDS 69 #define MAX_YEAR_SECONDS 69
#define SPD 0x15180 /*3600*24 */ #define SPD 0x15180 /*3600*24 */
#define SPY(y,l,s) (SPD * (365*y+l)+s) #define SPY(y, l, s) (SPD * (365 * y + l) + s)
static time_t year_seconds[MAX_YEAR_SECONDS]= { static time_t year_seconds[MAX_YEAR_SECONDS] = {
/*1970*/ SPY( 0, 0,0), SPY( 1, 0,0), SPY( 2, 0,0), SPY( 3, 1,0), /*1970*/ SPY(0, 0, 0), SPY(1, 0, 0), SPY(2, 0, 0), SPY(3, 1, 0),
/*1974*/ SPY( 4, 1,0), SPY( 5, 1,0), SPY( 6, 1,0), SPY( 7, 2,0), /*1974*/ SPY(4, 1, 0), SPY(5, 1, 0), SPY(6, 1, 0), SPY(7, 2, 0),
/*1978*/ SPY( 8, 2,0), SPY( 9, 2,0), SPY(10, 2,0), SPY(11, 3,0), /*1978*/ SPY(8, 2, 0), SPY(9, 2, 0), SPY(10, 2, 0), SPY(11, 3, 0),
/*1982*/ SPY(12, 3,0), SPY(13, 3,0), SPY(14, 3,0), SPY(15, 4,0), /*1982*/ SPY(12, 3, 0), SPY(13, 3, 0), SPY(14, 3, 0), SPY(15, 4, 0),
/*1986*/ SPY(16, 4,0), SPY(17, 4,0), SPY(18, 4,0), SPY(19, 5,0), /*1986*/ SPY(16, 4, 0), SPY(17, 4, 0), SPY(18, 4, 0), SPY(19, 5, 0),
/*1990*/ SPY(20, 5,0), SPY(21, 5,0), SPY(22, 5,0), SPY(23, 6,0), /*1990*/ SPY(20, 5, 0), SPY(21, 5, 0), SPY(22, 5, 0), SPY(23, 6, 0),
/*1994*/ SPY(24, 6,0), SPY(25, 6,0), SPY(26, 6,0), SPY(27, 7,0), /*1994*/ SPY(24, 6, 0), SPY(25, 6, 0), SPY(26, 6, 0), SPY(27, 7, 0),
/*1998*/ SPY(28, 7,0), SPY(29, 7,0), SPY(30, 7,0), SPY(31, 8,0), /*1998*/ SPY(28, 7, 0), SPY(29, 7, 0), SPY(30, 7, 0), SPY(31, 8, 0),
/*2002*/ SPY(32, 8,0), SPY(33, 8,0), SPY(34, 8,0), SPY(35, 9,0), /*2002*/ SPY(32, 8, 0), SPY(33, 8, 0), SPY(34, 8, 0), SPY(35, 9, 0),
/*2006*/ SPY(36, 9,0), SPY(37, 9,0), SPY(38, 9,0), SPY(39,10,0), /*2006*/ SPY(36, 9, 0), SPY(37, 9, 0), SPY(38, 9, 0), SPY(39, 10, 0),
/*2010*/ SPY(40,10,0), SPY(41,10,0), SPY(42,10,0), SPY(43,11,0), /*2010*/ SPY(40, 10, 0), SPY(41, 10, 0), SPY(42, 10, 0), SPY(43, 11, 0),
/*2014*/ SPY(44,11,0), SPY(45,11,0), SPY(46,11,0), SPY(47,12,0), /*2014*/ SPY(44, 11, 0), SPY(45, 11, 0), SPY(46, 11, 0), SPY(47, 12, 0),
/*2018*/ SPY(48,12,0), SPY(49,12,0), SPY(50,12,0), SPY(51,13,0), /*2018*/ SPY(48, 12, 0), SPY(49, 12, 0), SPY(50, 12, 0), SPY(51, 13, 0),
/*2022*/ SPY(52,13,0), SPY(53,13,0), SPY(54,13,0), SPY(55,14,0), /*2022*/ SPY(52, 13, 0), SPY(53, 13, 0), SPY(54, 13, 0), SPY(55, 14, 0),
/*2026*/ SPY(56,14,0), SPY(57,14,0), SPY(58,14,0), SPY(59,15,0), /*2026*/ SPY(56, 14, 0), SPY(57, 14, 0), SPY(58, 14, 0), SPY(59, 15, 0),
/*2030*/ SPY(60,15,0), SPY(61,15,0), SPY(62,15,0), SPY(63,16,0), /*2030*/ SPY(60, 15, 0), SPY(61, 15, 0), SPY(62, 15, 0), SPY(63, 16, 0),
/*2034*/ SPY(64,16,0), SPY(65,16,0), SPY(66,16,0), SPY(67,17,0), /*2034*/ SPY(64, 16, 0), SPY(65, 16, 0), SPY(66, 16, 0), SPY(67, 17, 0),
/*2038*/ SPY(68,17,0) /*2038*/ SPY(68, 17, 0)
}; };
extern struct timezone sys_tz; extern struct timezone sys_tz;
...@@ -115,7 +117,7 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src) ...@@ -115,7 +117,7 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
return dest; return dest;
} }
kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
{ {
long int days, rem, y; long int days, rem, y;
const unsigned short int *ip; const unsigned short int *ip;
...@@ -137,7 +139,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) ...@@ -137,7 +139,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
dest->second = rem % 60; dest->second = rem % 60;
y = 1970; y = 1970;
#define DIV(a,b) ((a) / (b) - ((a) % (b) < 0)) #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
while (days < 0 || days >= (__isleap(y) ? 366 : 365)) { while (days < 0 || days >= (__isleap(y) ? 366 : 365)) {
...@@ -145,8 +147,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) ...@@ -145,8 +147,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
/* Adjust DAYS and Y to match the guessed year. */ /* Adjust DAYS and Y to match the guessed year. */
days -= ((yg - y) * 365 days -= ((yg - y) * 365
+ LEAPS_THRU_END_OF (yg - 1) + LEAPS_THRU_END_OF(yg - 1)
- LEAPS_THRU_END_OF (y - 1)); - LEAPS_THRU_END_OF(y - 1));
y = yg; y = yg;
} }
dest->year = y; dest->year = y;
...@@ -158,7 +160,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) ...@@ -158,7 +160,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
dest->day = days + 1; dest->day = days + 1;
dest->centiseconds = ts.tv_nsec / 10000000; dest->centiseconds = ts.tv_nsec / 10000000;
dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100; dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 -
dest->centiseconds * 10000) / 100;
dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 - dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
dest->hundredsOfMicroseconds * 100); dest->hundredsOfMicroseconds * 100);
return dest; return dest;
......
...@@ -136,12 +136,18 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i) ...@@ -136,12 +136,18 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i)
if (c < 0x80U) { if (c < 0x80U) {
utf_o->u_name[utf_o->u_len++] = (uint8_t)c; utf_o->u_name[utf_o->u_len++] = (uint8_t)c;
} else if (c < 0x800U) { } else if (c < 0x800U) {
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6)); utf_o->u_name[utf_o->u_len++] =
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); (uint8_t)(0xc0 | (c >> 6));
utf_o->u_name[utf_o->u_len++] =
(uint8_t)(0x80 | (c & 0x3f));
} else { } else {
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12)); utf_o->u_name[utf_o->u_len++] =
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f)); (uint8_t)(0xe0 | (c >> 12));
utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); utf_o->u_name[utf_o->u_len++] =
(uint8_t)(0x80 |
((c >> 6) & 0x3f));
utf_o->u_name[utf_o->u_len++] =
(uint8_t)(0x80 | (c & 0x3f));
} }
} }
utf_o->u_cmpID = 8; utf_o->u_cmpID = 8;
...@@ -232,9 +238,8 @@ static int udf_UTF8toCS0(dstring *ocu, struct ustr *utf, int length) ...@@ -232,9 +238,8 @@ static int udf_UTF8toCS0(dstring *ocu, struct ustr *utf, int length)
goto error_out; goto error_out;
} }
if (max_val == 0xffffU) { if (max_val == 0xffffU)
ocu[++u_len] = (uint8_t)(utf_char >> 8); ocu[++u_len] = (uint8_t)(utf_char >> 8);
}
ocu[++u_len] = (uint8_t)(utf_char & 0xffU); ocu[++u_len] = (uint8_t)(utf_char & 0xffU);
} }
...@@ -330,29 +335,29 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname, ...@@ -330,29 +335,29 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
struct ustr filename, unifilename; struct ustr filename, unifilename;
int len; int len;
if (udf_build_ustr_exact(&unifilename, sname, flen)) { if (udf_build_ustr_exact(&unifilename, sname, flen))
return 0; return 0;
}
if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
if (!udf_CS0toUTF8(&filename, &unifilename)) { if (!udf_CS0toUTF8(&filename, &unifilename)) {
udf_debug("Failed in udf_get_filename: sname = %s\n", sname); udf_debug("Failed in udf_get_filename: sname = %s\n",
sname);
return 0; return 0;
} }
} else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename)) { if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename,
udf_debug("Failed in udf_get_filename: sname = %s\n", sname); &unifilename)) {
udf_debug("Failed in udf_get_filename: sname = %s\n",
sname);
return 0; return 0;
} }
} else { } else
return 0; return 0;
}
len = udf_translate_to_linux(dname, filename.u_name, filename.u_len, len = udf_translate_to_linux(dname, filename.u_name, filename.u_len,
unifilename.u_name, unifilename.u_len); unifilename.u_name, unifilename.u_len);
if (len) { if (len)
return len; return len;
}
return 0; return 0;
} }
...@@ -363,23 +368,20 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname, ...@@ -363,23 +368,20 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname,
struct ustr unifilename; struct ustr unifilename;
int namelen; int namelen;
if (!(udf_char_to_ustr(&unifilename, sname, flen))) { if (!udf_char_to_ustr(&unifilename, sname, flen))
return 0; return 0;
}
if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN); namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN);
if (!namelen) { if (!namelen)
return 0; return 0;
}
} else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN); namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname,
if (!namelen) { &unifilename, UDF_NAME_LEN);
if (!namelen)
return 0; return 0;
} } else
} else {
return 0; return 0;
}
return namelen; return namelen;
} }
...@@ -389,8 +391,9 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname, ...@@ -389,8 +391,9 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname,
#define CRC_MARK '#' #define CRC_MARK '#'
#define EXT_SIZE 5 #define EXT_SIZE 5
static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen, static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
uint8_t *fidName, int fidNameLen) int udfLen, uint8_t *fidName,
int fidNameLen)
{ {
int index, newIndex = 0, needsCRC = 0; int index, newIndex = 0, needsCRC = 0;
int extIndex = 0, newExtIndex = 0, hasExt = 0; int extIndex = 0, newExtIndex = 0, hasExt = 0;
...@@ -409,13 +412,16 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen ...@@ -409,13 +412,16 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
if (curr == '/' || curr == 0) { if (curr == '/' || curr == 0) {
needsCRC = 1; needsCRC = 1;
curr = ILLEGAL_CHAR_MARK; curr = ILLEGAL_CHAR_MARK;
while (index + 1 < udfLen && (udfName[index + 1] == '/' || while (index + 1 < udfLen &&
udfName[index + 1] == 0)) (udfName[index + 1] == '/' ||
udfName[index + 1] == 0))
index++; index++;
} if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) { }
if (udfLen == index + 1) { if (curr == EXT_MARK &&
(udfLen - index - 1) <= EXT_SIZE) {
if (udfLen == index + 1)
hasExt = 0; hasExt = 0;
} else { else {
hasExt = 1; hasExt = 1;
extIndex = index; extIndex = index;
newExtIndex = newIndex; newExtIndex = newIndex;
...@@ -433,16 +439,18 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen ...@@ -433,16 +439,18 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
if (hasExt) { if (hasExt) {
int maxFilenameLen; int maxFilenameLen;
for(index = 0; index < EXT_SIZE && extIndex + index + 1 < udfLen; index++) { for (index = 0;
index < EXT_SIZE && extIndex + index + 1 < udfLen;
index++) {
curr = udfName[extIndex + index + 1]; curr = udfName[extIndex + index + 1];
if (curr == '/' || curr == 0) { if (curr == '/' || curr == 0) {
needsCRC = 1; needsCRC = 1;
curr = ILLEGAL_CHAR_MARK; curr = ILLEGAL_CHAR_MARK;
while(extIndex + index + 2 < udfLen && while (extIndex + index + 2 < udfLen &&
(index + 1 < EXT_SIZE (index + 1 < EXT_SIZE &&
&& (udfName[extIndex + index + 2] == '/' || (udfName[extIndex + index + 2] == '/' ||
udfName[extIndex + index + 2] == 0))) udfName[extIndex + index + 2] == 0)))
index++; index++;
} }
ext[localExtIndex++] = curr; ext[localExtIndex++] = curr;
...@@ -452,9 +460,8 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen ...@@ -452,9 +460,8 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
newIndex = maxFilenameLen; newIndex = maxFilenameLen;
else else
newIndex = newExtIndex; newIndex = newExtIndex;
} else if (newIndex > 250) { } else if (newIndex > 250)
newIndex = 250; newIndex = 250;
}
newName[newIndex++] = CRC_MARK; newName[newIndex++] = CRC_MARK;
valueCRC = udf_crc(fidName, fidNameLen, 0); valueCRC = udf_crc(fidName, fidNameLen, 0);
newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12]; newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment