3 * Copyright (c) 2006-2012 by Roland Riegel <feedback@roland-riegel.de>
5 * This file is free software; you can redistribute it and/or modify
6 * it under the terms of either the GNU General Public License version 2
7 * or the GNU Lesser General Public License version 2.1, both as
8 * published by the Free Software Foundation.
15 #include "fat_config.h"
29 * FAT header (license: GPLv2 or LGPLv2.1)
31 * \author Roland Riegel
35 * \addtogroup fat_file
39 /** The file is read-only. */
40 #define FAT_ATTRIB_READONLY (1 << 0)
41 /** The file is hidden. */
42 #define FAT_ATTRIB_HIDDEN (1 << 1)
43 /** The file is a system file. */
44 #define FAT_ATTRIB_SYSTEM (1 << 2)
45 /** The file is empty and has the volume label as its name. */
46 #define FAT_ATTRIB_VOLUME (1 << 3)
47 /** The file is a directory. */
48 #define FAT_ATTRIB_DIR (1 << 4)
49 /** The file has to be archived. */
50 #define FAT_ATTRIB_ARCHIVE (1 << 5)
52 /** The given offset is relative to the beginning of the file. */
53 #define FAT_SEEK_SET 0
54 /** The given offset is relative to the current read/write position. */
55 #define FAT_SEEK_CUR 1
56 /** The given offset is relative to the end of the file. */
57 #define FAT_SEEK_END 2
63 struct partition_struct;
65 struct fat_file_struct;
66 struct fat_dir_struct;
70 * Describes a directory entry.
72 struct fat_dir_entry_struct
74 /** The file's name, truncated to 31 characters. */
76 /** The file's attributes. Mask of the FAT_ATTRIB_* constants. */
78 #if FAT_DATETIME_SUPPORT
79 /** Compressed representation of modification time. */
80 uint16_t modification_time;
81 /** Compressed representation of modification date. */
82 uint16_t modification_date;
84 /** The cluster in which the file's first byte resides. */
86 /** The file's size. */
88 /** The total disk offset of this directory entry. */
89 offset_t entry_offset;
92 struct fat_fs_struct* fat_open(struct partition_struct* partition);
93 void fat_close(struct fat_fs_struct* fs);
95 struct fat_file_struct* fat_open_file(struct fat_fs_struct* fs, const struct fat_dir_entry_struct* dir_entry);
96 void fat_close_file(struct fat_file_struct* fd);
97 intptr_t fat_read_file(struct fat_file_struct* fd, uint8_t* buffer, uintptr_t buffer_len);
98 intptr_t fat_write_file(struct fat_file_struct* fd, const uint8_t* buffer, uintptr_t buffer_len);
99 uint8_t fat_seek_file(struct fat_file_struct* fd, int32_t* offset, uint8_t whence);
100 uint8_t fat_resize_file(struct fat_file_struct* fd, uint32_t size);
102 struct fat_dir_struct* fat_open_dir(struct fat_fs_struct* fs, const struct fat_dir_entry_struct* dir_entry);
103 void fat_close_dir(struct fat_dir_struct* dd);
104 uint8_t fat_read_dir(struct fat_dir_struct* dd, struct fat_dir_entry_struct* dir_entry);
105 uint8_t fat_reset_dir(struct fat_dir_struct* dd);
107 uint8_t fat_create_file(struct fat_dir_struct* parent, const char* file, struct fat_dir_entry_struct* dir_entry);
108 uint8_t fat_delete_file(struct fat_fs_struct* fs, struct fat_dir_entry_struct* dir_entry);
109 uint8_t fat_move_file(struct fat_fs_struct* fs, struct fat_dir_entry_struct* dir_entry, struct fat_dir_struct* parent_new, const char* file_new);
110 uint8_t fat_create_dir(struct fat_dir_struct* parent, const char* dir, struct fat_dir_entry_struct* dir_entry);
111 #define fat_delete_dir fat_delete_file
112 #define fat_move_dir fat_move_file
114 void fat_get_file_modification_date(const struct fat_dir_entry_struct* dir_entry, uint16_t* year, uint8_t* month, uint8_t* day);
115 void fat_get_file_modification_time(const struct fat_dir_entry_struct* dir_entry, uint8_t* hour, uint8_t* min, uint8_t* sec);
117 uint8_t fat_get_dir_entry_of_path(struct fat_fs_struct* fs, const char* path, struct fat_dir_entry_struct* dir_entry);
119 offset_t fat_get_fs_size(const struct fat_fs_struct* fs);
120 offset_t fat_get_fs_free(const struct fat_fs_struct* fs);