Received: by 10.223.176.5 with SMTP id f5csp2863969wra; Mon, 29 Jan 2018 05:20:39 -0800 (PST) X-Google-Smtp-Source: AH8x227drz6bUx3UIYmASKQanw+7ZZnGDloJxgRu9PZ0T+TTu0KuBlA0hIl2L6zIiPrea/FWf8cm X-Received: by 2002:a17:902:42a3:: with SMTP id h32-v6mr21440002pld.56.1517232039045; Mon, 29 Jan 2018 05:20:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517232038; cv=none; d=google.com; s=arc-20160816; b=akHRJY1qc1x6uITy31dBOs8g1cWvDASKBqFSVu8Uz3FGsnq4UsodGpt/nMaxjOBY8J BAFjR8atGm3FdssJv5sPg62Pf0JJJ2ccNdSU8rZuv5Vi0BeEe+NiCogkKAaKfI64sY5X TZCKlwhDkd/8RGz7j0RWgtAFCzxLIQzuqDXw9P7RG/BEQCEK9Mp23h4fbhfzWD0kfuZ1 sKrbeqbAVDuk4ABnlt6yTVX7R5F6peV9CI7n1kRVaaWeslqJXUc1tKmE8ex17lJQ97CM DMoqKGx/CDcCVjEPOBujdWLEFtuwPTftoariFlAVi7aAYV8zb+y/xNhKo31J/NBDT/aa aVzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=YrvlRj99uF1yyIimjFzfKU5dTzN9dPX1fBL4t+iYZwk=; b=fdV9xqU3fviEfbPEY3315WWbHtpkycesO4wr202mHw85nfVuM4pgxogwjOYxVdRJW9 14eMkJos8hCEbgqGvFd2RFu1U5m/ASom3QiJYofCxWc+GSzqVbHj+jIFUcZU1nrdGtW0 0Sdn/hGXoj+c28Gpme2epRKhWuarx4mLvLnAIB5rQ8XTMyld2TEMKutca5ryxok2rNBU c9nXO8lx8CnpNAyB+ahxJXQLxuOPZobBPScULqvUo1FN1gvcM0DCoEX1Y/aEsDhqbfHA YM/l6eM9e1AMW4Y9QbtQu0drmwH2QQnKuGSMepfI2CvtTpHh80dGizzp3F9lWHLmPaVo Uc7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vY9tXuiK; 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 v195si7435742pgb.628.2018.01.29.05.20.24; Mon, 29 Jan 2018 05:20:38 -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=vY9tXuiK; 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 S1751964AbeA2NSp (ORCPT + 99 others); Mon, 29 Jan 2018 08:18:45 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:40899 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbeA2NSo (ORCPT ); Mon, 29 Jan 2018 08:18:44 -0500 Received: by mail-qk0-f196.google.com with SMTP id d18so5418841qke.7 for ; Mon, 29 Jan 2018 05:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=YrvlRj99uF1yyIimjFzfKU5dTzN9dPX1fBL4t+iYZwk=; b=vY9tXuiKrKT0wkJYM2/T1Krumi43qTTfO8GnJxdIPo/2RpvOqRU0rtojRYC7x+57hL hJ+JWgsXs1xE/0YbGHXa2iGtpAF3fNMhR1XtVZBaboanqNOfquuARnEDDKJ9aoqYxDQ5 ybhOOU15i/Cnz8MPCJLQ04xnMO+oSK6i4XjgCKb9FLRQwqdZ1czaGeBcFw/OSbJVQiTh L1RC5bLnk6pp6a0yajjzXWVWo5fYJH2fsLFGCbYdQKpYzzHslk1O7cZrQD9Ci93mbMeJ OFz4EvbpnWelYhK1Zqux5IuvbQplBjvEIL6Hb4VnoJjQ3aFFYY2VA1cx2DUAK5/EEy5w 6nIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=YrvlRj99uF1yyIimjFzfKU5dTzN9dPX1fBL4t+iYZwk=; b=kHKEy5jDKlB785SGTsGrtBFzk69RlKiATTPvVL+2pxMIpv88LZYWdKUeuNAUrcRL0Q 0Vxi6NrNQc1mCReq2bIbMbjHuIQQiHk6ss15lKksob+l1xvvWou+lF2Z9uUFrzJR2MTF BHHjHEcVRsrVgcN6o29BZWC+cEbvmlQ2CenZBDxBqnu1EmzIj8xwlOOWOnAWbu8mlaO6 K1lDFrVKBTo3zDzZfSqVQDUkdDO52nrwyrHXMyW3Q9Y9mCyKXSOJ/Nix1TG8NL94d+Hf 2zJItSWDby+rLlIZoCioa36ubp0iZvlKXJ5Xyn9Ap6fdHWDlGySB9CQLd6lz/DMftkor s4vQ== X-Gm-Message-State: AKwxyte5iNPzHs99W4Rt/vmE9lkDn75PhyzrTaF4oXrXDibol0jN7jBD MmUD3xL5P4yMIZ1KpKtyAy6JuZ0CG+ash4leyC8= X-Received: by 10.55.185.134 with SMTP id j128mr31428103qkf.341.1517231923421; Mon, 29 Jan 2018 05:18:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.175.35 with HTTP; Mon, 29 Jan 2018 05:18:42 -0800 (PST) In-Reply-To: <20180117104355.889-4-chen.chenchacha@foxmail.com> References: <20180117104355.889-1-chen.chenchacha@foxmail.com> <20180117104355.889-4-chen.chenchacha@foxmail.com> From: Andy Shevchenko Date: Mon, 29 Jan 2018 15:18:42 +0200 Message-ID: Subject: Re: [PATCH 3/3] fs: fat: add ioctl method in fat filesystem driver To: ChenGuanqiao , =?UTF-8?Q?Pali_Roh=C3=A1r?= Cc: OGAWA Hirofumi , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Cc: Pali, who AFAIRC is interested in FAT labeling mess. On Wed, Jan 17, 2018 at 12:43 PM, ChenGuanqiao wrote: Commit message? > Signed-off-by: ChenGuanqiao > #include > #include > #include > +#include It would be better to squeeze it to have order (to some extent) preserved. > +static int fat_check_d_characters(char *label, unsigned long len) > +{ > + int i; > + > + for (i = 0; i < len; ++i) { Oy vey, unsigned long len vs. int i. > + switch (label[i]) { > + case 'a' ... 'z': > + label[i] = __toupper(label[i]); > + case 'A' ... 'Z': > + case '0' ... '9': > + case '_': > + case 0x20: > + continue; I'm not sure this is best approach. And since there is no commit message I can't be constructive. > + default: > + return -EINVAL; > + } > + } > + > + return 0; > +} > +static int fat_ioctl_get_volume_label(struct inode *inode, > + u8 __user *vol_label) > +{ > + int err = 0; Redundant assignment. > + struct buffer_head *bh; > + struct msdos_dir_entry *de; > + struct super_block *sb = inode->i_sb; Moreover, perhaps reversed tree order for the definition block? > + > + inode = d_inode(sb->s_root); > + inode_lock_shared(inode); > + > + err = fat_get_volume_label_entry(inode, &bh, &de); > + if (err) > + goto out; > + > + if (copy_to_user(vol_label, de->name, MSDOS_NAME)) > + err = -EFAULT; > + > + brelse(bh); > +out: > + inode_unlock_shared(inode); > + > + return err; > +} > + > +static int fat_ioctl_set_volume_label(struct file *file, > + u8 __user *vol_label) Perhaps vol_label -> label, and fit one line? > +{ > + int err = 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 = file_inode(file); > + struct super_block *sb = inode->i_sb; > + struct msdos_sb_info *sbi = MSDOS_SB(sb); > + > + inode = d_inode(sb->s_root); > + > + if (copy_from_user(label, vol_label, sizeof(label))) { > + err = -EFAULT; > + goto out; > + } > + > + err = fat_check_d_characters(label, sizeof(label)); > + if (err) > + goto out; > + > + err = mnt_want_write_file(file); > + if (err) > + goto out; > + > + down_write(&sb->s_umount); > + > + /* Updates root directory's vol_label */ > + err = fat_get_volume_label_entry(inode, &vol_bh, &de); > + ts = current_time(inode); > + if (err) { > + /* Create volume label entry */ > + err = 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)); > + inode->i_ctime = inode->i_mtime = inode->i_atime = ts; > + > + mark_buffer_dirty(vol_bh); > + } > + > + /* Update sector's vol_label */ > + boot_bh = sb_bread(sb, 0); > + if (boot_bh == NULL) { > + fat_msg(sb, KERN_ERR, > + "unable to read boot sector to write volume label"); > + err = -EIO; > + goto out_boot_brelse; > + } > + > + b = (struct fat_boot_sector *)boot_bh->b_data; > + 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(boot_bh); > + > + /* Synchronize the data together */ > + err = 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; > +} -- With Best Regards, Andy Shevchenko