1 /* 2 * Copyright (c) 2022 Travis Geiselbrecht 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #pragma once 9 10 #include <inttypes.h> 11 #include <lk/list.h> 12 13 #include "file.h" 14 15 class fat_fs; 16 struct dir_entry; 17 struct dir_entry_location; 18 struct fat_dir_cookie; 19 20 // structure that represents an open dir, may have multiple cookies in its list 21 // at any point in time, 22 class fat_dir : public fat_file { 23 public: fat_dir(fat_fs * f)24 explicit fat_dir(fat_fs *f) : fat_file(f) {} 25 virtual ~fat_dir(); 26 27 static status_t opendir(fscookie *cookie, const char *name, dircookie **dcookie); 28 static status_t readdir(dircookie *dcookie, struct dirent *ent); 29 static status_t closedir(dircookie *dcookie); 30 31 private: 32 status_t opendir_priv(const dir_entry &entry, const dir_entry_location &loc, fat_dir_cookie **out_cookie); 33 status_t readdir_priv(fat_dir_cookie *cookie, struct dirent *ent); 34 status_t closedir_priv(fat_dir_cookie *cookie, bool *last_ref); 35 36 // list of all open dir handles and their offsets within us 37 list_node cookies_ = LIST_INITIAL_VALUE(cookies_); 38 }; 39 40