From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: ChenGuanqiao <chen.chenchacha@foxmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/2] fs: fat: add ioctl method in fat filesystem driver
Date: Wed, 27 Dec 2017 22:29:38 +0900 [thread overview]
Message-ID: <87efngwb7h.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <20171227091714.4566-3-chen.chenchacha@foxmail.com> (ChenGuanqiao's message of "Wed, 27 Dec 2017 17:17:14 +0800")
ChenGuanqiao <chen.chenchacha@foxmail.com> writes:
> +/* the characters in this field shall be d-characters, and unused byte shall be set to 0x20. */
> +static int fat_format_d_characters(char *label, unsigned long len)
> +{
> + int i;
> +
> + for (i=0; i<len; ++i) {
> + switch (label[i]) {
> + case '0' ... '9':
> + case 'A' ... 'Z':
> + case '_':
> + continue;
> + default:
> + break;
> + }
> + break;
> + }
> +
> + for (; i<len; ++i)
> + label[i] = 0x20;
> +
> + return len;
> +}
It should not accept and overwrite invalid char, return -EINVAL.
> +static int fat_ioctl_get_volume_label(struct inode *inode,
> + u8 __user *vol_label)
> +{
> + int err = 0;
> + struct fat_slot_info sinfo;
> +
> + err = fat_scan_volume_label(inode, &sinfo);
> + if (err)
> + goto out;
It needs to take inode read lock.
> + if (copy_to_user(vol_label, sinfo.de->name, MSDOS_NAME))
> + err = -EFAULT;
> +
> + brelse(sinfo.bh);
> +out:
> + return err;
> +}
> +
> +static int fat_ioctl_set_volume_label(struct file *file,
> + u8 __user *vol_label)
> +{
[...]
> + b = (struct fat_boot_sector *)bh->b_data;
> +
> + lock_buffer(bh);
Probably, sb->s_umount to exclusive with remount update.
> + if (sbi->fat_bits == 32)
> + memcpy(b->fat32.vol_label, label, sizeof(label));
> + else
> + memcpy(b->fat16.vol_label, label, sizeof(label));
> +
> + mark_buffer_dirty(bh);
> + unlock_buffer(bh);
> + err = sync_dirty_buffer(bh);
> + brelse(bh);
> + if (err)
> + goto out_drop_file;
It should not update before preparing is done and checking error.
> + /* updates root directory's vol_label */
> + err = fat_scan_volume_label(inode, &sinfo);
> + if (err)
> + goto out_drop_file;
It should add entry if no volume label.
> + lock_buffer(bh);
inode write lock.
> + memcpy(sinfo.de->name, label, sizeof(sinfo.de->name));
> + mark_buffer_dirty(bh);
> + unlock_buffer(bh);
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
prev parent reply other threads:[~2017-12-27 13:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-27 9:17 [PATCH v5 0/2] fs: fat: add ioctl to modify fat filesystem partion volume label ChenGuanqiao
2017-12-27 9:17 ` [PATCH v5 1/2] fs: fat: Add fat filesystem partition volume label in local structure ChenGuanqiao
2017-12-27 13:21 ` OGAWA Hirofumi
2017-12-27 9:17 ` [PATCH v5 2/2] fs: fat: add ioctl method in fat filesystem driver ChenGuanqiao
2017-12-27 13:29 ` 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=87efngwb7h.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
all inboxes | Powered by JetHome®