emu: deactivate debugger/memview when the other one is activated
[zymosis.git] / src / libfusefdc / diskfs_pisdos.h
blobc3303f22e48552219f09e5409b82c1d7a6f25ff1
1 /***************************************************************************
3 * pisDOS FS support (r/o)
5 * Written by Ketmar Dark <ketmar@ketmar.no-ip.org>
6 * Used some information from HalfElf XiSD FAR plugin
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, version 3 of the License ONLY.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **************************************************************************/
21 #ifndef PISDOS_FS_SUPPORT_H
22 #define PISDOS_FS_SUPPORT_H
24 #include "diskfs_p3dos.h"
27 // ////////////////////////////////////////////////////////////////////////// //
28 typedef struct __attribute__((packed)) {
29 uint16_t load_addr;
30 uint8_t size[3];
31 uint16_t first_block;
32 uint8_t sys_flag;
33 uint8_t reserved[6];
34 uint16_t crc;
35 uint16_t time;
36 } PisDOS_DEFile;
39 typedef struct __attribute__((packed)) {
40 uint16_t parent_dir_block;
41 uint16_t size;
42 uint8_t level;
43 uint16_t frag_block;
44 uint16_t first_block;
45 uint8_t files_total;
46 uint8_t files_count;
47 uint8_t level_chic;
48 uint8_t reserved[6];
49 } PisDOS_DEDir;
52 typedef struct __attribute__((packed)) {
53 uint8_t name[8];
54 uint8_t ext[3];
55 uint8_t attr;
56 union __attribute__((packed)) {
57 PisDOS_DEFile file;
58 PisDOS_DEDir dir;
60 uint16_t date;
61 } PisDOS_DirEnt;
64 typedef struct __attribute__((packed)) {
65 uint8_t reserved1[2];
66 uint8_t title[8];
67 uint8_t signature[3];
68 uint8_t sign_chic[3];
69 uint8_t reserved2[2];
70 uint16_t blocks_total;
71 uint16_t rootdir_block;
72 uint8_t tracks_total;
73 uint8_t type;
74 uint8_t sector_size;
75 uint8_t sectors_per_track;
76 uint8_t reserved3[4];
77 uint16_t date;
78 PisDOS_DEFile isd_sys;
79 uint8_t sector_table[0x10]; // dunno
80 } PisDOS_DPB;
83 typedef struct {
84 uint8_t day;
85 uint8_t month;
86 uint16_t year;
87 uint8_t hour;
88 uint8_t minute;
89 uint8_t second;
90 } PisDOSDateTime;
93 // doesn't modify time part
94 void pisdos_unpack_date (PisDOSDateTime *dt, uint16_t v);
96 // doesn't modify date part
97 void pisdos_unpack_time (PisDOSDateTime *dt, uint16_t v);
100 #define PISDOS_BLOCK_SIZE (256)
102 #define PISDOS_FLAG_USED (0x01)
103 #define PISDOS_FLAG_NO_READ (0x04)
104 #define PISDOS_FLAG_NO_WRITE (0x08)
105 #define PISDOS_FLAG_HIDDEN (0x10)
106 #define PISDOS_FLAG_DIR (0x20)
107 #define PISDOS_FLAG_CONTINUOUS (0x40)
108 #define PISDOS_FLAG_NO_DELETE (0x80)
111 // dummy DE for root dir
112 extern const PisDOS_DirEnt pisdos_deroot;
115 static __attribute__((unused)) inline int pisdos_is_dir (const PisDOS_DirEnt *h) {
116 return (h->attr != 0xFF && h->file.sys_flag != 0xFF && (h->attr&PISDOS_FLAG_DIR));
119 static __attribute__((unused)) inline uint32_t pisdos_get_entry_size (const PisDOS_DirEnt *h) {
120 return
121 pisdos_is_dir(h) ? h->dir.size :
122 h->file.size[0]|(h->file.size[1]<<8)|(h->file.size[2]<<16);
126 void pisdos_get_title (char fname[14], const PisDOS_DPB *dpb);
128 void pisdos_get_name (char fname[14], const PisDOS_DirEnt *de);
129 void pisdos_set_name (PisDOS_DirEnt *de, const char fname[14]);
131 // return NULL if disk doesn't look like a good pisdos disk
132 const PisDOS_DPB *pisdos_get_dpb (disk_t *dsk);
134 // return pointer to the given disk block data, or NULL
135 const void *pisdos_block_ptr (disk_t *dsk, int blknum);
138 // ////////////////////////////////////////////////////////////////////////// //
139 // file reading API
141 typedef struct __attribute__((packed)) {
142 uint16_t start_block; // of this fragment data
143 uint8_t block_count; // number of blocks in this fragment
144 } PisDOSFragInfo;
147 typedef struct {
148 uint8_t frag_count; // number of fragments; if 1, the file is continuous
149 PisDOSFragInfo frags[256]; // starting blocks of each fragment data
150 // for continuous files (files with one fragment are converted to this too)
151 uint16_t start_block; // of this fragment data
152 uint16_t block_count; // number of blocks in this fragment
153 // this is for file reading
154 uint8_t curr_frag; // current active fragment (from 0)
155 uint16_t curr_block_idx; // from the start of the current fragment
156 } PisDOSFragList;
159 // to read pisdos file, find it, build frags, and keep calling
160 // `pisdos_next_block()` until you read enough 256-byte blocks
163 // build list of fragments for the given file
164 // return 0 on success, negative number on error
165 int pisdos_build_frags (disk_t *dsk, const PisDOS_DirEnt *de, PisDOSFragList *list);
167 // return pointer to the next file block
168 // if called right after `pisdos_build_frags`, return pointer to the first block
169 // return NULL on error or EOF (nobody cares what exactly happened anyway)
170 const void *pisdos_next_block (disk_t *dsk, PisDOSFragList *list);
173 // iterator callback for the next function
174 // return non-zero to stop
175 typedef int (*pisdor_dir_iterator_cb) (const PisDOS_DirEnt *de, void *udata);
177 // return iterator callback result or 0
178 // return negative number on error
179 int pisdos_dir_foreach (disk_t *dsk, const PisDOS_DirEnt *dirde,
180 pisdor_dir_iterator_cb cb, void *udata);
183 // return non-zero if the given path is a path to the root directory
184 // note that empty or NULL string considered as "root path"
185 int pisdos_is_root_path (const char *path);
187 // walk down subdirs starting from `dirde` using `path`
188 // ignore last path entry (filename)
189 // return directory entry to look for the last path entry
190 // 'cmon, do you really care about all this shit?
191 const PisDOS_DirEnt *pisdos_walk_path (disk_t *dsk, const PisDOS_DirEnt *dirde,
192 const char *path);
195 // ////////////////////////////////////////////////////////////////////////// //
196 typedef struct {
197 disk_t *dsk;
198 char mask[32];
199 const PisDOS_DirEnt *dirde;
200 const PisDOS_DirEnt *delist[256];
201 uint32_t de_count;
202 uint32_t de_current;
203 } PisDOSFindInfo;
206 // exactly what you may thing
207 // supports wildcards
208 const PisDOS_DirEnt *pisdos_findnext (PisDOSFindInfo *fi);
209 const PisDOS_DirEnt *pisdos_findfirst (PisDOSFindInfo *fi, disk_t *dsk, const char *fname);
212 // ////////////////////////////////////////////////////////////////////////// //
213 // debug
214 void pisdos_debug_dump_dpb (disk_t *dsk);
217 #endif