From 0fb1239f662c26b80b62241f7a137485ce523f40 Mon Sep 17 00:00:00 2001 From: Namjae Jeon Date: Sun, 9 Oct 2011 22:54:51 +0900 Subject: [PATCH v5] udf : enable error print in udf_read_tagged(). While reading metadata, if a problem occurs, Print out only one of the five case.(It also does not show a checksum properly.) Because currently it have been disable by undef udf_debug. If there is a problem with scratched disc or loader, the user needs to know which error happened. And I use pr_fmt instead of printk by joe's suggestion. I try to modify totally it to pr_fmt also. Signed-off-by: Namjae Jeon --- fs/udf/balloc.c | 30 +++-- fs/udf/directory.c | 35 +++-- fs/udf/file.c | 11 +- fs/udf/inode.c | 61 +++++---- fs/udf/lowlevel.c | 8 +- fs/udf/misc.c | 28 +++-- fs/udf/namei.c | 15 +- fs/udf/partition.c | 23 ++-- fs/udf/super.c | 389 ++++++++++++++++++++++++++++++---------------------- fs/udf/truncate.c | 25 ++-- fs/udf/udfdecl.h | 43 +++--- fs/udf/udftime.c | 2 +- fs/udf/unicode.c | 42 +++--- 13 files changed, 406 insertions(+), 306 deletions(-) diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index 95518a9..8cbc2a1 100644 --- a/fs/udf/balloc.c +++ b/fs/udf/balloc.c @@ -59,8 +59,8 @@ static int __load_block_bitmap(struct super_block *sb, int nr_groups = bitmap->s_nr_groups; if (block_group >= nr_groups) { - udf_debug("block_group (%d) > nr_groups (%d)\n", block_group, - nr_groups); + udf_debug(sb, __func__, "block_group (%d) > nr_groups (%d)\n", + block_group, nr_groups); } if (bitmap->s_block_bitmap[block_group]) { @@ -125,9 +125,10 @@ static void udf_bitmap_free_blocks(struct super_block *sb, partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; if (bloc->logicalBlockNum + count < count || (bloc->logicalBlockNum + count) > partmap->s_partition_len) { - udf_debug("%d < %d || %d + %d > %d\n", - bloc->logicalBlockNum, 0, bloc->logicalBlockNum, - count, partmap->s_partition_len); + udf_debug(sb, __func__, "%d < %d || %d + %d > %d\n", + bloc->logicalBlockNum, 0, + bloc->logicalBlockNum, count, + partmap->s_partition_len); goto error_return; } @@ -153,8 +154,10 @@ static void udf_bitmap_free_blocks(struct super_block *sb, bh = bitmap->s_block_bitmap[bitmap_nr]; for (i = 0; i < count; i++) { if (udf_set_bit(bit + i, bh->b_data)) { - udf_debug("bit %ld already set\n", bit + i); - udf_debug("byte=%2x\n", + udf_debug(sb, __func__, + "bit %ld already set\n", + bit + i); + udf_debug(sb, __func__, "byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]); } } @@ -330,7 +333,8 @@ got_block: (sizeof(struct spaceBitmapDesc) << 3); if (!udf_clear_bit(bit, bh->b_data)) { - udf_debug("bit already cleared for block %d\n", bit); + udf_debug(sb, __func__, "bit already cleared for block %d\n", + bit); goto repeat; } @@ -368,9 +372,9 @@ static void udf_table_free_blocks(struct super_block *sb, partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; if (bloc->logicalBlockNum + count < count || (bloc->logicalBlockNum + count) > partmap->s_partition_len) { - udf_debug("%d < %d || %d + %d > %d\n", - bloc->logicalBlockNum, 0, bloc->logicalBlockNum, count, - partmap->s_partition_len); + udf_debug(sb, __func__, "%d < %d || %d + %d > %d\n", + bloc->logicalBlockNum, 0, bloc->logicalBlockNum, count, + partmap->s_partition_len); goto error_return; } @@ -610,8 +614,8 @@ static int udf_table_prealloc_blocks(struct super_block *sb, while (first_block != eloc.logicalBlockNum && (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { - udf_debug("eloc=%d, elen=%d, first_block=%d\n", - eloc.logicalBlockNum, elen, first_block); + udf_debug(sb, __func__, "eloc=%d, elen=%d, first_block=%d\n", + eloc.logicalBlockNum, elen, first_block); ; /* empty loop body */ } diff --git a/fs/udf/directory.c b/fs/udf/directory.c index 2ffdb67..a89d3ac 100644 --- a/fs/udf/directory.c +++ b/fs/udf/directory.c @@ -33,7 +33,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos, fibh->soffset = fibh->eoffset; if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { - fi = udf_get_fileident(iinfo->i_ext.i_data - + fi = udf_get_fileident(dir, iinfo->i_ext.i_data - (iinfo->i_efe ? sizeof(struct extendedFileEntry) : sizeof(struct fileEntry)), @@ -98,7 +98,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos, fibh->sbh = fibh->ebh; } - fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize, + fi = udf_get_fileident(dir, fibh->sbh->b_data, dir->i_sb->s_blocksize, &(fibh->eoffset)); if (!fi) @@ -154,7 +154,8 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos, return fi; } -struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) +struct fileIdentDesc *udf_get_fileident(struct inode *inode, void *buffer, + int bufsize, int *offset) { struct fileIdentDesc *fi; int lengthThisIdent; @@ -162,8 +163,9 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) int padlen; if ((!buffer) || (!offset)) { - udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, - offset); + udf_debug(inode->i_sb, __func__, + "invalidparms, buffer=%p, offset=%p\n", + buffer, offset); return NULL; } @@ -173,11 +175,11 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) ptr += *offset; fi = (struct fileIdentDesc *)ptr; if (fi->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) { - udf_debug("0x%x != TAG_IDENT_FID\n", - le16_to_cpu(fi->descTag.tagIdent)); - udf_debug("offset: %u sizeof: %lu bufsize: %u\n", - *offset, (unsigned long)sizeof(struct fileIdentDesc), - bufsize); + udf_debug(inode->i_sb, __func__, "0x%x != TAG_IDENT_FID\n", + le16_to_cpu(fi->descTag.tagIdent)); + udf_debug(inode->i_sb, __func__, + "offset: %u sizeof: %zu bufsize: %u\n", + *offset, sizeof(struct fileIdentDesc), bufsize); return NULL; } if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) @@ -195,13 +197,14 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) return fi; } -struct short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, uint32_t *offset, - int inc) +struct short_ad *udf_get_fileshortad(struct inode *inode, uint8_t *ptr, + int maxoffset, uint32_t *offset, int inc) { struct short_ad *sa; if ((!ptr) || (!offset)) { - printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n"); + udf_err(inode->i_sb, __func__, + "udf_get_fileshortad() invalidparms\n"); return NULL; } @@ -218,12 +221,14 @@ struct short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, uint32_t *offs return sa; } -struct long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, uint32_t *offset, int inc) +struct long_ad *udf_get_filelongad(struct inode *inode, uint8_t *ptr, + int maxoffset, uint32_t *offset, int inc) { struct long_ad *la; if ((!ptr) || (!offset)) { - printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n"); + udf_err(inode->i_sb, __func__, + "udf_get_filelongad() invalidparms\n"); return NULL; } diff --git a/fs/udf/file.c b/fs/udf/file.c index d8ffa7c..fccca11 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -124,7 +124,9 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, pos + count)) { err = udf_expand_file_adinicb(inode); if (err) { - udf_debug("udf_expand_adinicb: err=%d\n", err); + udf_debug(inode->i_sb, __func__, + "udf_expand_adinicb: err=%d\n", + err); up_write(&iinfo->i_data_sem); return err; } @@ -151,13 +153,16 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) int result = -EINVAL; if (inode_permission(inode, MAY_READ) != 0) { - udf_debug("no permission to access inode %lu\n", inode->i_ino); + udf_debug(inode->i_sb, __func__, + "no permission to access inode %lu\n", + inode->i_ino); result = -EPERM; goto out; } if (!arg) { - udf_debug("invalid argument to udf_ioctl\n"); + udf_debug(inode->i_sb, __func__, + "invalid argument to udf_ioctl\n"); result = -EINVAL; goto out; } diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 1d1358e..bd0afa0 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -83,10 +83,10 @@ void udf_evict_inode(struct inode *inode) end_writeback(inode); if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB && inode->i_size != iinfo->i_lenExtents) { - printk(KERN_WARNING "UDF-fs (%s): Inode %lu (mode %o) has " + udf_warn(inode->i_sb, __func__, "Inode %lu (mode %o) has " "inode size %llu different from extent length %llu. " "Filesystem need not be standards compliant.\n", - inode->i_sb->s_id, inode->i_ino, inode->i_mode, + inode->i_ino, inode->i_mode, (unsigned long long)inode->i_size, (unsigned long long)iinfo->i_lenExtents); } @@ -1169,16 +1169,18 @@ static void __udf_read_inode(struct inode *inode) */ bh = udf_read_ptagged(inode->i_sb, &iinfo->i_location, 0, &ident); if (!bh) { - printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n", - inode->i_ino); + udf_err(inode->i_sb, __func__, "udf_read_inode(ino %ld) " + "failed !bh\n", + inode->i_ino); make_bad_inode(inode); return; } if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && ident != TAG_IDENT_USE) { - printk(KERN_ERR "udf: udf_read_inode(ino %ld) " - "failed ident=%d\n", inode->i_ino, ident); + udf_err(inode->i_sb, __func__, "udf_read_inode(ino %ld) " + "failed ident=%d\n", + inode->i_ino, ident); brelse(bh); make_bad_inode(inode); return; @@ -1218,8 +1220,9 @@ static void __udf_read_inode(struct inode *inode) } brelse(ibh); } else if (fe->icbTag.strategyType != cpu_to_le16(4)) { - printk(KERN_ERR "udf: unsupported strategy type: %d\n", - le16_to_cpu(fe->icbTag.strategyType)); + udf_err(inode->i_sb, __func__, "unsupported strategy " + "type: %d\n", + le16_to_cpu(fe->icbTag.strategyType)); brelse(bh); make_bad_inode(inode); return; @@ -1404,18 +1407,18 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) inode->i_mode = S_IFLNK | S_IRWXUGO; break; case ICBTAG_FILE_TYPE_MAIN: - udf_debug("METADATA FILE-----\n"); + udf_debug(inode->i_sb, __func__, "METADATA FILE-----\n"); break; case ICBTAG_FILE_TYPE_MIRROR: - udf_debug("METADATA MIRROR FILE-----\n"); + udf_debug(inode->i_sb, __func__, "METADATA MIRROR FILE-----\n"); break; case ICBTAG_FILE_TYPE_BITMAP: - udf_debug("METADATA BITMAP FILE-----\n"); + udf_debug(inode->i_sb, __func__, "METADATA BITMAP FILE-----\n"); break; default: - printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown " - "file type=%d\n", inode->i_ino, - fe->icbTag.fileType); + udf_err(inode->i_sb, __func__, "udf_fill_inode(ino %ld) " + "failed unknown file type=%d\n", + inode->i_ino, fe->icbTag.fileType); make_bad_inode(inode); return; } @@ -1438,8 +1441,9 @@ static int udf_alloc_i_data(struct inode *inode, size_t size) iinfo->i_ext.i_data = kmalloc(size, GFP_KERNEL); if (!iinfo->i_ext.i_data) { - printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) " - "no free memory\n", inode->i_ino); + udf_err(inode->i_sb, __func__, "udf_alloc_i_data (ino %ld) " + "no free memory\n", + inode->i_ino); return -ENOMEM; } @@ -1491,7 +1495,7 @@ static int udf_update_inode(struct inode *inode, int do_sync) bh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, &iinfo->i_location, 0)); if (!bh) { - udf_debug("getblk failure\n"); + udf_debug(inode->i_sb, __func__, "getblk failure\n"); return -ENOMEM; } @@ -1689,9 +1693,9 @@ out: if (do_sync) { sync_dirty_buffer(bh); if (buffer_write_io_error(bh)) { - printk(KERN_WARNING "IO error syncing udf inode " - "[%s:%08lx]\n", inode->i_sb->s_id, - inode->i_ino); + udf_warn(inode->i_sb, __func__, "IO error syncing udf " + "inode [%s:%08lx]\n", + inode->i_sb->s_id, inode->i_ino); err = -EIO; } } @@ -1719,8 +1723,8 @@ struct inode *udf_iget(struct super_block *sb, struct kernel_lb_addr *ino) if (ino->logicalBlockNum >= UDF_SB(sb)-> s_partmaps[ino->partitionReferenceNum].s_partition_len) { - udf_debug("block=%d, partition=%d out of range\n", - ino->logicalBlockNum, ino->partitionReferenceNum); + udf_debug(sb, __func__, "block=%d, partition=%d out of range\n", + ino->logicalBlockNum, ino->partitionReferenceNum); make_bad_inode(inode); goto out_iput; } @@ -1927,7 +1931,9 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos, block = udf_get_lb_pblock(inode->i_sb, &epos->block, 0); epos->bh = udf_tread(inode->i_sb, block); if (!epos->bh) { - udf_debug("reading block %d failed!\n", block); + udf_debug(inode->i_sb, __func__, + "reading block %d failed!\n", + block); return -1; } } @@ -1964,7 +1970,7 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, switch (iinfo->i_alloc_type) { case ICBTAG_FLAG_AD_SHORT: - sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc); + sad = udf_get_fileshortad(inode, ptr, alen, &epos->offset, inc); if (!sad) return -1; etype = le32_to_cpu(sad->extLength) >> 30; @@ -1974,7 +1980,7 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK; break; case ICBTAG_FLAG_AD_LONG: - lad = udf_get_filelongad(ptr, alen, &epos->offset, inc); + lad = udf_get_filelongad(inode, ptr, alen, &epos->offset, inc); if (!lad) return -1; etype = le32_to_cpu(lad->extLength) >> 30; @@ -1982,8 +1988,9 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK; break; default: - udf_debug("alloc_type = %d unsupported\n", - iinfo->i_alloc_type); + udf_debug(inode->i_sb, __func__, + "alloc_type = %d unsupported\n", + iinfo->i_alloc_type); return -1; } diff --git a/fs/udf/lowlevel.c b/fs/udf/lowlevel.c index 43e24a3..4f6e689 100644 --- a/fs/udf/lowlevel.c +++ b/fs/udf/lowlevel.c @@ -37,12 +37,14 @@ unsigned int udf_get_last_session(struct super_block *sb) i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long)&ms_info); if (i == 0) { - udf_debug("XA disk: %s, vol_desc_start=%d\n", - (ms_info.xa_flag ? "yes" : "no"), ms_info.addr.lba); + udf_debug(sb, __func__, "XA disk: %s, vol_desc_start=%d\n", + (ms_info.xa_flag ? "yes" : "no"), ms_info.addr.lba); if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */ vol_desc_start = ms_info.addr.lba; } else { - udf_debug("CDROMMULTISESSION not supported: rc=%d\n", i); + udf_debug(sb, __func__, + "CDROMMULTISESSION not supported: rc=%d\n", + i); } return vol_desc_start; } diff --git a/fs/udf/misc.c b/fs/udf/misc.c index 9215700..45d4b4c 100644 --- a/fs/udf/misc.c +++ b/fs/udf/misc.c @@ -204,6 +204,7 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, { struct tag *tag_p; struct buffer_head *bh = NULL; + u8 checksum; /* Read the block */ if (block == 0xFFFFFFFF) @@ -211,8 +212,8 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, bh = udf_tread(sb, block); if (!bh) { - udf_debug("block=%d, location=%d: read failed\n", - block, location); + udf_err(sb, __func__, "block=%d, location=%d: read failed\n", + block, location); return NULL; } @@ -221,22 +222,27 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, *ident = le16_to_cpu(tag_p->tagIdent); if (location != le32_to_cpu(tag_p->tagLocation)) { - udf_debug("location mismatch block %u, tag %u != %u\n", - block, le32_to_cpu(tag_p->tagLocation), location); + udf_err(sb, __func__, + "location mismatch block %u, tag %u != %u\n", + block, le32_to_cpu(tag_p->tagLocation), location); goto error_out; } /* Verify the tag checksum */ - if (udf_tag_checksum(tag_p) != tag_p->tagChecksum) { - printk(KERN_ERR "udf: tag checksum failed block %d\n", block); + checksum = udf_tag_checksum(tag_p); + if (checksum != tag_p->tagChecksum) { + udf_err(sb, __func__, + "tag checksum failed block %d, checksum 0x%02x != 0x%02x\n", + block, checksum, tag_p->tagChecksum); goto error_out; } /* Verify the tag version */ if (tag_p->descVersion != cpu_to_le16(0x0002U) && tag_p->descVersion != cpu_to_le16(0x0003U)) { - udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n", - le16_to_cpu(tag_p->descVersion), block); + udf_err(sb, __func__, + "tag version 0x%04x != 0x0002 || 0x0003 block %d\n", + le16_to_cpu(tag_p->descVersion), block); goto error_out; } @@ -247,8 +253,10 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block, le16_to_cpu(tag_p->descCRCLength))) return bh; - udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", block, - le16_to_cpu(tag_p->descCRC), le16_to_cpu(tag_p->descCRCLength)); + udf_err(sb, __func__, + "Crc failure block %d: crc = %d, crclen = %d\n", + block, le16_to_cpu(tag_p->descCRC), + le16_to_cpu(tag_p->descCRCLength)); error_out: brelse(bh); diff --git a/fs/udf/namei.c b/fs/udf/namei.c index f1dce84..f2a1614 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -799,9 +799,9 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry) if (retval) goto end_rmdir; if (inode->i_nlink != 2) - udf_warning(inode->i_sb, "udf_rmdir", - "empty directory has nlink != 2 (%d)", - inode->i_nlink); + udf_warn(inode->i_sb, __func__, + "empty directory has nlink != 2 (%d)\n", + inode->i_nlink); clear_nlink(inode); inode->i_size = 0; inode_dec_link_count(dir); @@ -838,8 +838,9 @@ static int udf_unlink(struct inode *dir, struct dentry *dentry) goto end_unlink; if (!inode->i_nlink) { - udf_debug("Deleting nonexistent file (%lu), %d\n", - inode->i_ino, inode->i_nlink); + udf_debug(dir->i_sb, __func__, + "Deleting nonexistent file (%lu), %d\n", + inode->i_ino, inode->i_nlink); inode->i_nlink = 1; } retval = udf_delete_entry(dir, fi, &fibh, &cfi); @@ -1111,7 +1112,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, } retval = -EIO; if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { - dir_fi = udf_get_fileident( + dir_fi = udf_get_fileident(old_inode, old_iinfo->i_ext.i_data - (old_iinfo->i_efe ? sizeof(struct extendedFileEntry) : @@ -1121,7 +1122,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, dir_bh = udf_bread(old_inode, 0, 0, &retval); if (!dir_bh) goto end_rename; - dir_fi = udf_get_fileident(dir_bh->b_data, + dir_fi = udf_get_fileident(old_inode, dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset); } if (!dir_fi) diff --git a/fs/udf/partition.c b/fs/udf/partition.c index a71090e..5fb4dcf 100644 --- a/fs/udf/partition.c +++ b/fs/udf/partition.c @@ -33,8 +33,9 @@ uint32_t udf_get_pblock(struct super_block *sb, uint32_t block, struct udf_sb_info *sbi = UDF_SB(sb); struct udf_part_map *map; if (partition >= sbi->s_partitions) { - udf_debug("block=%d, partition=%d, offset=%d: " - "invalid partition\n", block, partition, offset); + udf_debug(sb, __func__, + "block=%d, partition=%d, offset=%d: invalid partition\n", + block, partition, offset); return 0xFFFFFFFF; } map = &sbi->s_partmaps[partition]; @@ -60,8 +61,9 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, vdata = &map->s_type_specific.s_virtual; if (block > vdata->s_num_entries) { - udf_debug("Trying to access block beyond end of VAT " - "(%d max %d)\n", block, vdata->s_num_entries); + udf_debug(sb, __func__, + "Trying to access block beyond end of VAT (%d max %d)\n", + block, vdata->s_num_entries); return 0xFFFFFFFF; } @@ -84,8 +86,9 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, bh = sb_bread(sb, loc); if (!bh) { - udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", - sb, block, partition, loc, index); + udf_debug(sb, __func__, + "get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", + sb, block, partition, loc, index); return 0xFFFFFFFF; } @@ -95,7 +98,7 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, translate: if (iinfo->i_location.partitionReferenceNum == partition) { - udf_debug("recursive call to udf_get_pblock!\n"); + udf_debug(sb, __func__, "recursive call to udf_get_pblock!\n"); return 0xFFFFFFFF; } @@ -312,7 +315,7 @@ uint32_t udf_get_pblock_meta25(struct super_block *sb, uint32_t block, uint32_t retblk; struct inode *inode; - udf_debug("READING from METADATA\n"); + udf_debug(sb, __func__, "READING from METADATA\n"); map = &sbi->s_partmaps[partition]; mdata = &map->s_type_specific.s_metadata; @@ -322,8 +325,8 @@ uint32_t udf_get_pblock_meta25(struct super_block *sb, uint32_t block, BUG_ON(!inode); retblk = udf_try_read_meta(inode, block, partition, offset); if (retblk == 0xFFFFFFFF) { - udf_warning(sb, __func__, "error reading from METADATA, " - "trying to read from MIRROR"); + udf_warn(sb, __func__, + "error reading from METADATA, trying to read from MIRROR"); inode = mdata->s_mirror_fe; if (!inode) return 0xFFFFFFFF; diff --git a/fs/udf/super.c b/fs/udf/super.c index 7b27b06..a12cd28 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -75,8 +75,6 @@ #define UDF_DEFAULT_BLOCKSIZE 2048 -static char error_buf[1024]; - /* These are the "meat" - everything else is stuffing */ static int udf_fill_super(struct super_block *, void *, int); static void udf_put_super(struct super_block *); @@ -92,8 +90,6 @@ static void udf_close_lvid(struct super_block *); static unsigned int udf_count_free(struct super_block *); static int udf_statfs(struct dentry *, struct kstatfs *); static int udf_show_options(struct seq_file *, struct vfsmount *); -static void udf_error(struct super_block *sb, const char *function, - const char *fmt, ...); struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi) { @@ -244,9 +240,9 @@ static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count) sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map), GFP_KERNEL); if (!sbi->s_partmaps) { - udf_error(sb, __func__, - "Unable to allocate space for %d partition maps", - count); + udf_err(sb, __func__, + "Unable to allocate space for %d partition maps", + count); sbi->s_partitions = 0; return -ENOMEM; } @@ -405,8 +401,8 @@ static const match_table_t tokens = { {Opt_err, NULL} }; -static int udf_parse_options(char *options, struct udf_options *uopt, - bool remount) +static int udf_parse_options(struct super_block *sb, char *options, + struct udf_options *uopt, bool remount) { char *p; int option; @@ -550,8 +546,9 @@ static int udf_parse_options(char *options, struct udf_options *uopt, uopt->dmode = option & 0777; break; default: - printk(KERN_ERR "udf: bad mount option \"%s\" " - "or missing value\n", p); + udf_err(sb, __func__, + "bad mount option \"%s\" or missing value\n", + p); return 0; } } @@ -571,7 +568,7 @@ static int udf_remount_fs(struct super_block *sb, int *flags, char *options) uopt.fmode = sbi->s_fmode; uopt.dmode = sbi->s_dmode; - if (!udf_parse_options(options, &uopt, true)) + if (!udf_parse_options(sb, options, &uopt, true)) return -EINVAL; write_lock(&sbi->s_cred_lock); @@ -621,9 +618,9 @@ static loff_t udf_check_vsd(struct super_block *sb) sector += (sbi->s_session << sb->s_blocksize_bits); - udf_debug("Starting at sector %u (%ld byte sectors)\n", - (unsigned int)(sector >> sb->s_blocksize_bits), - sb->s_blocksize); + udf_debug(sb, __func__, "Starting at sector %u (%ld byte sectors)\n", + (unsigned int)(sector >> sb->s_blocksize_bits), + sb->s_blocksize); /* Process the sequence (if applicable) */ for (; !nsr02 && !nsr03; sector += sectorsize) { /* Read a block */ @@ -642,27 +639,29 @@ static loff_t udf_check_vsd(struct super_block *sb) VSD_STD_ID_LEN)) { switch (vsd->structType) { case 0: - udf_debug("ISO9660 Boot Record found\n"); + udf_debug(sb, __func__, + "ISO9660 Boot Record found\n"); break; case 1: - udf_debug("ISO9660 Primary Volume Descriptor " - "found\n"); + udf_debug(sb, __func__, + "ISO9660 Primary Volume Descriptor found\n"); break; case 2: - udf_debug("ISO9660 Supplementary Volume " - "Descriptor found\n"); + udf_debug(sb, __func__, + "ISO9660 Supplementary Volume Descriptor found\n"); break; case 3: - udf_debug("ISO9660 Volume Partition Descriptor " - "found\n"); + udf_debug(sb, __func__, + "ISO9660 Volume Partition Descriptor found\n"); break; case 255: - udf_debug("ISO9660 Volume Descriptor Set " - "Terminator found\n"); + udf_debug(sb, __func__, + "ISO9660 Volume Descriptor Set Terminator found\n"); break; default: - udf_debug("ISO9660 VRS (%u) found\n", - vsd->structType); + udf_debug(sb, __func__, + "ISO9660 VRS (%u) found\n", + vsd->structType); break; } } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, @@ -769,9 +768,9 @@ static int udf_find_fileset(struct super_block *sb, if ((fileset->logicalBlockNum != 0xFFFFFFFF || fileset->partitionReferenceNum != 0xFFFF) && bh) { - udf_debug("Fileset at block=%d, partition=%d\n", - fileset->logicalBlockNum, - fileset->partitionReferenceNum); + udf_debug(sb, __func__, "Fileset at block=%d, partition=%d\n", + fileset->logicalBlockNum, + fileset->partitionReferenceNum); sbi->s_partition = fileset->partitionReferenceNum; udf_load_fileset(sb, bh, root); @@ -809,24 +808,25 @@ static int udf_load_pvoldesc(struct super_block *sb, sector_t block) pvoldesc->recordingDateAndTime)) { #ifdef UDFFS_DEBUG struct timestamp *ts = &pvoldesc->recordingDateAndTime; - udf_debug("recording time %04u/%02u/%02u" - " %02u:%02u (%x)\n", - le16_to_cpu(ts->year), ts->month, ts->day, ts->hour, - ts->minute, le16_to_cpu(ts->typeAndTimezone)); + udf_debug(sb, __func__, + "recording time %04u/%02u/%02u %02u:%02u (%x)\n", + le16_to_cpu(ts->year), ts->month, ts->day, ts->hour, + ts->minute, le16_to_cpu(ts->typeAndTimezone)); #endif } if (!udf_build_ustr(instr, pvoldesc->volIdent, 32)) - if (udf_CS0toUTF8(outstr, instr)) { + if (udf_CS0toUTF8(sb, outstr, instr)) { strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name, outstr->u_len > 31 ? 31 : outstr->u_len); - udf_debug("volIdent[] = '%s'\n", - UDF_SB(sb)->s_volume_ident); + udf_debug(sb, __func__, "volIdent[] = '%s'\n", + UDF_SB(sb)->s_volume_ident); } if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128)) - if (udf_CS0toUTF8(outstr, instr)) - udf_debug("volSetIdent[] = '%s'\n", outstr->u_name); + if (udf_CS0toUTF8(sb, outstr, instr)) + udf_debug(sb, __func__, + "volSetIdent[] = '%s'\n", outstr->u_name); brelse(bh); ret = 0; @@ -852,19 +852,20 @@ static int udf_load_metadata_files(struct super_block *sb, int partition) addr.logicalBlockNum = mdata->s_meta_file_loc; addr.partitionReferenceNum = map->s_partition_num; - udf_debug("Metadata file location: block = %d part = %d\n", - addr.logicalBlockNum, addr.partitionReferenceNum); + udf_debug(sb, __func__, + "Metadata file location: block = %d part = %d\n", + addr.logicalBlockNum, addr.partitionReferenceNum); mdata->s_metadata_fe = udf_iget(sb, &addr); if (mdata->s_metadata_fe == NULL) { - udf_warning(sb, __func__, "metadata inode efe not found, " - "will try mirror inode."); + udf_warn(sb, __func__, + "metadata inode efe not found, will try mirror inode."); fe_error = 1; } else if (UDF_I(mdata->s_metadata_fe)->i_alloc_type != ICBTAG_FLAG_AD_SHORT) { - udf_warning(sb, __func__, "metadata inode efe does not have " - "short allocation descriptors!"); + udf_warn(sb, __func__, + "metadata inode efe does not have short allocation descriptors!"); fe_error = 1; iput(mdata->s_metadata_fe); mdata->s_metadata_fe = NULL; @@ -874,23 +875,24 @@ static int udf_load_metadata_files(struct super_block *sb, int partition) addr.logicalBlockNum = mdata->s_mirror_file_loc; addr.partitionReferenceNum = map->s_partition_num; - udf_debug("Mirror metadata file location: block = %d part = %d\n", - addr.logicalBlockNum, addr.partitionReferenceNum); + udf_debug(sb, __func__, + "Mirror metadata file location: block = %d part = %d\n", + addr.logicalBlockNum, addr.partitionReferenceNum); mdata->s_mirror_fe = udf_iget(sb, &addr); if (mdata->s_mirror_fe == NULL) { if (fe_error) { - udf_error(sb, __func__, "mirror inode efe not found " - "and metadata inode is missing too, exiting..."); + udf_err(sb, __func__, + "mirror inode efe not found and metadata inode is missing too, exiting..."); goto error_exit; } else - udf_warning(sb, __func__, "mirror inode efe not found," - " but metadata inode is OK"); + udf_warn(sb, __func__, + "mirror inode efe not found, but metadata inode is OK"); } else if (UDF_I(mdata->s_mirror_fe)->i_alloc_type != ICBTAG_FLAG_AD_SHORT) { - udf_warning(sb, __func__, "mirror inode efe does not have " - "short allocation descriptors!"); + udf_warn(sb, __func__, + "mirror inode efe does not have short allocation descriptors!"); iput(mdata->s_mirror_fe); mdata->s_mirror_fe = NULL; if (fe_error) @@ -906,25 +908,25 @@ static int udf_load_metadata_files(struct super_block *sb, int partition) addr.logicalBlockNum = mdata->s_bitmap_file_loc; addr.partitionReferenceNum = map->s_partition_num; - udf_debug("Bitmap file location: block = %d part = %d\n", + udf_debug(sb, __func__, + "Bitmap file location: block = %d part = %d\n", addr.logicalBlockNum, addr.partitionReferenceNum); mdata->s_bitmap_fe = udf_iget(sb, &addr); if (mdata->s_bitmap_fe == NULL) { if (sb->s_flags & MS_RDONLY) - udf_warning(sb, __func__, "bitmap inode efe " - "not found but it's ok since the disc" - " is mounted read-only"); + udf_warn(sb, __func__, + "bitmap inode efe not found but it's ok since the disc is mounted read-only"); else { - udf_error(sb, __func__, "bitmap inode efe not " - "found and attempted read-write mount"); + udf_err(sb, __func__, + "bitmap inode efe not found and attempted read-write mount"); goto error_exit; } } } - udf_debug("udf_load_metadata_files Ok\n"); + udf_debug(sb, __func__, "udf_load_metadata_files Ok\n"); return 0; @@ -943,8 +945,8 @@ static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum); - udf_debug("Rootdir at block=%d, partition=%d\n", - root->logicalBlockNum, root->partitionReferenceNum); + udf_debug(sb, __func__, "Rootdir at block=%d, partition=%d\n", + root->logicalBlockNum, root->partitionReferenceNum); } int udf_compute_nr_groups(struct super_block *sb, u32 partition) @@ -971,9 +973,9 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index) bitmap = vzalloc(size); /* TODO: get rid of vzalloc */ if (bitmap == NULL) { - udf_error(sb, __func__, - "Unable to allocate space for bitmap " - "and %d buffer_head pointers", nr_groups); + udf_err(sb, __func__, + "Unable to allocate space for bitmap and %d buffer_head pointers\n", + nr_groups); return NULL; } @@ -1003,10 +1005,10 @@ static int udf_fill_partdesc_info(struct super_block *sb, if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE)) map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE; - udf_debug("Partition (%d type %x) starts at physical %d, " - "block length %d\n", p_index, - map->s_partition_type, map->s_partition_root, - map->s_partition_len); + udf_debug(sb, __func__, + "Partition (%d type %x) starts at physical %d, block length %d\n", + p_index, map->s_partition_type, + map->s_partition_root, map->s_partition_len); if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) && strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03)) @@ -1022,13 +1024,14 @@ static int udf_fill_partdesc_info(struct super_block *sb, map->s_uspace.s_table = udf_iget(sb, &loc); if (!map->s_uspace.s_table) { - udf_debug("cannot load unallocSpaceTable (part %d)\n", - p_index); + udf_debug(sb, __func__, + "cannot load unallocSpaceTable (part %d)\n", + p_index); return 1; } map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE; - udf_debug("unallocSpaceTable (part %d) @ %ld\n", - p_index, map->s_uspace.s_table->i_ino); + udf_debug(sb, __func__, "unallocSpaceTable (part %d) @ %ld\n", + p_index, map->s_uspace.s_table->i_ino); } if (phd->unallocSpaceBitmap.extLength) { @@ -1041,12 +1044,14 @@ static int udf_fill_partdesc_info(struct super_block *sb, bitmap->s_extPosition = le32_to_cpu( phd->unallocSpaceBitmap.extPosition); map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP; - udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index, - bitmap->s_extPosition); + udf_debug(sb, __func__, "unallocSpaceBitmap (part %d) @ %d\n", + p_index, bitmap->s_extPosition); } if (phd->partitionIntegrityTable.extLength) - udf_debug("partitionIntegrityTable (part %d)\n", p_index); + udf_debug(sb, __func__, + "partitionIntegrityTable (part %d)\n", + p_index); if (phd->freedSpaceTable.extLength) { struct kernel_lb_addr loc = { @@ -1057,14 +1062,15 @@ static int udf_fill_partdesc_info(struct super_block *sb, map->s_fspace.s_table = udf_iget(sb, &loc); if (!map->s_fspace.s_table) { - udf_debug("cannot load freedSpaceTable (part %d)\n", + udf_debug(sb, __func__, + "cannot load freedSpaceTable (part %d)\n", p_index); return 1; } map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE; - udf_debug("freedSpaceTable (part %d) @ %ld\n", - p_index, map->s_fspace.s_table->i_ino); + udf_debug(sb, __func__, "freedSpaceTable (part %d) @ %ld\n", + p_index, map->s_fspace.s_table->i_ino); } if (phd->freedSpaceBitmap.extLength) { @@ -1077,8 +1083,8 @@ static int udf_fill_partdesc_info(struct super_block *sb, bitmap->s_extPosition = le32_to_cpu( phd->freedSpaceBitmap.extPosition); map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP; - udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index, - bitmap->s_extPosition); + udf_debug(sb, __func__, "freedSpaceBitmap (part %d) @ %d\n", + p_index, bitmap->s_extPosition); } return 0; } @@ -1118,11 +1124,10 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index) udf_find_vat_block(sb, p_index, type1_index, sbi->s_last_block); if (!sbi->s_vat_inode && sbi->s_last_block != blocks - 1) { - printk(KERN_NOTICE "UDF-fs: Failed to read VAT inode from the" - " last recorded block (%lu), retrying with the last " - "block of the device (%lu).\n", - (unsigned long)sbi->s_last_block, - (unsigned long)blocks - 1); + udf_info(sb, + "Failed to read VAT inode from the last recorded block (%lu), retrying with the last block of the device (%lu).\n", + (unsigned long)sbi->s_last_block, + (unsigned long)blocks - 1); udf_find_vat_block(sb, p_index, type1_index, blocks - 1); } if (!sbi->s_vat_inode) @@ -1179,8 +1184,8 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block) /* First scan for TYPE1, SPARABLE and METADATA partitions */ for (i = 0; i < sbi->s_partitions; i++) { map = &sbi->s_partmaps[i]; - udf_debug("Searching map: (%d == %d)\n", - map->s_partition_num, partitionNumber); + udf_debug(sb, __func__, "Searching map: (%d == %d)\n", + map->s_partition_num, partitionNumber); if (map->s_partition_num == partitionNumber && (map->s_partition_type == UDF_TYPE1_MAP15 || map->s_partition_type == UDF_SPARABLE_MAP15)) @@ -1188,8 +1193,9 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block) } if (i >= sbi->s_partitions) { - udf_debug("Partition (%d) not found in partition map\n", - partitionNumber); + udf_debug(sb, __func__, + "Partition (%d) not found in partition map\n", + partitionNumber); goto out_bh; } @@ -1220,8 +1226,9 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block) if (map->s_partition_type == UDF_METADATA_MAP25) { ret = udf_load_metadata_files(sb, i); if (ret) { - printk(KERN_ERR "UDF-fs: error loading MetaData " - "partition map %d\n", i); + udf_err(sb, __func__, + "loading MetaData partition map %d\n", + i); goto out_bh; } } else { @@ -1234,9 +1241,8 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block) * overwrite blocks instead of relocating them). */ sb->s_flags |= MS_RDONLY; - printk(KERN_NOTICE "UDF-fs: Filesystem marked read-only " - "because writing to pseudooverwrite partition is " - "not implemented.\n"); + udf_info(sb, + "Filesystem marked read-only because writing to pseudooverwrite partition is not implemented.\n"); } out_bh: /* In case loading failed, we handle cleanup in udf_fill_super */ @@ -1344,9 +1350,9 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block, struct metadataPartitionMap *mdm = (struct metadataPartitionMap *) &(lvd->partitionMaps[offset]); - udf_debug("Parsing Logical vol part %d " - "type %d id=%s\n", i, type, - UDF_ID_METADATA); + udf_debug(sb, __func__, + "Parsing Logical vol part %d type %d id=%s\n", + i, type, UDF_ID_METADATA); map->s_partition_type = UDF_METADATA_MAP25; map->s_partition_func = udf_get_pblock_meta25; @@ -1364,42 +1370,50 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block, mdata->s_dup_md_flag = mdm->flags & 0x01; - udf_debug("Metadata Ident suffix=0x%x\n", - (le16_to_cpu( - ((__le16 *) - mdm->partIdent.identSuffix)[0]))); - udf_debug("Metadata part num=%d\n", + udf_debug(sb, __func__, + "Metadata Ident suffix=0x%x\n", + (le16_to_cpu(((__le16 *) + mdm->partIdent.identSuffix)[0]))); + udf_debug(sb, __func__, + "Metadata part num=%d\n", le16_to_cpu(mdm->partitionNum)); - udf_debug("Metadata part alloc unit size=%d\n", + udf_debug(sb, __func__, + "Metadata part alloc unit size=%d\n", le32_to_cpu(mdm->allocUnitSize)); - udf_debug("Metadata file loc=%d\n", + udf_debug(sb, __func__, + "Metadata file loc=%d\n", le32_to_cpu(mdm->metadataFileLoc)); - udf_debug("Mirror file loc=%d\n", - le32_to_cpu(mdm->metadataMirrorFileLoc)); - udf_debug("Bitmap file loc=%d\n", - le32_to_cpu(mdm->metadataBitmapFileLoc)); - udf_debug("Duplicate Flag: %d %d\n", + udf_debug(sb, __func__, + "Mirror file loc=%d\n", + le32_to_cpu( + mdm->metadataMirrorFileLoc)); + udf_debug(sb, __func__, "Bitmap file loc=%d\n", + le32_to_cpu( + mdm->metadataBitmapFileLoc)); + udf_debug(sb, __func__, + "Duplicate Flag: %d %d\n", mdata->s_dup_md_flag, mdm->flags); } else { - udf_debug("Unknown ident: %s\n", - upm2->partIdent.ident); + udf_debug(sb, __func__, "Unknown ident: %s\n", + upm2->partIdent.ident); continue; } map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum); map->s_partition_num = le16_to_cpu(upm2->partitionNum); } - udf_debug("Partition (%d:%d) type %d on volume %d\n", - i, map->s_partition_num, type, - map->s_volumeseqnum); + udf_debug(sb, __func__, + "Partition (%d:%d) type %d on volume %d\n", + i, map->s_partition_num, type, map->s_volumeseqnum); } if (fileset) { struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]); *fileset = lelb_to_cpu(la->extLocation); - udf_debug("FileSet found in LogicalVolDesc at block=%d, " - "partition=%d\n", fileset->logicalBlockNum, - fileset->partitionReferenceNum); + udf_debug(sb, __func__, + "FileSet found in LogicalVolDesc at block=%d, partition=%d\n", + fileset->logicalBlockNum, + fileset->partitionReferenceNum); } if (lvd->integritySeqExt.extLength) udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt)); @@ -1478,9 +1492,9 @@ static noinline int udf_process_sequence(struct super_block *sb, long block, bh = udf_read_tagged(sb, block, block, &ident); if (!bh) { - printk(KERN_ERR "udf: Block %Lu of volume descriptor " - "sequence is corrupted or we could not read " - "it.\n", (unsigned long long)block); + udf_err(sb, __func__, + "Block %llu of volume descriptor sequence is corrupted or we could not read it.\n", + (unsigned long long)block); return 1; } @@ -1553,7 +1567,7 @@ static noinline int udf_process_sequence(struct super_block *sb, long block, * in a suitable order */ if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) { - printk(KERN_ERR "udf: Primary Volume Descriptor not found!\n"); + udf_err(sb, __func__, "Primary Volume Descriptor not found!\n"); return 1; } if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block)) @@ -1740,7 +1754,7 @@ static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt, if (!sb_set_blocksize(sb, uopt->blocksize)) { if (!silent) - printk(KERN_WARNING "UDF-fs: Bad block size\n"); + udf_warn(sb, __func__, "Bad block size\n"); return 0; } sbi->s_last_block = uopt->lastblock; @@ -1749,23 +1763,24 @@ static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt, nsr_off = udf_check_vsd(sb); if (!nsr_off) { if (!silent) - printk(KERN_WARNING "UDF-fs: No VRS found\n"); + udf_warn(sb, __func__, "No VRS found\n"); return 0; } if (nsr_off == -1) - udf_debug("Failed to read byte 32768. Assuming open " - "disc. Skipping validity check\n"); + udf_debug(sb, __func__, + "Failed to read byte 32768. Assuming open disc. Skipping validity check\n"); if (!sbi->s_last_block) sbi->s_last_block = udf_get_last_block(sb); } else { - udf_debug("Validity check skipped because of novrs option\n"); + udf_debug(sb, __func__, + "Validity check skipped because of novrs option\n"); } /* Look for anchor block and load Volume Descriptor Sequence */ sbi->s_anchor = uopt->anchor; if (!udf_find_anchor(sb, fileset)) { if (!silent) - printk(KERN_WARNING "UDF-fs: No anchor found\n"); + udf_warn(sb, __func__, "No anchor found\n"); return 0; } return 1; @@ -1932,13 +1947,13 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) mutex_init(&sbi->s_alloc_mutex); - if (!udf_parse_options((char *)options, &uopt, false)) + if (!udf_parse_options(sb, (char *)options, &uopt, false)) goto error_out; if (uopt.flags & (1 << UDF_FLAG_UTF8) && uopt.flags & (1 << UDF_FLAG_NLS_MAP)) { - udf_error(sb, "udf_read_super", - "utf8 cannot be combined with iocharset\n"); + udf_err(sb, __func__, + "utf8 cannot be combined with iocharset\n"); goto error_out; } #ifdef CONFIG_UDF_NLS @@ -1947,7 +1962,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) if (!uopt.nls_map) uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP); else - udf_debug("Using default NLS map\n"); + udf_debug(sb, __func__, "Using default NLS map\n"); } #endif if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP))) @@ -1970,7 +1985,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) else sbi->s_session = uopt.session; - udf_debug("Multi-session=%d\n", sbi->s_session); + udf_debug(sb, __func__, "Multi-session=%d\n", sbi->s_session); /* Fill in the rest of the superblock */ sb->s_op = &udf_sb_ops; @@ -1987,19 +2002,18 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) ret = udf_load_vrs(sb, &uopt, silent, &fileset); if (!ret && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) { if (!silent) - printk(KERN_NOTICE - "UDF-fs: Rescanning with blocksize " - "%d\n", UDF_DEFAULT_BLOCKSIZE); + udf_info(sb, "Rescanning with blocksize %d\n", + UDF_DEFAULT_BLOCKSIZE); uopt.blocksize = UDF_DEFAULT_BLOCKSIZE; ret = udf_load_vrs(sb, &uopt, silent, &fileset); } } if (!ret) { - printk(KERN_WARNING "UDF-fs: No partition found (1)\n"); + udf_warn(sb, __func__, "No partition found (1)\n"); goto error_out; } - udf_debug("Lastblock=%d\n", sbi->s_last_block); + udf_debug(sb, __func__, "Lastblock=%d\n", sbi->s_last_block); if (sbi->s_lvid_bh) { struct logicalVolIntegrityDescImpUse *lvidiu = @@ -2010,10 +2024,9 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) le16_to_cpu(lvidiu->maxUDFWriteRev); */ if (minUDFReadRev > UDF_MAX_READ_VERSION) { - printk(KERN_ERR "UDF-fs: minUDFReadRev=%x " - "(max is %x)\n", - le16_to_cpu(lvidiu->minUDFReadRev), - UDF_MAX_READ_VERSION); + udf_err(sb, __func__, "minUDFReadRev=%x (max is %x)\n", + le16_to_cpu(lvidiu->minUDFReadRev), + UDF_MAX_READ_VERSION); goto error_out; } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) sb->s_flags |= MS_RDONLY; @@ -2027,29 +2040,30 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) } if (!sbi->s_partitions) { - printk(KERN_WARNING "UDF-fs: No partition found (2)\n"); + udf_warn(sb, __func__, "No partition found (2)\n"); goto error_out; } if (sbi->s_partmaps[sbi->s_partition].s_partition_flags & UDF_PART_FLAG_READ_ONLY) { - printk(KERN_NOTICE "UDF-fs: Partition marked readonly; " - "forcing readonly mount\n"); + udf_info(sb, + "Partition marked readonly; forcing readonly mount\n"); sb->s_flags |= MS_RDONLY; } if (udf_find_fileset(sb, &fileset, &rootdir)) { - printk(KERN_WARNING "UDF-fs: No fileset found\n"); + udf_warn(sb, __func__, "No fileset found\n"); goto error_out; } if (!silent) { struct timestamp ts; udf_time_to_disk_stamp(&ts, sbi->s_record_time); - udf_info("UDF: Mounting volume '%s', " - "timestamp %04u/%02u/%02u %02u:%02u (%x)\n", - sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day, - ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone)); + udf_info(sb, + "Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n", + sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, + ts.day, ts.hour, ts.minute, + le16_to_cpu(ts.typeAndTimezone)); } if (!(sb->s_flags & MS_RDONLY)) udf_open_lvid(sb); @@ -2059,16 +2073,16 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) /* perhaps it's not extensible enough, but for now ... */ inode = udf_iget(sb, &rootdir); if (!inode) { - printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, " - "partition=%d\n", - rootdir.logicalBlockNum, rootdir.partitionReferenceNum); + udf_err(sb, __func__, + "Error in udf_iget, block=%d, partition=%d\n", + rootdir.logicalBlockNum, rootdir.partitionReferenceNum); goto error_out; } /* Allocate a dentry for the root inode */ sb->s_root = d_alloc_root(inode); if (!sb->s_root) { - printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n"); + udf_err(sb, __func__, "Couldn't allocate root dentry\n"); iput(inode); goto error_out; } @@ -2096,34 +2110,77 @@ error_out: return -EINVAL; } -static void udf_error(struct super_block *sb, const char *function, - const char *fmt, ...) +void udf_err(struct super_block *sb, const char *function, + const char *fmt, ...) { + struct va_format vaf; va_list args; + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + if (!(sb->s_flags & MS_RDONLY)) { /* mark sb error */ sb->s_dirt = 1; } + + pr_crit("error (device %s): %s: %pV", sb->s_id, function, &vaf); + va_end(args); +} + +void udf_warn(struct super_block *sb, const char *function, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + va_start(args, fmt); - vsnprintf(error_buf, sizeof(error_buf), fmt, args); + + vaf.fmt = fmt; + vaf.va = &args; + + pr_warn("warning (device %s): %s: %pV", sb->s_id, function, &vaf); va_end(args); - printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n", - sb->s_id, function, error_buf); } -void udf_warning(struct super_block *sb, const char *function, - const char *fmt, ...) +void udf_info(struct super_block *sb, const char *fmt, ...) { + struct va_format vaf; va_list args; va_start(args, fmt); - vsnprintf(error_buf, sizeof(error_buf), fmt, args); + + vaf.fmt = fmt; + vaf.va = &args; + + pr_info("info (device %s): %pV", sb->s_id, &vaf); va_end(args); - printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n", - sb->s_id, function, error_buf); } +#ifdef udf_debug +void udf_debug(struct super_block *sb, const char *function, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; + + pr_debug("debug (device %s): %s: %pV", sb->s_id, function, &vaf); + va_end(args); +} +#else +void udf_debug(struct super_block *sb, const char *function, + const char *fmt, ...) +{ + return; +} +#endif + static void udf_put_super(struct super_block *sb) { int i; @@ -2213,11 +2270,11 @@ static unsigned int udf_count_free_bitmap(struct super_block *sb, bh = udf_read_ptagged(sb, &loc, 0, &ident); if (!bh) { - printk(KERN_ERR "udf: udf_count_free failed\n"); + udf_err(sb, __func__, "udf_count_free failed\n"); goto out; } else if (ident != TAG_IDENT_SBD) { brelse(bh); - printk(KERN_ERR "udf: udf_count_free failed\n"); + udf_err(sb, __func__, "udf_count_free failed\n"); goto out; } @@ -2236,7 +2293,7 @@ static unsigned int udf_count_free_bitmap(struct super_block *sb, newblock = udf_get_lb_pblock(sb, &loc, ++block); bh = udf_tread(sb, newblock); if (!bh) { - udf_debug("read failed\n"); + udf_debug(sb, __func__, "read failed\n"); goto out; } index = 0; diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c index 8424308..f07ef23 100644 --- a/fs/udf/truncate.c +++ b/fs/udf/truncate.c @@ -95,23 +95,24 @@ void udf_truncate_tail_extent(struct inode *inode) lbcount += elen; if (lbcount > inode->i_size) { if (lbcount - inode->i_size >= inode->i_sb->s_blocksize) - printk(KERN_WARNING - "udf_truncate_tail_extent(): Too long " - "extent after EOF in inode %u: i_size: " - "%Ld lbcount: %Ld extent %u+%u\n", - (unsigned)inode->i_ino, - (long long)inode->i_size, - (long long)lbcount, - (unsigned)eloc.logicalBlockNum, - (unsigned)elen); + udf_warn(inode->i_sb, __func__, + "udf_truncate_tail_extent(): Too long " + "extent after EOF in inode %u: i_size: " + "%lld lbcount: %lld extent %u+%u\n", + (unsigned)inode->i_ino, + (long long)inode->i_size, + (long long)lbcount, + (unsigned)eloc.logicalBlockNum, + (unsigned)elen); nelen = elen - (lbcount - inode->i_size); epos.offset -= adsize; extent_trunc(inode, &epos, &eloc, etype, elen, nelen); epos.offset += adsize; if (udf_next_aext(inode, &epos, &eloc, &elen, 1) != -1) - printk(KERN_ERR "udf_truncate_tail_extent(): " - "Extent after EOF in inode %u.\n", - (unsigned)inode->i_ino); + udf_warn(inode->i_sb, __func__, + "udf_truncate_tail_extent(): " + "Extent after EOF in inode %u.\n", + (unsigned)inode->i_ino); break; } } diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index dbd52d4b..3d4cc4d 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -1,6 +1,8 @@ #ifndef __UDF_DECL_H #define __UDF_DECL_H +#define pr_fmt(fmt) "UDF-fs " fmt + #include "ecma_167.h" #include "osta_udf.h" @@ -16,22 +18,22 @@ #define UDF_PREALLOCATE #define UDF_DEFAULT_PREALLOC_BLOCKS 8 -#undef UDFFS_DEBUG +__attribute__((format(printf, 3, 4))) +void udf_err(struct super_block *sb, const char *function, + const char *fmt, ...); + +__attribute__((format(printf, 3, 4))) +void udf_warn(struct super_block *sb, const char *function, + const char *fmt, ...); -#ifdef UDFFS_DEBUG -#define udf_debug(f, a...) \ -do { \ - printk(KERN_DEBUG "UDF-fs DEBUG %s:%d:%s: ", \ - __FILE__, __LINE__, __func__); \ - printk(f, ##a); \ -} while (0) -#else -#define udf_debug(f, a...) /**/ -#endif +__attribute__((format(printf, 2, 3))) +void udf_info(struct super_block *sb, const char *fmt, ...); -#define udf_info(f, a...) \ - printk(KERN_INFO "UDF-fs INFO " f, ##a); +#undef UDFFS_DEBUG +__attribute__((format(printf, 3, 4))) +void udf_debug(struct super_block *sb, const char *function, + const char *fmt, ...); #define udf_fixed_to_variable(x) ( ( ( (x) >> 5 ) * 39 ) + ( (x) & 0x0000001F ) ) #define udf_variable_to_fixed(x) ( ( ( (x) / 39 ) << 5 ) + ( (x) % 39 ) ) @@ -112,8 +114,6 @@ struct extent_position { /* super.c */ -__attribute__((format(printf, 3, 4))) -extern void udf_warning(struct super_block *, const char *, const char *, ...); static inline void udf_updated_lvid(struct super_block *sb) { struct buffer_head *bh = UDF_SB(sb)->s_lvid_bh; @@ -202,7 +202,8 @@ extern int udf_get_filename(struct super_block *, uint8_t *, uint8_t *, int); extern int udf_put_filename(struct super_block *, const uint8_t *, uint8_t *, int); extern int udf_build_ustr(struct ustr *, dstring *, int); -extern int udf_CS0toUTF8(struct ustr *, const struct ustr *); +extern int udf_CS0toUTF8(struct super_block *, struct ustr *, + const struct ustr *); /* ialloc.c */ extern void udf_free_inode(struct inode *); @@ -228,10 +229,12 @@ extern struct fileIdentDesc *udf_fileident_read(struct inode *, loff_t *, struct extent_position *, struct kernel_lb_addr *, uint32_t *, sector_t *); -extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, - int *offset); -extern struct long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int); -extern struct short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int); +extern struct fileIdentDesc *udf_get_fileident(struct inode *, void *buffer, + int bufsize, int *offset); +extern struct long_ad *udf_get_filelongad(struct inode *, uint8_t *, int, + uint32_t *, int); +extern struct short_ad *udf_get_fileshortad(struct inode *, uint8_t *, int, + uint32_t *, int); /* udftime.c */ extern struct timespec *udf_disk_stamp_to_time(struct timespec *dest, diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c index b8c828c..927c931 100644 --- a/fs/udf/udftime.c +++ b/fs/udf/udftime.c @@ -34,9 +34,9 @@ * http://www.boulder.nist.gov/timefreq/pubs/bulletin/leapsecond.htm */ +#include "udfdecl.h" #include #include -#include "udfdecl.h" #define EPOCH_YEAR 1970 diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c index d03a90b..9ce8b95 100644 --- a/fs/udf/unicode.c +++ b/fs/udf/unicode.c @@ -99,7 +99,8 @@ static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) * November 12, 1997 - Andrew E. Mileski * Written, tested, and released. */ -int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i) +int udf_CS0toUTF8(struct super_block *sb, struct ustr *utf_o, + const struct ustr *ocu_i) { const uint8_t *ocu; uint8_t cmp_id, ocu_len; @@ -114,8 +115,8 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i) cmp_id = ocu_i->u_cmpID; if (cmp_id != 8 && cmp_id != 16) { memset(utf_o, 0, sizeof(struct ustr)); - printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", - cmp_id, ocu_i->u_name); + udf_err(sb, __func__, "unknown compression code (%d) stri=%s\n", + cmp_id, ocu_i->u_name); return 0; } @@ -174,7 +175,8 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i) * November 12, 1997 - Andrew E. Mileski * Written, tested, and released. */ -static int udf_UTF8toCS0(dstring *ocu, struct ustr *utf, int length) +static int udf_UTF8toCS0(struct super_block *sb, dstring *ocu, struct ustr *utf, + int length) { unsigned c, i, max_val, utf_char; int utf_cnt, u_len; @@ -242,7 +244,7 @@ try_again: if (utf_cnt) { error_out: ocu[++u_len] = '?'; - printk(KERN_DEBUG "udf: bad UTF-8 character\n"); + udf_debug(sb, __func__, "bad UTF-8 character\n"); } ocu[length - 1] = (uint8_t)u_len + 1; @@ -250,8 +252,8 @@ error_out: return u_len + 1; } -static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, - const struct ustr *ocu_i) +static int udf_CS0toNLS(struct super_block *sb, struct nls_table *nls, + struct ustr *utf_o, const struct ustr *ocu_i) { const uint8_t *ocu; uint8_t cmp_id, ocu_len; @@ -267,8 +269,8 @@ static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, cmp_id = ocu_i->u_cmpID; if (cmp_id != 8 && cmp_id != 16) { memset(utf_o, 0, sizeof(struct ustr)); - printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", - cmp_id, ocu_i->u_name); + udf_err(sb, __func__, "unknown compression code (%d) stri=%s\n", + cmp_id, ocu_i->u_name); return 0; } @@ -293,8 +295,8 @@ static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, return utf_o->u_len; } -static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, - int length) +static int udf_NLStoCS0(struct super_block *sb, struct nls_table *nls, + dstring *ocu, struct ustr *uni, int length) { int len; unsigned i, max_val; @@ -351,16 +353,18 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname, goto out2; if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { - if (!udf_CS0toUTF8(filename, unifilename)) { - udf_debug("Failed in udf_get_filename: sname = %s\n", - sname); + if (!udf_CS0toUTF8(sb, filename, unifilename)) { + udf_debug(sb, __func__, + "Failed in udf_get_filename: sname = %s\n", + sname); goto out2; } } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { - if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, filename, + if (!udf_CS0toNLS(sb, UDF_SB(sb)->s_nls_map, filename, unifilename)) { - udf_debug("Failed in udf_get_filename: sname = %s\n", - sname); + udf_debug(sb, __func__, + "Failed in udf_get_filename: sname = %s\n", + sname); goto out2; } } else @@ -385,11 +389,11 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname, return 0; if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { - namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN); + namelen = udf_UTF8toCS0(sb, dname, &unifilename, UDF_NAME_LEN); if (!namelen) return 0; } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { - namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, + namelen = udf_NLStoCS0(sb, UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN); if (!namelen) return 0; -- 1.7.4.4