Rev Author Line No. Line
1144 kaklik 1  
2 /*
3 * Copyright (c) 2006-2007 by Roland Riegel <feedback@roland-riegel.de>
4 *
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.
9 */
10  
11 #ifndef FAT16_H
12 #define FAT16_H
13  
14 #include "fat16_config.h"
15  
16 #include <stdint.h>
17  
18 /**
19 * \addtogroup fat16
20 *
21 * @{
22 */
23 /**
24 * \file
25 * FAT16 header (license: GPLv2 or LGPLv2.1)
26 *
27 * \author Roland Riegel
28 */
29  
30 /**
31 * \addtogroup fat16_file
32 * @{
33 */
34  
35 /** The file is read-only. */
36 #define FAT16_ATTRIB_READONLY (1 << 0)
37 /** The file is hidden. */
38 #define FAT16_ATTRIB_HIDDEN (1 << 1)
39 /** The file is a system file. */
40 #define FAT16_ATTRIB_SYSTEM (1 << 2)
41 /** The file is empty and has the volume label as its name. */
42 #define FAT16_ATTRIB_VOLUME (1 << 3)
43 /** The file is a directory. */
44 #define FAT16_ATTRIB_DIR (1 << 4)
45 /** The file has to be archived. */
46 #define FAT16_ATTRIB_ARCHIVE (1 << 5)
47  
48 /** The given offset is relative to the beginning of the file. */
49 #define FAT16_SEEK_SET 0
50 /** The given offset is relative to the current read/write position. */
51 #define FAT16_SEEK_CUR 1
52 /** The given offset is relative to the end of the file. */
53 #define FAT16_SEEK_END 2
54  
55 /**
56 * @}
57 */
58  
59 struct partition_struct;
60 struct fat16_fs_struct;
61 struct fat16_file_struct;
62 struct fat16_dir_struct;
63  
64 /**
65 * \ingroup fat16_file
66 * Describes a directory entry.
67 */
68 struct fat16_dir_entry_struct
69 {
70 /** The file's name, truncated to 31 characters. */
71 char long_name[32];
72 /** The file's attributes. Mask of the FAT16_ATTRIB_* constants. */
73 uint8_t attributes;
74 #if FAT16_DATETIME_SUPPORT
75 /** Compressed representation of modification time. */
76 uint16_t modification_time;
77 /** Compressed representation of modification date. */
78 uint16_t modification_date;
79 #endif
80 /** The cluster in which the file's first byte resides. */
81 uint16_t cluster;
82 /** The file's size. */
83 uint32_t file_size;
84 /** The total disk offset of this directory entry. */
85 uint32_t entry_offset;
86 };
87  
88 struct fat16_fs_struct* fat16_open(struct partition_struct* partition);
89 void fat16_close(struct fat16_fs_struct* fs);
90  
91 struct fat16_file_struct* fat16_open_file(struct fat16_fs_struct* fs, const struct fat16_dir_entry_struct* dir_entry);
92 void fat16_close_file(struct fat16_file_struct* fd);
93 int16_t fat16_read_file(struct fat16_file_struct* fd, uint8_t* buffer, uint16_t buffer_len);
94 int16_t fat16_write_file(struct fat16_file_struct* fd, const uint8_t* buffer, uint16_t buffer_len);
95 uint8_t fat16_seek_file(struct fat16_file_struct* fd, int32_t* offset, uint8_t whence);
96 uint8_t fat16_resize_file(struct fat16_file_struct* fd, uint32_t size);
97  
98 struct fat16_dir_struct* fat16_open_dir(struct fat16_fs_struct* fs, const struct fat16_dir_entry_struct* dir_entry);
99 void fat16_close_dir(struct fat16_dir_struct* dd);
100 uint8_t fat16_read_dir(struct fat16_dir_struct* dd, struct fat16_dir_entry_struct* dir_entry);
101 uint8_t fat16_reset_dir(struct fat16_dir_struct* dd);
102  
103 uint8_t fat16_create_file(struct fat16_dir_struct* parent, const char* file, struct fat16_dir_entry_struct* dir_entry);
104 uint8_t fat16_delete_file(struct fat16_fs_struct* fs, struct fat16_dir_entry_struct* dir_entry);
105 uint8_t fat16_create_dir(struct fat16_dir_struct* parent, const char* dir, struct fat16_dir_entry_struct* dir_entry);
106 #define fat16_delete_dir fat16_delete_file
107  
108 void fat16_get_file_modification_date(const struct fat16_dir_entry_struct* dir_entry, uint16_t* year, uint8_t* month, uint8_t* day);
109 void fat16_get_file_modification_time(const struct fat16_dir_entry_struct* dir_entry, uint8_t* hour, uint8_t* min, uint8_t* sec);
110  
111 uint8_t fat16_get_dir_entry_of_path(struct fat16_fs_struct* fs, const char* path, struct fat16_dir_entry_struct* dir_entry);
112  
113 uint32_t fat16_get_fs_size(const struct fat16_fs_struct* fs);
114 uint32_t fat16_get_fs_free(const struct fat16_fs_struct* fs);
115  
116 /**
117 * @}
118 */
119  
120 #endif
121