Skip to content

Commit

Permalink
fs/adfs: clean up error message printing
Browse files Browse the repository at this point in the history
Overhaul our message printing:

- provide a consistent way to print messages:
  - filesystem corruption should be reported via adfs_error()
  - everything else should use adfs_msg()
- clean up the error message printing when mounting a filesystem
- fix the messages printed by the big directory format code to only
  use adfs_error() when there is filesystem corruption, otherwise
  use adfs_msg().

Signed-off-by: Russell King <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Russell King authored and Al Viro committed Jun 27, 2019
1 parent 2e67080 commit ceb3b10
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
1 change: 1 addition & 0 deletions fs/adfs/adfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ __printf(3, 4)
void __adfs_error(struct super_block *sb, const char *function,
const char *fmt, ...);
#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
void adfs_msg(struct super_block *sb, const char *pfx, const char *fmt, ...);

/* super.c */

Expand Down
18 changes: 8 additions & 10 deletions fs/adfs/dir_fplus.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ adfs_fplus_read(struct super_block *sb, unsigned int id, unsigned int sz, struct
h = (struct adfs_bigdirheader *)dir->bh_fplus[0]->b_data;
size = le32_to_cpu(h->bigdirsize);
if (size != sz) {
printk(KERN_WARNING "adfs: adfs_fplus_read:"
" directory header size %X\n"
" does not match directory size %X\n",
size, sz);
adfs_msg(sb, KERN_WARNING,
"directory header size %X does not match directory size %X",
size, sz);
}

if (h->bigdirversion[0] != 0 || h->bigdirversion[1] != 0 ||
h->bigdirversion[2] != 0 || size & 2047 ||
h->bigdirstartname != cpu_to_le32(BIGDIRSTARTNAME)) {
printk(KERN_WARNING "adfs: dir object %X has"
" malformed dir header\n", id);
adfs_error(sb, "dir %06x has malformed header", id);
goto out;
}

Expand All @@ -60,9 +58,10 @@ adfs_fplus_read(struct super_block *sb, unsigned int id, unsigned int sz, struct
kcalloc(size, sizeof(struct buffer_head *),
GFP_KERNEL);
if (!bh_fplus) {
adfs_msg(sb, KERN_ERR,
"not enough memory for dir object %X (%d blocks)",
id, size);
ret = -ENOMEM;
adfs_error(sb, "not enough memory for"
" dir object %X (%d blocks)", id, size);
goto out;
}
dir->bh_fplus = bh_fplus;
Expand Down Expand Up @@ -93,8 +92,7 @@ adfs_fplus_read(struct super_block *sb, unsigned int id, unsigned int sz, struct
if (t->bigdirendname != cpu_to_le32(BIGDIRENDNAME) ||
t->bigdirendmasseq != h->startmasseq ||
t->reserved[0] != 0 || t->reserved[1] != 0) {
printk(KERN_WARNING "adfs: dir object %X has "
"malformed dir end\n", id);
adfs_error(sb, "dir %06x has malformed tail", id);
goto out;
}

Expand Down
45 changes: 29 additions & 16 deletions fs/adfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ void __adfs_error(struct super_block *sb, const char *function, const char *fmt,
va_end(args);
}

void adfs_msg(struct super_block *sb, const char *pfx, const char *fmt, ...)
{
struct va_format vaf;
va_list args;

va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
printk("%sADFS-fs (%s): %pV\n", pfx, sb->s_id, &vaf);
va_end(args);
}

static int adfs_checkdiscrecord(struct adfs_discrecord *dr)
{
int i;
Expand Down Expand Up @@ -203,8 +215,9 @@ static int parse_options(struct super_block *sb, char *options)
asb->s_ftsuffix = option;
break;
default:
printk("ADFS-fs: unrecognised mount option \"%s\" "
"or missing value\n", p);
adfs_msg(sb, KERN_ERR,
"unrecognised mount option \"%s\" or missing value",
p);
return -EINVAL;
}
}
Expand Down Expand Up @@ -377,19 +390,16 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)

sb_set_blocksize(sb, BLOCK_SIZE);
if (!(bh = sb_bread(sb, ADFS_DISCRECORD / BLOCK_SIZE))) {
adfs_error(sb, "unable to read superblock");
adfs_msg(sb, KERN_ERR, "error: unable to read superblock");
ret = -EIO;
goto error;
}

b_data = bh->b_data + (ADFS_DISCRECORD % BLOCK_SIZE);

if (adfs_checkbblk(b_data)) {
if (!silent)
printk("VFS: Can't find an adfs filesystem on dev "
"%s.\n", sb->s_id);
ret = -EINVAL;
goto error_free_bh;
goto error_badfs;
}

dr = (struct adfs_discrecord *)(b_data + ADFS_DR_OFFSET);
Expand All @@ -398,33 +408,31 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
* Do some sanity checks on the ADFS disc record
*/
if (adfs_checkdiscrecord(dr)) {
if (!silent)
printk("VPS: Can't find an adfs filesystem on dev "
"%s.\n", sb->s_id);
ret = -EINVAL;
goto error_free_bh;
goto error_badfs;
}

brelse(bh);
if (sb_set_blocksize(sb, 1 << dr->log2secsize)) {
bh = sb_bread(sb, ADFS_DISCRECORD / sb->s_blocksize);
if (!bh) {
adfs_error(sb, "couldn't read superblock on "
"2nd try.");
adfs_msg(sb, KERN_ERR,
"error: couldn't read superblock on 2nd try.");
ret = -EIO;
goto error;
}
b_data = bh->b_data + (ADFS_DISCRECORD % sb->s_blocksize);
if (adfs_checkbblk(b_data)) {
adfs_error(sb, "disc record mismatch, very weird!");
adfs_msg(sb, KERN_ERR,
"error: disc record mismatch, very weird!");
ret = -EINVAL;
goto error_free_bh;
}
dr = (struct adfs_discrecord *)(b_data + ADFS_DR_OFFSET);
} else {
if (!silent)
printk(KERN_ERR "VFS: Unsupported blocksize on dev "
"%s.\n", sb->s_id);
adfs_msg(sb, KERN_ERR,
"error: unsupported blocksize");
ret = -EINVAL;
goto error;
}
Expand Down Expand Up @@ -497,6 +505,11 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
}
return 0;

error_badfs:
if (!silent)
adfs_msg(sb, KERN_ERR,
"error: can't find an ADFS filesystem on dev %s.",
sb->s_id);
error_free_bh:
brelse(bh);
error:
Expand Down

0 comments on commit ceb3b10

Please sign in to comment.