From nobody Thu Apr 2 15:36:22 2026 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67B7D2FF148 for ; Tue, 17 Feb 2026 23:08:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771369736; cv=none; b=PiakjBqrNgOwDl4AolR4Z7HXErxu451QRXes40UBP0vKR8pmemeViYIXv3/d59ZvvQY3q7U9IRNufNwtkhucPFWj1SD3KWvRigFstFGOIpFzMZc1nAerOdDAQded9UqYbGXlYjri3pNtAOAU002fNKeJciDhoQE7A4/qhlWKRgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771369736; c=relaxed/simple; bh=bpyKdwxEgiGS0ibektv1g5DWi5ZbckLP8xYHNlvIEmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tyvsNHU51b3ym8I8IrgnvP7a7LncaBE10BIOv64qEMWHQvBjSRwRkvYhqXQceJ7afDiCcDjl8/weFQRrzTvqDztmwea/pjVy85KsJPmFzvbsO1HNyR+yU+80U0KVIy05dvrdIURPwabey3nNcHkId4MQwNCwbTtZ/YxcoXYHuP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=zetier.com; spf=pass smtp.mailfrom=zetier.com; dkim=pass (2048-bit key) header.d=zetier.com header.i=@zetier.com header.b=UQvxiKrI; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=zetier.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zetier.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zetier.com header.i=@zetier.com header.b="UQvxiKrI" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-89549b2f538so5878096d6.2 for ; Tue, 17 Feb 2026 15:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zetier.com; s=gm; t=1771369734; x=1771974534; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=67x0rmIMjc1SgKva+b4U06wk0ssnpT3jAfZBeoUNrj0=; b=UQvxiKrIyfeXPaHjdc4EPAg1rhTdynhZRhj2AeuMaf6fzevtiTPm8LL28BuJGJVIYd NcsS6aSfCBG3Sdqmr92xNgLOgFn8LIgviATv74z3jCGJNe9nA8hkoy2qjx5vLzPl2U3L UZfa9hTsJdbDUmjwAspuZONqYyPryZ+V3212+wklyMEDQikkrlXPGqYzKpD78dVTMAFq vT1QNZiJjwXW91fHIi4OMqNcIjcKVprSK9ZTiYpN/O3+fJg9y+8i+m+MlASDMlwPUbe6 TSZ9nHU+tv9wAzS6BKNdNiv7gDGko4NQIl9H0C+CXt4RMVq0rXXjk9plAQnysj0DW+xn DeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771369734; x=1771974534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=67x0rmIMjc1SgKva+b4U06wk0ssnpT3jAfZBeoUNrj0=; b=vE+uIcJ0Z/czmMDw+h3I0INiRNhVHp7kWKq8jqJqVgT8POneQo1AlCB9oA/Ptv6I1V 9TBO530Mf1idw1pDCaz2AMk9AV5nhrOTJYgt3PBFMfdGVRqxeGB6Jug+KgcYjKXIf+An ARqFBXAPKZ2Uv2Gm3s9EKbjw5v7bQgqNtvJe819ltGCCs0O7mOpNhySCEq6mGXr3j/Vq uIG8be7U+wd97sQCnKrlk8+O5New2r3fF8KutLH0FiWkxgmCAtBNOi0rbij7XSH2D+Md xbelhtYZfacw/CsFszUlOU/hRGU4OPi7U+w8kOBdCAThHWJoCdTjcQE9JO+j+OwCqwDI xUiw== X-Forwarded-Encrypted: i=1; AJvYcCXOrNySwZisyTvCd0E7pz432jQhBJ0ypFMg6SP16RDRwhFKumvkLhLUw09u1WImoEqhgg+0HxodHx2dV1g=@vger.kernel.org X-Gm-Message-State: AOJu0YyAUmRcySv7dfBmrurD61zAK+vvAChPDu+/t1WegcQzmEzO9WJW e2DaALxFugHukSK023SZ4z7pz9te1zXJa6Imb7GPiwfQJ7CQiwXlhmHXTAFE3pXjG2Y= X-Gm-Gg: AZuq6aI2eMXE0slV6LIgYKN5q77eZHkVLJQ1cUd6128tzUHcrlsITCZhkuQifrWYgvw o4P03C1HQoCcLjBH2ra8CHpFQpFLb0JK7xdv0x7HqmrKaHKaceuNleUbZmdIp7JajO5OM/bfmth 6wTGmXKrbZUIBLlASPK19lPC0F2XlOkDDse/qKgnkOUeepU19vvLUV/21egDFc+SzJt5PvR/INU muwui5kwM1VTp6Q8SQZHy0MetC1yj4R/KQHv5eQASyeT+I2jaHcFWPmCVuE6zD05fN1tRKfUcUl HF7tIe0jeR6ASkP21HQqKdCynOCK+HSpxlRsVlf6aKemsGlBDH6LnxLKMrievs+DKJivGXyDXi9 jAS0g/gXxLcxV2PsCtvV36gziaZ3rN+RYueMngBRmgaSqJnY8hXnanDnmRzgDOtLLB/IVrdZEAW 3qwUub+KlUeC1WKdWSk23g1oETgeeFhFf/5CvzMq0la+/rjDj2Yw1naS/Rvfx8Y9AVa3m5fQEhw F5p X-Received: by 2002:ad4:5d6b:0:b0:895:4cc2:8bfe with SMTP id 6a1803df08f44-8974049b5ffmr182540386d6.48.1771369734196; Tue, 17 Feb 2026 15:08:54 -0800 (PST) Received: from warpstation.incus (243.69.21.34.bc.googleusercontent.com. [34.21.69.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8971cc7f82csm175513186d6.4.2026.02.17.15.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Feb 2026 15:08:53 -0800 (PST) From: Ethan Ferguson To: hirofumi@mail.parknet.co.jp Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Ethan Ferguson Subject: [PATCH v2 1/2] fat: Add FS_IOC_GETFSLABEL ioctl Date: Tue, 17 Feb 2026 18:06:27 -0500 Message-ID: <20260217230628.719475-2-ethan.ferguson@zetier.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260217230628.719475-1-ethan.ferguson@zetier.com> References: <20260217230628.719475-1-ethan.ferguson@zetier.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for reading the volume label of a FAT filesystem via the FS_IOC_GETFSLABEL ioctl. Signed-off-by: Ethan Ferguson --- fs/fat/fat.h | 1 + fs/fat/file.c | 16 ++++++++++++++++ fs/fat/inode.c | 11 +++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 0d269dba897b..4350c00dba34 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -89,6 +89,7 @@ struct msdos_sb_info { int dir_per_block; /* dir entries per block */ int dir_per_block_bits; /* log2(dir_per_block) */ unsigned int vol_id; /*volume ID*/ + char vol_label[MSDOS_NAME]; /* volume label */ =20 int fatent_shift; const struct fatent_operations *fatent_ops; diff --git a/fs/fat/file.c b/fs/fat/file.c index 124d9c5431c8..029b1750d1ec 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -153,6 +153,20 @@ static int fat_ioctl_fitrim(struct inode *inode, unsig= ned long arg) return 0; } =20 +static int fat_ioctl_get_volume_label(struct super_block *sb, char __user = *arg) +{ + struct msdos_sb_info *sbi =3D MSDOS_SB(sb); + int ret; + + mutex_lock(&sbi->s_lock); + ret =3D copy_to_user(arg, sbi->vol_label, MSDOS_NAME); + mutex_unlock(&sbi->s_lock); + if (ret) + return -EFAULT; + + return 0; +} + long fat_generic_ioctl(struct file *filp, unsigned int cmd, unsigned long = arg) { struct inode *inode =3D file_inode(filp); @@ -165,6 +179,8 @@ long fat_generic_ioctl(struct file *filp, unsigned int = cmd, unsigned long arg) return fat_ioctl_set_attributes(filp, user_attr); case FAT_IOCTL_GET_VOLUME_ID: return fat_ioctl_get_volume_id(inode, user_attr); + case FS_IOC_GETFSLABEL: + return fat_ioctl_get_volume_label(inode->i_sb, (char __user *) arg); case FITRIM: return fat_ioctl_fitrim(inode, arg); default: diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 59fa90617b5b..6f9a8cc1ad2a 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -53,12 +53,14 @@ struct fat_bios_param_block { =20 u8 fat16_state; u32 fat16_vol_id; + u8 fat16_vol_label[MSDOS_NAME]; =20 u32 fat32_length; u32 fat32_root_cluster; u16 fat32_info_sector; u8 fat32_state; u32 fat32_vol_id; + u8 fat32_vol_label[MSDOS_NAME]; }; =20 static int fat_default_codepage =3D CONFIG_FAT_DEFAULT_CODEPAGE; @@ -1406,12 +1408,14 @@ static int fat_read_bpb(struct super_block *sb, str= uct fat_boot_sector *b, =20 bpb->fat16_state =3D b->fat16.state; bpb->fat16_vol_id =3D get_unaligned_le32(b->fat16.vol_id); + memcpy(bpb->fat16_vol_label, b->fat16.vol_label, MSDOS_NAME); =20 bpb->fat32_length =3D le32_to_cpu(b->fat32.length); bpb->fat32_root_cluster =3D le32_to_cpu(b->fat32.root_cluster); bpb->fat32_info_sector =3D le16_to_cpu(b->fat32.info_sector); bpb->fat32_state =3D b->fat32.state; bpb->fat32_vol_id =3D get_unaligned_le32(b->fat32.vol_id); + memcpy(bpb->fat32_vol_label, b->fat32.vol_label, MSDOS_NAME); =20 /* Validate this looks like a FAT filesystem BPB */ if (!bpb->fat_reserved) { @@ -1708,10 +1712,13 @@ int fat_fill_super(struct super_block *sb, struct f= s_context *fc, } =20 /* interpret volume ID as a little endian 32 bit integer */ - if (is_fat32(sbi)) + if (is_fat32(sbi)) { sbi->vol_id =3D bpb.fat32_vol_id; - else /* fat 16 or 12 */ + memcpy(sbi->vol_label, bpb.fat32_vol_label, MSDOS_NAME); + } else { /* fat 16 or 12 */ sbi->vol_id =3D bpb.fat16_vol_id; + memcpy(sbi->vol_label, bpb.fat16_vol_label, MSDOS_NAME); + } =20 __le32 vol_id_le =3D cpu_to_le32(sbi->vol_id); super_set_uuid(sb, (void *) &vol_id_le, sizeof(vol_id_le)); --=20 2.43.0 From nobody Thu Apr 2 15:36:22 2026 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95DC0311950 for ; Tue, 17 Feb 2026 23:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771369738; cv=none; b=EwejIVC2qbGRlyhLeUsROVjypyjdhOlYA9Lac8SeWOZQBsZBc4OjGfTOc3ih0t17Zu+DuMEqYqAxNCAWHmQmH1imlMFlFZIwGXkbaEdrKC5ex+M+iHv3C1jXqtipl4+OEMSM7wkDpfQVoOwKG+Ra+roGNGRzLG/X8vHyFtxBKJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771369738; c=relaxed/simple; bh=/dDrVfDKsUcytHVbJjVpT632+/VzkrBDFcDuhbzCGrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sstvJpNkl6u+5ZhqSzOVy8nW+LETPU/od6GH2ldLRzVbhpsMILyl9TmfL4ye5YCQzEJ5iGv9vDwQDa7aStNARdxYI/NmfqAleVStwlsY0aX7Fz/V6lk0VUsV/7YqWt/zELg0GluulR3DX8wqYB/KJ3/3olFJN1RjoNKTVc+cxFk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=zetier.com; spf=pass smtp.mailfrom=zetier.com; dkim=pass (2048-bit key) header.d=zetier.com header.i=@zetier.com header.b=BaZYIcI8; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=zetier.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zetier.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zetier.com header.i=@zetier.com header.b="BaZYIcI8" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-8c70b5594f4so32536485a.1 for ; Tue, 17 Feb 2026 15:08:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zetier.com; s=gm; t=1771369736; x=1771974536; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yrA5zBI886Ak4PDcuZ2foshmoLSrHCLowKH+/koqLNU=; b=BaZYIcI8iCLAVN+Er7e6PAhfNT5B3ZoWsif7+4qPEs9zUVYbtzwuLV9w0K7i+Zyl5b zO65fRZkMVwSEO6h3/0MxTnvL6H75MgNVFgY0+N4p0T5jyGIQzXK05RC5ySDRgPlt/jq yXoD3g93jewOMWApU1HgJqiQFx3Prf1azDVJ3yDxzeKSP1l1Vn6OMzA9/W3cBn7rEK6X WyHlF+tzLWlbXpZ7kz/nTrc/lXgDbrJN1doRcjtoPBB8Bk0CjP4pgQiDuLMefYIXTAUU XI6QUTw5C6am8X4Fj/41KR6nXF4uBauPmKqfoms92fIkE8LFb/OJt6VBiizFL8/vrAS6 XjZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771369736; x=1771974536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yrA5zBI886Ak4PDcuZ2foshmoLSrHCLowKH+/koqLNU=; b=cTdUd28rnfKhK534NXHdj1Mnwk7gBj9BYdPvfac7D6xZzrlcmN5DPGDyqoHhiJfoeH ZrNcozQ+pmNfntiQ8NFvAgb1BJAa+sFPSk2U4Sk2AljSWFVP5ZbF/2uRxY1UnuHxR6o0 sykEQu80Ir93gB+tFVZ7lhmxy9ZRAwKbnYJwzaGFfUgOe4KQNmxacRM24jrIQfXbwS+5 oGR+VBtFGkSWrDCYdxgrgniF5H0jO7hqQtzFDDu/8ZjeIMEvPRWCnq8n+xOkqTxR+vYp 2tljwM/qGxnXMjsZMQu0UMR+k3vi6pXdTXNx3ZZx8sjS2T+O7OFeS8j/XWPh2QW0FGDc 0AbA== X-Forwarded-Encrypted: i=1; AJvYcCWQOyUTb76ACC0TSL+GdBZCZ2DG4/m3TpyRSYnLUGIDS8pcnANOSr+rrqu3Np6lJ1T/z87ZgRj5aciEqcA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+KK0XUj6pcIgetww1uN7t5lyzPUiDRkPM4WqAoWzRAWdFD98r M+YoFujHgOQ45AHO47yHxwd40KFJAv4JNcUFmaqXNn29O6vmEb5HPLSK7jDQlRmXtSs= X-Gm-Gg: AZuq6aIDb0iOiQl9LTF1ExasOkIAnzVq7F+STeBnlbW+EBFtrq2W0BEu0M4fZcXNQ+5 hTO+5KGHArouAXuxnlP6lyjIR0Y8ji/qUgQUfEW1jsj7c1rQZFjOUUq6DahgYLFoMzVInscHsUg hsv7TaQ8P86fHX15cMjnZpjqmHnmsITTJkjguk3jU3wI++WE4nqesfeKMrQM4Qx/I73muSObPKb EVfNcW+K8zTqW+hpKS9qpBi8CECyOUzORIB9WVlB5RulBOZxQP87qFgAuPYxqYA84i3ICssIQfu LL/Hh+s4gTu8tLnGl3kdCqDUALh3jX0uDRme4VtHzDMlSyTsSZGBLETnuorbQxUwS1f095jNtxb OyELnYX0bmGwacafkHYBPpJ+RWAqKWR4MdBamb7EjJUrTjFT+sfOMClE1X9DoXHosm7Fm+JpUvX hPm9Ic5/sHLf92Inj5O9IZB8MVjVmq+0/wd3LAXOFehouJraCBv8p9nLtBm6bwExeSLxPavZvJ1 0CZMufqENQEAqg= X-Received: by 2002:a05:620a:254d:b0:8c7:110e:9cd5 with SMTP id af79cd13be357-8cb741dd2d0mr5743685a.45.1771369735368; Tue, 17 Feb 2026 15:08:55 -0800 (PST) Received: from warpstation.incus (243.69.21.34.bc.googleusercontent.com. [34.21.69.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8971cc7f82csm175513186d6.4.2026.02.17.15.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Feb 2026 15:08:54 -0800 (PST) From: Ethan Ferguson To: hirofumi@mail.parknet.co.jp Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Ethan Ferguson Subject: [PATCH v2 2/2] fat: Add FS_IOC_SETFSLABEL ioctl Date: Tue, 17 Feb 2026 18:06:28 -0500 Message-ID: <20260217230628.719475-3-ethan.ferguson@zetier.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260217230628.719475-1-ethan.ferguson@zetier.com> References: <20260217230628.719475-1-ethan.ferguson@zetier.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for writing to the volume label of a FAT filesystem via the FS_IOC_SETFSLABEL ioctl. Signed-off-by: Ethan Ferguson --- fs/fat/dir.c | 51 +++++++++++++++++++++++++++++++++++ fs/fat/fat.h | 6 +++++ fs/fat/file.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ fs/fat/inode.c | 15 +++++++++++ fs/fat/namei_msdos.c | 4 +-- 5 files changed, 137 insertions(+), 2 deletions(-) diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 07d95f1442c8..1b11713309ae 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -1425,3 +1425,54 @@ int fat_add_entries(struct inode *dir, void *slots, = int nr_slots, return err; } EXPORT_SYMBOL_GPL(fat_add_entries); + +static int fat_create_volume_label_dentry(struct super_block *sb, char *vo= l_label) +{ + struct msdos_sb_info *sbi =3D MSDOS_SB(sb); + struct inode *root_inode =3D sb->s_root->d_inode; + struct msdos_dir_entry de; + struct fat_slot_info sinfo; + struct timespec64 ts =3D current_time(root_inode); + __le16 date, time; + u8 time_cs; + + memcpy(de.name, vol_label, MSDOS_NAME); + de.attr =3D ATTR_VOLUME; + de.starthi =3D de.start =3D de.size =3D de.lcase =3D 0; + + fat_time_unix2fat(sbi, &ts, &time, &date, &time_cs); + de.time =3D time; + de.date =3D date; + if (sbi->options.isvfat) { + de.cdate =3D de.adate =3D date; + de.ctime =3D time; + de.ctime_cs =3D time_cs; + } else + de.cdate =3D de.adate =3D de.ctime =3D de.ctime_cs =3D 0; + + return fat_add_entries(root_inode, &de, 1, &sinfo); +} + +int fat_rename_volume_label_dentry(struct super_block *sb, char *vol_label) +{ + struct inode *root_inode =3D sb->s_root->d_inode; + struct buffer_head *bh =3D NULL; + struct msdos_dir_entry *de; + loff_t cpos =3D 0; + int err =3D 0; + + while (1) { + if (fat_get_entry(root_inode, &cpos, &bh, &de) =3D=3D -1) + return fat_create_volume_label_dentry(sb, vol_label); + + if (de->attr =3D=3D ATTR_VOLUME) { + memcpy(de->name, vol_label, MSDOS_NAME); + mark_buffer_dirty_inode(bh, root_inode); + if (IS_DIRSYNC(root_inode)) + err =3D sync_dirty_buffer(bh); + brelse(bh); + return err; + } + } +} +EXPORT_SYMBOL_GPL(fat_rename_volume_label_dentry); diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 4350c00dba34..3b75223fbe76 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -341,6 +341,8 @@ extern int fat_alloc_new_dir(struct inode *dir, struct = timespec64 *ts); extern int fat_add_entries(struct inode *dir, void *slots, int nr_slots, struct fat_slot_info *sinfo); extern int fat_remove_entries(struct inode *dir, struct fat_slot_info *sin= fo); +extern int fat_rename_volume_label_dentry(struct super_block *sb, + char *vol_label); =20 /* fat/fatent.c */ struct fat_entry { @@ -480,6 +482,10 @@ extern int fat_sync_bhs(struct buffer_head **bhs, int = nr_bhs); int fat_cache_init(void); void fat_cache_destroy(void); =20 +/* fat/namei/msdos.c */ +int msdos_format_name(const unsigned char *name, int len, + unsigned char *res, struct fat_mount_options *opts); + /* fat/nfs.c */ extern const struct export_operations fat_export_ops; extern const struct export_operations fat_export_ops_nostale; diff --git a/fs/fat/file.c b/fs/fat/file.c index 029b1750d1ec..5d445c2d8657 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -167,6 +167,67 @@ static int fat_ioctl_get_volume_label(struct super_blo= ck *sb, char __user *arg) return 0; } =20 +static int fat_convert_volume_label_str(struct msdos_sb_info *sbi, char *i= n, + char *out) +{ + int ret, in_len =3D max(strnlen(in, FSLABEL_MAX), 11); + char *needle; + + /* + * '.' is not included in any bad_chars list in this driver, + * but it is specifically not allowed for volume labels + */ + for (needle =3D in; needle - in < in_len; needle++) + if (*needle =3D=3D '.') + return -EINVAL; + + ret =3D msdos_format_name(in, in_len, out, &sbi->options); + if (ret) + return ret; + + /* + * msdos_format_name assumes we're translating an 8.3 name, but + * we can handle 11 chars + */ + if (in_len > 8) + ret =3D msdos_format_name(in + 8, in_len - 8, out + 8, + &sbi->options); + return ret; +} + +static int fat_ioctl_set_volume_label(struct super_block *sb, char __user = *arg) +{ + struct msdos_sb_info *sbi =3D MSDOS_SB(sb); + struct inode *root_inode =3D sb->s_root->d_inode; + char from_user[FSLABEL_MAX]; + char new_vol_label[MSDOS_NAME]; + int ret; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (sb_rdonly(sb)) + return -EROFS; + + if (copy_from_user(from_user, arg, FSLABEL_MAX)) + return -EFAULT; + + ret =3D fat_convert_volume_label_str(sbi, from_user, new_vol_label); + if (ret) + return ret; + + inode_lock(root_inode); + ret =3D fat_rename_volume_label_dentry(sb, new_vol_label); + inode_unlock(root_inode); + if (ret) + return ret; + + mutex_lock(&sbi->s_lock); + memcpy(sbi->vol_label, new_vol_label, MSDOS_NAME); + mutex_unlock(&sbi->s_lock); + return 0; +} + long fat_generic_ioctl(struct file *filp, unsigned int cmd, unsigned long = arg) { struct inode *inode =3D file_inode(filp); @@ -181,6 +242,8 @@ long fat_generic_ioctl(struct file *filp, unsigned int = cmd, unsigned long arg) return fat_ioctl_get_volume_id(inode, user_attr); case FS_IOC_GETFSLABEL: return fat_ioctl_get_volume_label(inode->i_sb, (char __user *) arg); + case FS_IOC_SETFSLABEL: + return fat_ioctl_set_volume_label(inode->i_sb, (char __user *) arg); case FITRIM: return fat_ioctl_fitrim(inode, arg); default: diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 6f9a8cc1ad2a..a7528937383b 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -736,6 +736,21 @@ static void delayed_free(struct rcu_head *p) static void fat_put_super(struct super_block *sb) { struct msdos_sb_info *sbi =3D MSDOS_SB(sb); + struct buffer_head *bh =3D NULL; + struct fat_boot_sector *bs; + + bh =3D sb_bread(sb, 0); + if (bh =3D=3D NULL) + fat_msg(sb, KERN_ERR, "unable to read boot sector"); + else if (!sb_rdonly(sb)) { + bs =3D (struct fat_boot_sector *)bh->b_data; + if (is_fat32(sbi)) + memcpy(bs->fat32.vol_label, sbi->vol_label, MSDOS_NAME); + else + memcpy(bs->fat16.vol_label, sbi->vol_label, MSDOS_NAME); + mark_buffer_dirty(bh); + } + brelse(bh); =20 fat_set_state(sb, 0, 0); =20 diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index ba0152ed0810..92b5d387f88e 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -16,8 +16,8 @@ static unsigned char bad_chars[] =3D "*?<>|\""; static unsigned char bad_if_strict[] =3D "+=3D,; "; =20 /***** Formats an MS-DOS file name. Rejects invalid names. */ -static int msdos_format_name(const unsigned char *name, int len, - unsigned char *res, struct fat_mount_options *opts) +int msdos_format_name(const unsigned char *name, int len, unsigned char *r= es, + struct fat_mount_options *opts) /* * name is the proposed name, len is its length, res is * the resulting name, opts->name_check is either (r)elaxed, --=20 2.43.0