[PATCH 1/2] befs: Add FS_IOC_GETFSLABEL ioctl

Ethan Ferguson posted 2 patches 2 weeks, 2 days ago
There is a newer version of this series
[PATCH 1/2] befs: Add FS_IOC_GETFSLABEL ioctl
Posted by Ethan Ferguson 2 weeks, 2 days ago
Add the FS_IOC_GETFSLABEL ioctl to the befs filesystem.

Signed-off-by: Ethan Ferguson <ethan.ferguson@zetier.com>
---
 fs/befs/befs.h     |  1 +
 fs/befs/linuxvfs.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/befs/super.c    |  1 +
 3 files changed, 49 insertions(+)

diff --git a/fs/befs/befs.h b/fs/befs/befs.h
index 7cd47245694d..e4e2e9f4e307 100644
--- a/fs/befs/befs.h
+++ b/fs/befs/befs.h
@@ -30,6 +30,7 @@ struct befs_mount_options {
 };
 
 struct befs_sb_info {
+	char name[B_OS_NAME_LENGTH];
 	u32 magic1;
 	u32 block_size;
 	u32 block_shift;
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index d7c5d9270387..942d247a6cae 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -25,6 +25,7 @@
 #include <linux/exportfs.h>
 #include <linux/seq_file.h>
 #include <linux/blkdev.h>
+#include <linux/compat.h>
 
 #include "befs.h"
 #include "btree.h"
@@ -64,6 +65,15 @@ static struct dentry *befs_fh_to_parent(struct super_block *sb,
 				struct fid *fid, int fh_len, int fh_type);
 static struct dentry *befs_get_parent(struct dentry *child);
 static void befs_free_fc(struct fs_context *fc);
+static int befs_ioctl_get_volume_label(struct super_block *sb,
+				       char __user *arg);
+static long befs_generic_ioctl(struct file *filp, unsigned int cmd,
+			       unsigned long arg);
+#ifdef CONFIG_COMPAT
+static long befs_generic_compat_ioctl(struct file *filp, unsigned int cmd,
+				      unsigned long arg);
+#endif
+
 
 static const struct super_operations befs_sops = {
 	.alloc_inode	= befs_alloc_inode,	/* allocate a new inode */
@@ -81,6 +91,10 @@ static const struct file_operations befs_dir_operations = {
 	.iterate_shared	= befs_readdir,
 	.llseek		= generic_file_llseek,
 	.setlease	= generic_setlease,
+	.unlocked_ioctl	= befs_generic_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl	= befs_generic_compat_ioctl,
+#endif
 };
 
 static const struct inode_operations befs_dir_inode_operations = {
@@ -940,6 +954,39 @@ befs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	return 0;
 }
 
+static int befs_ioctl_get_volume_label(struct super_block *sb, char __user *arg)
+{
+	struct befs_sb_info *sbi = BEFS_SB(sb);
+
+	if (copy_to_user(arg, sbi->name, B_OS_NAME_LENGTH))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long befs_generic_ioctl(struct file *filp, unsigned int cmd,
+			       unsigned long arg)
+{
+	struct inode *inode = file_inode(filp);
+	char __user *user = (char __user *)arg;
+
+	switch (cmd) {
+	case FS_IOC_GETFSLABEL:
+		return befs_ioctl_get_volume_label(inode->i_sb, user);
+	default:
+		return -ENOTTY;
+	}
+}
+
+#ifdef CONFIG_COMPAT
+static long befs_generic_compat_ioctl(struct file *filp, unsigned int cmd,
+				      unsigned long arg)
+
+{
+	return befs_generic_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif
+
 static int befs_get_tree(struct fs_context *fc)
 {
 	return get_tree_bdev(fc, befs_fill_super);
diff --git a/fs/befs/super.c b/fs/befs/super.c
index 7c50025c99d8..e6a13b497ac1 100644
--- a/fs/befs/super.c
+++ b/fs/befs/super.c
@@ -28,6 +28,7 @@ befs_load_sb(struct super_block *sb, befs_super_block *disk_sb)
 	else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE)
 		befs_sb->byte_order = BEFS_BYTESEX_BE;
 
+	memcpy(befs_sb->name, disk_sb->name, B_OS_NAME_LENGTH);
 	befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1);
 	befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2);
 	befs_sb->magic3 = fs32_to_cpu(sb, disk_sb->magic3);
-- 
2.43.0