Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932756AbeAJKYm (ORCPT + 1 other); Wed, 10 Jan 2018 05:24:42 -0500 Received: from smtpbgau2.qq.com ([54.206.34.216]:39503 "EHLO smtpbgau2.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755632AbeAJKYf (ORCPT ); Wed, 10 Jan 2018 05:24:35 -0500 X-QQ-mid: esmtp15t1515579869tqurz9s8v X-QQ-SSF: A1000000000000706H110000000000P X-QQ-FEAT: yN/dV50aaV/FdwKZVLN82FRWl1qksoiaQlHw3x6Lcyvy/xZESqlRRYfRKgUnY QmDPOtN58KYHlslol5Fz0aP0Xpm/BFKlSk/W1pzv29nknkdWh/KGUnedQqWx8nXGjlWL/Kw KB+7EbnRadLb38RcCFv8QJ2uf9TxN/opbiRrzBYF+4op8sLNmOBB5pdIw710dOd15rBMZJB QJCLktxtMPPku5b84r+aPVYN5IouyaTiZfyRBvx2E/nIQG3Mq/Mac53r1XwDTqBwh+ljBEw s2QeDaamfMLa94JZezXipFVY8= X-QQ-GoodBg: 0 From: ChenGuanqiao To: hirofumi@mail.parknet.co.jp Cc: linux-kernel@vger.kernel.org, ChenGuanqiao Subject: [PATCH v7 2/3] fs: fat: Add volume label entry method function Date: Wed, 10 Jan 2018 18:21:52 +0800 Message-Id: <20180110102153.12388-3-chen.chenchacha@foxmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180110102153.12388-1-chen.chenchacha@foxmail.com> References: <20180110102153.12388-1-chen.chenchacha@foxmail.com> X-QQ-SENDSIZE: 520 Feedback-ID: esmtp:foxmail.com:bgforeign:bgforeign1 X-QQ-Bgrelay: 1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Signed-off-by: ChenGuanqiao --- fs/fat/dir.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 8e100c3bf72c..53f36c03760e 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -881,6 +881,59 @@ static int fat_get_short_entry(struct inode *dir, loff_t *pos, return -ENOENT; } +int fat_get_volume_label_entry(struct inode *dir, struct buffer_head **bh, + struct msdos_dir_entry **de) +{ + loff_t pos = 0; + + if (dir->i_ino != MSDOS_ROOT_INO) + return -EFAULT; + + *bh = NULL; + *de = NULL; + while (fat_get_entry(dir, &pos, bh, de) >= 0) { + if (((*de)->attr & ATTR_VOLUME) && ((*de)->attr != ATTR_EXT) && + !IS_FREE((*de)->name)) + return 0; + } + return -ENOENT; +} +EXPORT_SYMBOL_GPL(fat_get_volume_label_entry); + +int fat_add_volume_label_entry(struct inode *dir, const unsigned char *name, + struct timespec *ts) +{ + struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb); + struct msdos_dir_entry de; + struct fat_slot_info sinfo; + __le16 time, date; + int err; + + if (dir->i_ino != MSDOS_ROOT_INO) + return -EFAULT; + + memcpy(de.name, name, MSDOS_NAME); + de.attr = ATTR_VOLUME; + de.lcase = 0; + fat_time_unix2fat(sbi, ts, &time, &date, NULL); + de.cdate = de.adate = 0; + de.ctime = 0; + de.ctime_cs = 0; + de.time = time; + de.date = date; + fat_set_start(&de, 0); + de.size = 0; + + err = fat_add_entries(dir, &de, 1, &sinfo); + if (err) + return err; + + brelse(sinfo.bh); + + return 0; +} +EXPORT_SYMBOL_GPL(fat_add_volume_label_entry); + /* * The ".." entry can not provide the "struct fat_slot_info" information * for inode, nor a usable i_pos. So, this function provides some information -- 2.11.0