mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Chen Guanqiao <chen.chenchacha@foxmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] fs: fat: add ioctl method in fat filesystem driver
Date: Sat, 23 Dec 2017 19:23:27 +0900	[thread overview]
Message-ID: <874loh4uao.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <25bdc7c814dedce538cb419804fdf0c0ca9d62cd.1514017201.git.chen.chenchacha@foxmail.com> (Chen Guanqiao's message of "Sat, 23 Dec 2017 16:25:12 +0800")

Chen Guanqiao <chen.chenchacha@foxmail.com> writes:

> +static int fat_check_volume_label(const char *label)
> +{
> +	int i;
> +
> +	for (i=0; i<11; ++i) {
> +		switch (label[i]) {
> +		case 0x20:
> +		case 'A' ... 'Z':
> +		case '0' ... '9':
> +			continue;
> +		case 0:
> +			return 0;
> +		default:
> +			return -EINVAL;
> +		}
> +	}
> +	return -EINVAL;
> +}

This check is really work? Especially what Windows show if '\0' is
included in label?

> +static int fat_ioctl_get_volume_label(struct inode *inode,
> +				      u8 __user *vol_label)
> +{
> +	int ret = 0;
> +	struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
> +
> +	if (copy_to_user(vol_label, sbi->vol_label, sizeof(sbi->vol_label)))
> +		ret = -EFAULT;
> +
> +	return ret;
> +}

This should handle the label in root dir too.

> +	inode_lock(inode);

Lock is not enough.

> +	if (sb_rdonly(inode->i_sb)) {
> +		err = -EROFS;
> +		goto out_unlock_inode;
> +	}

mnt_want_write_file() checks it already.

> +	/* handling sector's vol_label */
> +	bh = sb_bread(inode->i_sb, 0);
> +	if (bh == NULL) {
> +		fat_msg(inode->i_sb, KERN_ERR,
> +			"unable to read boot sector to write volume label");
> +		err = -EFAULT;

-EIO

> +	if (b->fat16.signature == 0x28 || b->fat32.signature == 0x28) {
> +		fat_msg(inode->i_sb, KERN_ERR,
> +			"volume label supported since OS/2 1.2 and MS-DOS 4.0 "
> +			"and higher");
> +		err = -EFAULT;
> +		goto out_unlock_inode;
> +	}

I don't know though, is this check necessary?

> +	/* handling root directory's vol_label */
> +	bh = sb_bread(sb, sbi->dir_start);
> +	entry = &((struct msdos_dir_entry *)(bh->b_data))[0];
> +
> +	lock_buffer(bh);
> +	memcpy(entry->name, label, sizeof(entry->name));
> +	mark_buffer_dirty(bh);
> +	unlock_buffer(bh);
> +	brelse(bh);

This totally doesn't work. Please check other implementations how to
handle label.

> + out_unlock_inode:
> +	inode_unlock(inode);

Missing release mnt_want_write_file().

Thanks.

      reply	other threads:[~2017-12-23 10:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-23  8:25 [PATCH v3 0/2] fs: fat: add ioctl to modify fat filesystem partion volume label Chen Guanqiao
2017-12-23  8:25 ` [PATCH v3 1/2] fs: fat: add fat filesystem partition volume label in local structure Chen Guanqiao
2017-12-23  8:25 ` [PATCH v3 2/2] fs: fat: add ioctl method in fat filesystem driver Chen Guanqiao
2017-12-23 10:23   ` OGAWA Hirofumi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874loh4uao.fsf@mail.parknet.co.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --cc=chen.chenchacha@foxmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome