From: Ethan Ferguson <ethan.ferguson@zetier.com>
To: hirofumi@mail.parknet.co.jp
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Ethan Ferguson <ethan.ferguson@zetier.com>
Subject: [PATCH v2 1/2] fat: Add FS_IOC_GETFSLABEL ioctl
Date: Tue, 17 Feb 2026 18:06:27 -0500 [thread overview]
Message-ID: <20260217230628.719475-2-ethan.ferguson@zetier.com> (raw)
In-Reply-To: <20260217230628.719475-1-ethan.ferguson@zetier.com>
Add support for reading the volume label of a FAT filesystem via the
FS_IOC_GETFSLABEL ioctl.
Signed-off-by: Ethan Ferguson <ethan.ferguson@zetier.com>
---
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 */
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, unsigned long arg)
return 0;
}
+static int fat_ioctl_get_volume_label(struct super_block *sb, char __user *arg)
+{
+ struct msdos_sb_info *sbi = MSDOS_SB(sb);
+ int ret;
+
+ mutex_lock(&sbi->s_lock);
+ ret = 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 = 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 {
u8 fat16_state;
u32 fat16_vol_id;
+ u8 fat16_vol_label[MSDOS_NAME];
u32 fat32_length;
u32 fat32_root_cluster;
u16 fat32_info_sector;
u8 fat32_state;
u32 fat32_vol_id;
+ u8 fat32_vol_label[MSDOS_NAME];
};
static int fat_default_codepage = CONFIG_FAT_DEFAULT_CODEPAGE;
@@ -1406,12 +1408,14 @@ static int fat_read_bpb(struct super_block *sb, struct fat_boot_sector *b,
bpb->fat16_state = b->fat16.state;
bpb->fat16_vol_id = get_unaligned_le32(b->fat16.vol_id);
+ memcpy(bpb->fat16_vol_label, b->fat16.vol_label, MSDOS_NAME);
bpb->fat32_length = le32_to_cpu(b->fat32.length);
bpb->fat32_root_cluster = le32_to_cpu(b->fat32.root_cluster);
bpb->fat32_info_sector = le16_to_cpu(b->fat32.info_sector);
bpb->fat32_state = b->fat32.state;
bpb->fat32_vol_id = get_unaligned_le32(b->fat32.vol_id);
+ memcpy(bpb->fat32_vol_label, b->fat32.vol_label, MSDOS_NAME);
/* 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 fs_context *fc,
}
/* interpret volume ID as a little endian 32 bit integer */
- if (is_fat32(sbi))
+ if (is_fat32(sbi)) {
sbi->vol_id = 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 = bpb.fat16_vol_id;
+ memcpy(sbi->vol_label, bpb.fat16_vol_label, MSDOS_NAME);
+ }
__le32 vol_id_le = cpu_to_le32(sbi->vol_id);
super_set_uuid(sb, (void *) &vol_id_le, sizeof(vol_id_le));
--
2.43.0
next prev parent reply other threads:[~2026-02-17 23:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 23:06 [PATCH v2 0/2] fat: Add FS_IOC_GETFSLABEL / FS_IOC_SETFSLABEL ioctls Ethan Ferguson
2026-02-17 23:06 ` Ethan Ferguson [this message]
2026-02-17 23:06 ` [PATCH v2 2/2] fat: Add FS_IOC_SETFSLABEL ioctl Ethan Ferguson
2026-02-18 6:50 ` kernel test robot
2026-02-18 7:21 ` kernel test robot
2026-02-18 7:22 ` OGAWA Hirofumi
2026-02-18 10:22 ` kernel test robot
2026-02-18 16:26 ` kernel test robot
2026-02-18 8:46 ` [syzbot ci] Re: fat: Add FS_IOC_GETFSLABEL / FS_IOC_SETFSLABEL ioctls syzbot ci
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=20260217230628.719475-2-ethan.ferguson@zetier.com \
--to=ethan.ferguson@zetier.com \
--cc=hirofumi@mail.parknet.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--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®