2018-10-04 17:29:39

by chenchacha

[permalink] [raw]
Subject: [PATCH 0/2] fs: fat: add ioctl method to read voluem label in fat filesystem driver

This patch add fat ioctl command FAT_IOCTL_GET_VOLUME_LABEL.

We can get the volume label with this command:

ioctl(fd, FAT_IOCTL_GET_VOLUME_LABEL, &volume_label);

FAT volume label (volume name) is exactly same stored in boot sector and root
directory. And this patch read label only from the root directory. If label in
root directory is missing then disk would be treated as without label. Label
from boot sector would not be read.

The volume label format reference from Pali Rohár testing results
(https://www.spinics.net/lists/kernel/msg2645732.html) in the previous mail.

chenchacha (2):
Add FAT_IOCTL_GET_VOLUME_LABEL in fat_generic_ioctl()
Add a new function to get root directory with ATTR_VOLUME

fs/fat/dir.c | 13 +++++++++++++
fs/fat/fat.h | 2 ++
fs/fat/file.c | 22 ++++++++++++++++++++++
include/uapi/linux/msdos_fs.h | 1 +
4 files changed, 38 insertions(+)

--
2.19.0



2018-10-04 17:27:02

by Pali Rohár

[permalink] [raw]
Subject: Re: [PATCH 0/2] fs: fat: add ioctl method to read voluem label in fat filesystem driver

On Friday 05 October 2018 01:20:59 chenchacha wrote:
> This patch add fat ioctl command FAT_IOCTL_GET_VOLUME_LABEL.
>
> We can get the volume label with this command:
>
> ioctl(fd, FAT_IOCTL_GET_VOLUME_LABEL, &volume_label);

Hi! What is purpose of having such functionality in kernel? Userspace
can read it without any kernel support. (e.g. mlabel or fatlabel)

> FAT volume label (volume name) is exactly same stored in boot sector and root
> directory. And this patch read label only from the root directory. If label in
> root directory is missing then disk would be treated as without label. Label
> from boot sector would not be read.
>
> The volume label format reference from Pali Rohár testing results
> (https://www.spinics.net/lists/kernel/msg2645732.html) in the previous mail.
>
> chenchacha (2):
> Add FAT_IOCTL_GET_VOLUME_LABEL in fat_generic_ioctl()
> Add a new function to get root directory with ATTR_VOLUME
>
> fs/fat/dir.c | 13 +++++++++++++
> fs/fat/fat.h | 2 ++
> fs/fat/file.c | 22 ++++++++++++++++++++++
> include/uapi/linux/msdos_fs.h | 1 +
> 4 files changed, 38 insertions(+)
>

--
Pali Rohár
[email protected]


Attachments:
(No filename) (1.21 kB)
signature.asc (201.00 B)
Download all attachments

2018-10-04 17:29:04

by chenchacha

[permalink] [raw]
Subject: [PATCH 2/2] Add a new function to get root directory with ATTR_VOLUME

Signed-off-by: chenchacha <[email protected]>
---
fs/fat/dir.c | 13 +++++++++++++
fs/fat/fat.h | 2 ++
2 files changed, 15 insertions(+)

diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 7f5f3699fc6c..4fdcc1200f2b 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -881,6 +881,19 @@ static int fat_get_short_entry(struct inode *dir, loff_t *pos,
return -ENOENT;
}

+int fat_get_root_entry(struct inode *dir, struct buffer_head **bh,
+ struct msdos_dir_entry **de)
+{
+ loff_t offset = 0;
+
+ *de = NULL;
+ while (fat_get_entry(dir, &offset, bh, de) >= 0) {
+ if (!IS_FREE((*de)->name) && (*de)->attr & ATTR_VOLUME)
+ return 0;
+ }
+ return -ENOENT;
+}
+
/*
* The ".." entry can not provide the "struct fat_slot_info" information
* for inode, nor a usable i_pos. So, this function provides some information
diff --git a/fs/fat/fat.h b/fs/fat/fat.h
index be012de96f65..4195cb1e891a 100644
--- a/fs/fat/fat.h
+++ b/fs/fat/fat.h
@@ -302,6 +302,8 @@ extern int fat_scan(struct inode *dir, const unsigned char *name,
struct fat_slot_info *sinfo);
extern int fat_scan_logstart(struct inode *dir, int i_logstart,
struct fat_slot_info *sinfo);
+extern int fat_get_root_entry(struct inode *dir, struct buffer_head **bh,
+ struct msdos_dir_entry **de);
extern int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh,
struct msdos_dir_entry **de);
extern int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts);
--
2.19.0


2018-10-04 17:32:07

by Pali Rohár

[permalink] [raw]
Subject: Re: [PATCH 2/2] Add a new function to get root directory with ATTR_VOLUME

On Friday 05 October 2018 01:21:01 chenchacha wrote:
> Signed-off-by: chenchacha <[email protected]>
> ---
> fs/fat/dir.c | 13 +++++++++++++
> fs/fat/fat.h | 2 ++
> 2 files changed, 15 insertions(+)
>
> diff --git a/fs/fat/dir.c b/fs/fat/dir.c
> index 7f5f3699fc6c..4fdcc1200f2b 100644
> --- a/fs/fat/dir.c
> +++ b/fs/fat/dir.c
> @@ -881,6 +881,19 @@ static int fat_get_short_entry(struct inode *dir, loff_t *pos,
> return -ENOENT;
> }
>
> +int fat_get_root_entry(struct inode *dir, struct buffer_head **bh,
> + struct msdos_dir_entry **de)

fat_get_root_volume_entry would be better name. It does not return root
entry, but volume label entry.

> +{
> + loff_t offset = 0;
> +
> + *de = NULL;
> + while (fat_get_entry(dir, &offset, bh, de) >= 0) {
> + if (!IS_FREE((*de)->name) && (*de)->attr & ATTR_VOLUME)

You should check that cluster number is zero. As e.g. first entry with
ATTR_VOLUME can be also LFN entry and not real volume label. So you
should properly check mask and filter out also LFN entries which have
ATTR_VOLUME flag set too.

> + return 0;
> + }
> + return -ENOENT;
> +}
> +
> /*
> * The ".." entry can not provide the "struct fat_slot_info" information
> * for inode, nor a usable i_pos. So, this function provides some information
> diff --git a/fs/fat/fat.h b/fs/fat/fat.h
> index be012de96f65..4195cb1e891a 100644
> --- a/fs/fat/fat.h
> +++ b/fs/fat/fat.h
> @@ -302,6 +302,8 @@ extern int fat_scan(struct inode *dir, const unsigned char *name,
> struct fat_slot_info *sinfo);
> extern int fat_scan_logstart(struct inode *dir, int i_logstart,
> struct fat_slot_info *sinfo);
> +extern int fat_get_root_entry(struct inode *dir, struct buffer_head **bh,
> + struct msdos_dir_entry **de);
> extern int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh,
> struct msdos_dir_entry **de);
> extern int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts);
> --
> 2.19.0
>

--
Pali Rohár
[email protected]


Attachments:
(No filename) (2.03 kB)
signature.asc (201.00 B)
Download all attachments