blob: a2bd970933dc8de8954f051e80561d94d14102f6 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
2 * pubstruct.h
3 *
4 * Public structure definition.
5 * head file.
6 *
7 * Copyright (C) knightray@gmail.com
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 */
11#ifndef _PUB_STRUCT_H
12#define _PUB_STRUCT_H
13
14#include "comdef.h"
15#include "crtdef.h"
16#include "cache.h"
17#include "hai.h"
18
19typedef struct _boot_sector_bh_fat16{
20 ubyte drv_num;
21 ubyte reserved1;
22 ubyte boot_sig;
23 uint32 vol_id;
24 ubyte vol_lab[11];
25 ubyte fil_sys_type[8];
26 ubyte boot_code[448];
27}__attribute__((packed)) boot_sector_bh_fat16_t;
28
29typedef struct _boot_sector_bh_fat32{
30 uint32 fatsz32;
31 uint16 ext_flags;
32 uint16 fsver;
33 uint32 root_clus;
34 uint16 fs_info;
35 uint16 bk_boot_sec;
36 ubyte reserved[12];
37 ubyte drv_num;
38 ubyte reserved1;
39 ubyte boot_sig;
40 uint32 vol_id;
41 ubyte vol_lab[11];
42 ubyte fil_sys_type[8];
43 ubyte boot_code[420];
44}__attribute__((packed)) boot_sector_bh_fat32_t;
45
46typedef struct _boot_sector{
47 ubyte jmp_boot[3];
48 ubyte oem_name[8];
49 uint16 byts_per_sec;
50 ubyte sec_per_clus;
51 uint16 resvd_sec_cnt;
52 ubyte num_fats;
53 uint16 root_ent_cnt;
54 uint16 tot_sec16;
55 ubyte media;
56 uint16 fatsz16;
57 uint16 sec_per_trk;
58 uint16 num_heads;
59 uint32 hidd_sec;
60 uint32 tot_sec32;
61 union{
62 boot_sector_bh_fat16_t bh16;
63 boot_sector_bh_fat32_t bh32;
64 };
65 uint16 bs_sig;
66}__attribute__((packed)) boot_sector_t;
67
68#define FT_FAT12 (1)
69#define FT_FAT16 (2)
70#define FT_FAT32 (3)
71
72typedef struct _tffs{
73 boot_sector_t* pbs;
74 tdev_handle_t hdev;
75 struct _tfat* pfat;
76 struct _tdir* root_dir;
77 struct _tdir* cur_dir;
78 tcache_t* pcache;
79 /* Marvell fixed */
80#ifdef TFFS_FAT_CACHE
81 tcache_t* pfatcache;
82#endif
83 ubyte fat_type;
84 /* Marvell fixed */
85 ubyte num_fats;
86 uint16 root_dir_sectors;
87 uint32 sec_root_dir;
88 uint32 sec_first_data;
89 uint32 sec_fat;
90 uint32 fatsz;
91 uint32 total_clusters;
92 /* Marvell fixed: added externel helper for nospace cases */
93 int32 (*p_nospace_handler)(void *);
94 void *nospace_handler_arg;
95}tffs_t;
96
97typedef struct _tdir{
98 tffs_t * ptffs;
99 ubyte * secbuf;
100 uint32 start_clus;
101 uint32 cur_clus;
102 uint32 cur_sec;
103 uint32 cur_dir_entry;
104}tdir_t;
105
106#define ATTR_READ_ONLY 0x01
107#define ATTR_HIDDEN 0x02
108#define ATTR_SYSTEM 0x04
109#define ATTR_VOLUME_ID 0x08
110#define ATTR_DIRECTORY 0x10
111#define ATTR_ARCHIVE 0x20
112#define ATTR_LONG_NAME (ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID)
113
114#define LAST_LONG_ENTRY 0x40
115
116typedef struct _dir_entry{
117 ubyte dir_name[11];
118 ubyte dir_attr;
119 ubyte dir_ntres;
120 ubyte dir_crt_time_tenth;
121 uint16 dir_crt_time;
122 uint16 dir_crt_date;
123 uint16 dir_lst_acc_date;
124 uint16 dir_fst_clus_hi;
125 uint16 dir_wrt_time;
126 uint16 dir_wrt_date;
127 uint16 dir_fst_clus_lo;
128 uint32 dir_file_size;
129}__attribute__((packed)) dir_entry_t;
130
131#define LONG_NAME_LEN 64
132#define SHORT_NAME_LEN 14
133
134typedef struct _tdir_entry{
135 dir_entry_t * pdirent;
136 uint32 dirent_num;
137 byte long_name[LONG_NAME_LEN];
138 byte short_name[SHORT_NAME_LEN];
139}tdir_entry_t;
140
141#define ROOT_DIR_CLUS_FAT16 (0)
142#define INVALID_CLUSTER (1)
143
144#define OPENMODE_READONLY 0x1
145#define OPENMODE_WRITE 0x2
146#define OPENMODE_APPEND 0x4
147
148typedef struct _tfile{
149 tffs_t * ptffs;
150 tdir_t * pdir;
151 tdir_entry_t * pdir_entry;
152 ubyte * secbuf;
153 uint32 open_mode;
154 uint32 start_clus;
155
156 uint32 file_size;
157 uint32 cur_fp_offset;
158
159 uint32 cur_clus;
160 uint32 cur_sec;
161 uint32 cur_sec_offset;
162}tfile_t;
163
164#define FAT_INVALID_CLUS (0xF0000000)
165
166/* Marvell fixed */
167#ifdef TFFS_FAT_MIRROR
168struct fat_mirror {
169 ubyte *buffer;
170 uint32 first;
171 uint32 nsec;
172 uint32 maxsec;
173};
174#endif
175typedef struct _tfat{
176 tffs_t * ptffs;
177 uint32 last_free_clus;
178 ubyte * secbuf;
179 uint32 cur_fat_sec;
180#ifdef TFFS_FAT_MIRROR
181 struct fat_mirror fatm; /* Marvell fixed */
182#endif
183}tfat_t;
184
185#endif