some cleaning
[protos/imu.git] / fat.h
1
2 /*
3  * Copyright (c) 2006-2012 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 FAT_H
12 #define FAT_H
13
14 #include <stdint.h>
15 #include "fat_config.h"
16
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif
21
22 /**
23  * \addtogroup fat
24  *
25  * @{
26  */
27 /**
28  * \file
29  * FAT header (license: GPLv2 or LGPLv2.1)
30  *
31  * \author Roland Riegel
32  */
33
34 /**
35  * \addtogroup fat_file
36  * @{
37  */
38
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)
51
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
58
59 /**
60  * @}
61  */
62
63 struct partition_struct;
64 struct fat_fs_struct;
65 struct fat_file_struct;
66 struct fat_dir_struct;
67
68 /**
69  * \ingroup fat_file
70  * Describes a directory entry.
71  */
72 struct fat_dir_entry_struct
73 {
74     /** The file's name, truncated to 31 characters. */
75     char long_name[32];
76     /** The file's attributes. Mask of the FAT_ATTRIB_* constants. */
77     uint8_t attributes;
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;
83 #endif
84     /** The cluster in which the file's first byte resides. */
85     cluster_t cluster;
86     /** The file's size. */
87     uint32_t file_size;
88     /** The total disk offset of this directory entry. */
89     offset_t entry_offset;
90 };
91
92 struct fat_fs_struct* fat_open(struct partition_struct* partition);
93 void fat_close(struct fat_fs_struct* fs);
94
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);
101
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);
106
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
113
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);
116
117 uint8_t fat_get_dir_entry_of_path(struct fat_fs_struct* fs, const char* path, struct fat_dir_entry_struct* dir_entry);
118
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);
121
122 /**
123  * @}
124  */
125
126 #ifdef __cplusplus
127 }
128 #endif
129
130 #endif
131