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