* [PATCH 1/2] fs: fat: add file attributes to struct fs_dirent
2021-06-12 5:48 [PATCH 0/2] efi_loader: provide file attributes in directory Heinrich Schuchardt
@ 2021-06-12 5:48 ` Heinrich Schuchardt
2021-06-12 5:48 ` [PATCH 2/2] efi_loader: provide file attributes in EFI_FILE_PROTOCOL.Read() Heinrich Schuchardt
1 sibling, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2021-06-12 5:48 UTC (permalink / raw)
To: Alexander Graf
Cc: Simon Glass, Jason Wessel, Christian Gmeiner, Masami Hiramatsu,
Vincent Stehlé,
u-boot, Heinrich Schuchardt
When reading a directory in the UEFI file system we have to return file
attributes and timestamps. Copy this data to the directory entry structure.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
fs/fat/fat.c | 32 +++++++++++++++++++++++++++++++-
include/fs.h | 22 ++++++++++++++++++----
2 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index c561d82b35..7021138b98 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1187,6 +1187,28 @@ out:
return ret == 0;
}
+/**
+ * fat2rtc() - convert FAT time stamp to RTC file stamp
+ *
+ * @date: FAT date
+ * @time: FAT time
+ * @tm: RTC time stamp
+ */
+static void __maybe_unused fat2rtc(u16 date, u16 time, struct rtc_time *tm)
+{
+ tm->tm_mday = date & 0x1f;
+ tm->tm_mon = (date & 0x1e0) >> 4;
+ tm->tm_year = (date >> 9) + 1980;
+
+ tm->tm_sec = (time & 0x1f) << 1;
+ tm->tm_min = (time & 0x7e0) >> 5;
+ tm->tm_hour = time >> 11;
+
+ rtc_calc_weekday(tm);
+ tm->tm_yday = 0;
+ tm->tm_isdst = 0;
+}
+
int fat_size(const char *filename, loff_t *size)
{
fsdata fsdata;
@@ -1325,7 +1347,15 @@ int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp)
memset(dent, 0, sizeof(*dent));
strcpy(dent->name, dir->itr.name);
-
+ if (CONFIG_IS_ENABLED(EFI_LOADER)) {
+ dent->attr = dir->itr.dent->attr;
+ fat2rtc(le16_to_cpu(dir->itr.dent->cdate),
+ le16_to_cpu(dir->itr.dent->ctime), &dent->create_time);
+ fat2rtc(le16_to_cpu(dir->itr.dent->date),
+ le16_to_cpu(dir->itr.dent->time), &dent->change_time);
+ fat2rtc(le16_to_cpu(dir->itr.dent->adate),
+ 0, &dent->access_time);
+ }
if (fat_itr_isdir(&dir->itr)) {
dent->type = FS_DT_DIR;
} else {
diff --git a/include/fs.h b/include/fs.h
index 0794b50d10..1c79e299fd 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -6,6 +6,7 @@
#define _FS_H
#include <common.h>
+#include <rtc.h>
struct cmd_tbl;
@@ -160,13 +161,26 @@ int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
#define FS_DT_REG 8 /* regular file */
#define FS_DT_LNK 10 /* symbolic link */
-/*
- * A directory entry, returned by fs_readdir(). Returns information
+/**
+ * struct fs_dirent - directory entry
+ *
+ * A directory entry, returned by fs_readdir(). Returns information
* about the file/directory at the current directory entry position.
*/
struct fs_dirent {
- unsigned type; /* one of FS_DT_x (not a mask) */
- loff_t size; /* size in bytes */
+ /** @type: one of FS_DT_x (not a mask) */
+ unsigned int type;
+ /** @size: file size */
+ loff_t size;
+ /** @flags: attribute flags (FS_ATTR_*) */
+ u32 attr;
+ /** create_time: time of creation */
+ struct rtc_time create_time;
+ /** access_time: time of last access */
+ struct rtc_time access_time;
+ /** change_time: time of last modification */
+ struct rtc_time change_time;
+ /** name: file name */
char name[256];
};
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] efi_loader: provide file attributes in EFI_FILE_PROTOCOL.Read()
2021-06-12 5:48 [PATCH 0/2] efi_loader: provide file attributes in directory Heinrich Schuchardt
2021-06-12 5:48 ` [PATCH 1/2] fs: fat: add file attributes to struct fs_dirent Heinrich Schuchardt
@ 2021-06-12 5:48 ` Heinrich Schuchardt
1 sibling, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2021-06-12 5:48 UTC (permalink / raw)
To: Alexander Graf
Cc: Simon Glass, Jason Wessel, Christian Gmeiner, Masami Hiramatsu,
Vincent Stehlé,
u-boot, Heinrich Schuchardt
When reading a directory using EFI_FILE_PROTOCOL.Read() provide file
attributes and timestamps.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
lib/efi_loader/efi_file.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index 6b3f5962be..6299fcbbf4 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -480,6 +480,17 @@ static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size,
return EFI_SUCCESS;
}
+static void rtc2efi(struct efi_time *time, struct rtc_time *tm)
+{
+ memset(time, 0, sizeof(struct efi_time));
+ time->year = tm->tm_year;
+ time->month = tm->tm_mon;
+ time->day = tm->tm_mday;
+ time->hour = tm->tm_hour;
+ time->minute = tm->tm_min;
+ time->second = tm->tm_sec;
+}
+
static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size,
void *buffer)
{
@@ -535,6 +546,10 @@ static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size,
info->size = required_size;
info->file_size = dent->size;
info->physical_size = dent->size;
+ info->attribute = dent->attr;
+ rtc2efi(&info->create_time, &dent->create_time);
+ rtc2efi(&info->modification_time, &dent->change_time);
+ rtc2efi(&info->last_access_time, &dent->access_time);
if (dent->type == FS_DT_DIR)
info->attribute |= EFI_FILE_DIRECTORY;
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread