From 4d2118023e7aecf83c384e56591778e1fe0554ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiesner=20Andr=C3=A1s?= Date: Sat, 11 Nov 2023 20:55:58 +0100 Subject: [PATCH] - fat32: returning -1 on file open failure --- fs/fat32/fat32.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/fat32/fat32.c b/fs/fat32/fat32.c index cf19b6e..4465795 100644 --- a/fs/fat32/fat32.c +++ b/fs/fat32/fat32.c @@ -520,9 +520,21 @@ uint32_t fat32_read_file_random_access(const Fat32_CtrlBlock *ctrl, const Fat32_ // ----------------- +/** + * Open file. + * + * @param ctrl pointer to FAT32 control block + * @param path full file path + * @param file_helper pointer to file helper object + * @return int 0 if successful, -1 on failure + */ int fat32_open_file(const Fat32_CtrlBlock *ctrl, const char *path, Fat32_FileHelper *file_helper) { uint32_t file_entry_ba; const Fat32_FileEntry *entry = fat32_locate_file(ctrl, path, &file_entry_ba); + if (entry == NULL) { // if cannot open file, then return -1 + return -1; + } + uint32_t first_cluster = fat32_get_first_cluster(entry); // store data usable for identifying file on the storage