[PATCH 2/2] Add a new function to get root directory with ATTR_VOLUME
From: chenchacha
Date: Thu Oct 04 2018 - 13:28:37 EST
Signed-off-by: chenchacha <chen.chenchacha@xxxxxxxxxxx>
---
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