Received: by 10.223.176.5 with SMTP id f5csp3097932wra; Mon, 29 Jan 2018 08:43:51 -0800 (PST) X-Google-Smtp-Source: AH8x226lq6hpdrzxi3GzZ69+G8qBEdrK3F+lyNvvWcqqkyzpmvbo+P/6ezBqAz7ClYjCeyBD1kIS X-Received: by 2002:a17:902:6b89:: with SMTP id p9-v6mr22670622plk.377.1517244230960; Mon, 29 Jan 2018 08:43:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517244230; cv=none; d=google.com; s=arc-20160816; b=gdam12AF2RNerWGPuJoXmo8jitfZ30/vGNLOND+0sSWEh9j9lfBDPy9TCW6qP/uf6B 1ZihqeT8X2mzekDlBIXgrML/2dCG4cyDbgxkZI+cgmzefkUmOubFZYoRWXOOkuZRxLo4 EOE+sT43RTsV4lvRHmKjsHwZprQ3ZIfCJfgLxszxLuVkpXC+YghNbzCa0DqxwXkbbx76 GO0H0PTwingwuxE5k8sFraU2t8O1L91QnZa1fFYaafzJe7280drQ0EhDig9t17xZZjR6 BPV0RSe0nMqBpRA9A5BYUoh9Y18uRDmlpNUmnisEUPs4VNx1v98j+Oe7SpCqZpbX3gvy rqdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=vza3S8g9ydgP+YAzhgLB2aK8/WvzVI5kvsF7jokXh88=; b=jdYCvLdbCIBmVzOUn+N+9WWg5CbQ9D1xD/PSBWBuHAfvG3MmLZ1oCmi9w73n5Zvxc1 1Vle0/Proj4mhoyYH/PjzX9+hHFU9n6VCGeZSY0Tr8Q9rvUwm85L3uq7uolQ4A8nrSeS LkQcg5XJ8PhzneHUsrYjxzrYycH6j4OwyI4dcc9cQwBUOCUVESo4MkywWyLtXgCCKPLg bJz90EzLfoD7i3xueH0tTv7hchP/gixF69eW/pPw2DFmq/FhgspcKJ1oeR4/oM9PFfMX zxyayHp8BWc1dR7pLjeMf+F/ghOdTbR5Z978/BZ6aM111OXOrP1OHuT4m1YwP8TLtYHJ 8Y7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IU877xS+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a70si7744800pge.448.2018.01.29.08.43.36; Mon, 29 Jan 2018 08:43:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IU877xS+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751411AbeA2QnK (ORCPT + 99 others); Mon, 29 Jan 2018 11:43:10 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39807 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751072AbeA2QnI (ORCPT ); Mon, 29 Jan 2018 11:43:08 -0500 Received: by mail-wr0-f194.google.com with SMTP id f6so6303691wra.6 for ; Mon, 29 Jan 2018 08:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=vza3S8g9ydgP+YAzhgLB2aK8/WvzVI5kvsF7jokXh88=; b=IU877xS+ozcQjeI8dB9Hs+34gy4D8UwJpryqwEHpAgjD5CmSbKUg9Le81d46SKiEtg jdYn8W8ay05vpIrXshhI8g210RZmCIyVnAlEyUDnZaxhYpHbeOGsycFmLePTPU8NPvyf +Eh1L0WyNw9Osy/vcsqo8a+xfkAmU3Qpm8GLdeywFsIDMa0JRJMe1jJ5aHKyKG84k8at D4VYXW425Fr6QfTxLPLXqPslmOpRvvQOs9TO8Y+R0/5+4Na6+7rFIzpvJ8gVhkMiZ/tN Ct0liQ+quIbuYW9gZ+YTLBAKNqf9jvZh9vdm4s7TQFaKxz6tb8bWafS58qGrVStnjYfk 0DEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=vza3S8g9ydgP+YAzhgLB2aK8/WvzVI5kvsF7jokXh88=; b=CaNAvJbIdX8Ka/h6DTGqzNafjyixpwuRc5RbB/XfmI+aEl2xjB+oCE1vs0o/ELNaox I37KHrCq+CAiiUtEZVKL9Fd27sJBIRO6oO8JS3dpQEP9zthhx3NgJ+w0de1v3B0jpyXr idwLrTypQIvA8RNW2XWCqVAsCDw+vpYblIR7M2iHTlLphbkkBa+FZMDg3XaEv/GBn1j/ 5EtAf4NbAERnS+XcGB81LmddepgnD8td5YrvdunR69uc0obYMlkiwjfNM1nFYXsrHNk9 atDSs4U8i6U604Ikko9zDydpwynTJe4UclYBFriRX5sL820AubZDW2KUCSzdYC7BPDNI 0a5w== X-Gm-Message-State: AKwxytev5Zir8S5mWGu+9+O/Vc3d7p+SdwD1kKfCayAcpxGzyXkMxy36 7IgbOib/4vpxyqj3v8VoioAClQ== X-Received: by 10.223.179.193 with SMTP id x1mr18945777wrd.171.1517244187544; Mon, 29 Jan 2018 08:43:07 -0800 (PST) Received: from pali ([2a02:2b88:2:1::5cc6:2f]) by smtp.gmail.com with ESMTPSA id z41sm16746628wrb.50.2018.01.29.08.43.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jan 2018 08:43:06 -0800 (PST) Date: Mon, 29 Jan 2018 17:43:04 +0100 From: Pali =?utf-8?B?Um9ow6Fy?= To: Andy Shevchenko Cc: ChenGuanqiao , OGAWA Hirofumi , Linux Kernel Mailing List Subject: Re: [PATCH 3/3] fs: fat: add ioctl method in fat filesystem driver Message-ID: <20180129164304.44on6tdlhpzcwarv@pali> References: <20180117104355.889-1-chen.chenchacha@foxmail.com> <20180117104355.889-4-chen.chenchacha@foxmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ld7gx26c7xpqj5fn" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ld7gx26c7xpqj5fn Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Monday 29 January 2018 15:18:42 Andy Shevchenko wrote: > +Cc: Pali, who AFAIRC is interested in FAT labeling mess. Yes, please CC me for FAT labeling discussing in future. > On Wed, Jan 17, 2018 at 12:43 PM, ChenGuanqiao > wrote: >=20 > Commit message? >=20 > > Signed-off-by: ChenGuanqiao >=20 > > #include > > #include > > #include > > +#include >=20 > It would be better to squeeze it to have order (to some extent) preserved. >=20 > > +static int fat_check_d_characters(char *label, unsigned long len) > > +{ > > + int i; > > + > > + for (i =3D 0; i < len; ++i) { >=20 > Oy vey, unsigned long len vs. int i. >=20 > > + switch (label[i]) { > > + case 'a' ... 'z': > > + label[i] =3D __toupper(label[i]); Why only lower a..z? =C3=A1 or =C3=B3 are also valid (according to some OEM codepage) and are lower case. Also please look at my testing results. Even old DOS versions are able to correctly read lower case label. Therefore I do not see any reason why to have such "force" code in kernel. https://www.spinics.net/lists/kernel/msg2645732.html Here I proposed how should be linux tools unified which manipulates with fat label. > > + case 'A' ... 'Z': > > + case '0' ... '9': > > + case '_': > > + case 0x20: > > + continue; >=20 > I'm not sure this is best approach. And since there is no commit > message I can't be constructive. >=20 > > + default: > > + return -EINVAL; And what about other valid characters? Why are ignored and returned error? > > + } > > + } > > + > > + return 0; > > +} >=20 > > +static int fat_ioctl_get_volume_label(struct inode *inode, > > + u8 __user *vol_label) > > +{ >=20 > > + int err =3D 0; >=20 > Redundant assignment. >=20 > > + struct buffer_head *bh; > > + struct msdos_dir_entry *de; > > + struct super_block *sb =3D inode->i_sb; >=20 > Moreover, perhaps reversed tree order for the definition block? >=20 > > + > > + inode =3D d_inode(sb->s_root); > > + inode_lock_shared(inode); > > + > > + err =3D fat_get_volume_label_entry(inode, &bh, &de); > > + if (err) > > + goto out; > > + > > + if (copy_to_user(vol_label, de->name, MSDOS_NAME)) > > + err =3D -EFAULT; > > + > > + brelse(bh); > > +out: > > + inode_unlock_shared(inode); > > + > > + return err; > > +} > > + >=20 > > +static int fat_ioctl_set_volume_label(struct file *file, > > + u8 __user *vol_label) >=20 > Perhaps vol_label -> label, and fit one line? >=20 > > +{ > > + int err =3D 0; > > + u8 label[MSDOS_NAME]; > > + struct timespec ts; > > + struct buffer_head *boot_bh; > > + struct buffer_head *vol_bh; > > + struct msdos_dir_entry *de; > > + struct fat_boot_sector *b; > > + struct inode *inode =3D file_inode(file); > > + struct super_block *sb =3D inode->i_sb; > > + struct msdos_sb_info *sbi =3D MSDOS_SB(sb); > > + > > + inode =3D d_inode(sb->s_root); > > + > > + if (copy_from_user(label, vol_label, sizeof(label))) { > > + err =3D -EFAULT; > > + goto out; > > + } > > + > > + err =3D fat_check_d_characters(label, sizeof(label)); > > + if (err) > > + goto out; > > + > > + err =3D mnt_want_write_file(file); > > + if (err) > > + goto out; > > + > > + down_write(&sb->s_umount); > > + > > + /* Updates root directory's vol_label */ > > + err =3D fat_get_volume_label_entry(inode, &vol_bh, &de); > > + ts =3D current_time(inode); > > + if (err) { > > + /* Create volume label entry */ Not handling situation when buffer is empty which means that user what to remove label. Entry name in FAT directory cannot be empty string. > > + err =3D fat_add_volume_label_entry(inode, label, &ts); > > + if (err) > > + goto out_vol_brelse; > > + } else { > > + /* Write to root directory */ > > + memcpy(de->name, label, sizeof(de->name)); Really? You forgot for 0x05/0xE5 handling. And also conversion from VFS NLS encoding to OEM code page. Anyway, kernel's fat driver already has this conversion implemented in some function, so it is better to not reinvent wheel. > > + inode->i_ctime =3D inode->i_mtime =3D inode->i_atime = =3D ts; > > + > > + mark_buffer_dirty(vol_bh); > > + } > > + > > + /* Update sector's vol_label */ > > + boot_bh =3D sb_bread(sb, 0); > > + if (boot_bh =3D=3D NULL) { > > + fat_msg(sb, KERN_ERR, > > + "unable to read boot sector to write volume lab= el"); > > + err =3D -EIO; > > + goto out_boot_brelse; > > + } > > + > > + b =3D (struct fat_boot_sector *)boot_bh->b_data; > > + if (sbi->fat_bits =3D=3D 32) > > + memcpy(b->fat32.vol_label, label, sizeof(label)); > > + else > > + memcpy(b->fat16.vol_label, label, sizeof(label)); Missing NO NAME handling. > > + mark_buffer_dirty(boot_bh); > > + > > + /* Synchronize the data together */ > > + err =3D sync_dirty_buffer(boot_bh); > > + if (err) > > + goto out_boot_brelse; > > + > > +out_boot_brelse: > > + brelse(boot_bh); > > +out_vol_brelse: > > + brelse(vol_bh); > > + > > + up_write(&sb->s_umount); > > + mnt_drop_write_file(file); > > +out: > > + return err; > > +} >=20 >=20 >=20 --=20 Pali Roh=C3=A1r pali.rohar@gmail.com --ld7gx26c7xpqj5fn Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQS4VrIQdKium2krgIWL8Mk9A+RDUgUCWm9PFgAKCRCL8Mk9A+RD UqquAKCR3rO/NRxUP9OCrenucE+XfrXtNACfa8OmGA75fBvhyZaLiT8HxjjnW5E= =Zj9G -----END PGP SIGNATURE----- --ld7gx26c7xpqj5fn--