New upstream version 2.20
[debian/cpmtools] / cpmfs.h
1 #ifndef CPMFS_H
2 #define CPMFS_H
3
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 #include <utime.h>
7
8 #ifdef _WIN32
9     #include <windows.h>
10     #include <winioctl.h>
11     /* To make it compile on NT: extracts from Linux 2.0 *
12      * <statbuf.h> and <sys/stat.h>                      */
13     #define __S_IFMT        0170000 /* These bits determine file type.  */
14     #define __S_IFDIR       0040000 /* Directory.  */
15     #define __S_IFREG       0100000 /* Regular file.  */
16     #define __S_IWUSR       0000200 /* Writable for user.  */
17     #define __S_IWGRP       0000200 /* Writable for group.  */
18     #define __S_IWOTH       0000200 /* Writable for others.  */
19
20     #define __S_ISTYPE(mode, mask)  (((mode) & __S_IFMT) == (mask))
21     #define __S_ISTYPE(mode, mask)  (((mode) & __S_IFMT) == (mask))
22     /* These bits are defined in Borland C++ 5 but not in MS Visual C++ */
23     #ifndef S_ISDIR
24     # define S_ISDIR(mode)   __S_ISTYPE((mode), __S_IFDIR)
25     #endif
26     #ifndef S_ISREG
27     # define S_ISREG(mode)   __S_ISTYPE((mode), __S_IFREG)
28     #endif
29     #ifndef S_IWUSR
30     #define S_IWUSR __S_IWUSR
31     #endif
32     #ifndef S_IWGRP
33     #define S_IWGRP __S_IWGRP
34     #endif
35     #ifndef S_IWOTH
36     #define S_IWOTH __S_IWOTH
37     #endif
38
39     #include <io.h>            /* For open(), lseek() etc. */
40     #ifndef HAVE_MODE_T
41     typedef int mode_t;
42     #endif
43 #endif
44
45 #ifdef __cplusplus
46         extern "C" {
47 #endif
48
49 #include "device.h"
50
51 /* CP/M file attributes */
52 #define CPM_ATTR_F1             1
53 #define CPM_ATTR_F2             2
54 #define CPM_ATTR_F3             4
55 #define CPM_ATTR_F4             8
56 /* F5-F8 are banned in CP/M 2 & 3, F7 is used by ZSDOS */
57 #define CPM_ATTR_RO             256     /* Read-only */
58 #define CPM_ATTR_SYS            512     /* System */
59 #define CPM_ATTR_ARCV           1024    /* Archive */
60 #define CPM_ATTR_PWDEL          2048    /* Password required to delete */
61 #define CPM_ATTR_PWWRITE        4096    /* Password required to write */
62 #define CPM_ATTR_PWREAD         8192    /* Password required to read */
63
64 typedef int cpm_attr_t;
65
66 struct cpmInode
67 {
68   ino_t ino;
69   mode_t mode;
70   off_t size;
71   cpm_attr_t attr;
72   time_t atime;
73   time_t mtime;
74   time_t ctime;
75   struct cpmSuperBlock *sb;
76 };
77
78 struct cpmFile
79 {
80   mode_t mode;
81   off_t pos;
82   struct cpmInode *ino;
83 };
84
85 struct cpmDirent
86 {
87   ino_t ino;
88   off_t off;
89   size_t reclen;
90   char name[2+8+1+3+1]; /* 00foobarxy.zzy\0 */
91 };
92
93 struct cpmStat
94 {
95   ino_t ino;
96   mode_t mode;
97   off_t size;
98   time_t atime;
99   time_t mtime;
100   time_t ctime;
101 };
102
103 #define CPMFS_HI_USER    (0x1<<0) /* has user numbers up to 31    */
104 #define CPMFS_CPM3_DATES (0x1<<1) /* has CP/M+ style time stamps  */
105 #define CPMFS_CPM3_OTHER (0x1<<2) /* has passwords and disc label */
106 #define CPMFS_DS_DATES   (0x1<<3) /* has datestamper timestamps   */
107 #define CPMFS_EXACT_SIZE (0x1<<4) /* has reverse exact file size  */
108
109 #define CPMFS_DR22  0
110 #define CPMFS_P2DOS (CPMFS_CPM3_DATES|CPMFS_HI_USER)
111 #define CPMFS_DR3   (CPMFS_CPM3_DATES|CPMFS_CPM3_OTHER|CPMFS_HI_USER)
112 #define CPMFS_ISX   (CPMFS_EXACT_SIZE)
113 #define CPMFS_ZSYS  (CPMFS_HI_USER)
114
115 struct dsEntry
116 {
117   char year;
118   char month;
119   char day;
120   char hour;
121   char minute;
122 };
123           
124 struct dsDate
125 {
126   struct dsEntry create;
127   struct dsEntry access;
128   struct dsEntry modify;
129   char checksum;
130 };
131
132 struct cpmSuperBlock
133 {
134   struct Device dev;
135
136   int secLength;
137   int tracks;
138   int sectrk;
139   int blksiz;
140   int maxdir;
141   int skew;
142   int boottrk;
143   off_t offset;
144   int type;
145   int size;
146   int extents; /* logical extents per physical extent */
147   struct PhysDirectoryEntry *dir;
148   int alvSize;
149   int *alv;
150   int *skewtab;
151   int cnotatime;
152   char *label;
153   size_t labelLength;
154   char *passwd;
155   size_t passwdLength;
156   struct cpmInode *root;
157   int dirtyDirectory;
158   struct dsDate *ds;
159   int dirtyDs;
160   char libdskGeometry[256];
161 };
162
163 struct cpmStatFS
164 {
165   long f_bsize;
166   long f_blocks;
167   long f_bfree;
168   long f_bused;
169   long f_bavail;
170   long f_files;
171   long f_ffree;
172   long f_namelen;
173 };
174
175 extern const char cmd[];
176 extern const char *boo;
177
178 int match(const char *a, const char *pattern);
179 void cpmglob(int opti, int argc, char * const argv[], struct cpmInode *root, int *gargc, char ***gargv);
180
181 int cpmReadSuper(struct cpmSuperBlock *drive, struct cpmInode *root, const char *format);
182 int cpmNamei(const struct cpmInode *dir, const char *filename, struct cpmInode *i);
183 void cpmStatFS(const struct cpmInode *ino, struct cpmStatFS *buf);
184 int cpmUnlink(const struct cpmInode *dir, const char *fname);
185 int cpmRename(const struct cpmInode *dir, const char *old, const char *newname);
186 int cpmOpendir(struct cpmInode *dir, struct cpmFile *dirp);
187 int cpmReaddir(struct cpmFile *dir, struct cpmDirent *ent);
188 void cpmStat(const struct cpmInode *ino, struct cpmStat *buf);
189 int cpmAttrGet(struct cpmInode *ino, cpm_attr_t *attrib);
190 int cpmAttrSet(struct cpmInode *ino, cpm_attr_t attrib);
191 int cpmChmod(struct cpmInode *ino, mode_t mode);
192 int cpmOpen(struct cpmInode *ino, struct cpmFile *file, mode_t mode);
193 int cpmRead(struct cpmFile *file, char *buf, int count);
194 int cpmWrite(struct cpmFile *file, const char *buf, int count);
195 int cpmClose(struct cpmFile *file);
196 int cpmCreat(struct cpmInode *dir, const char *fname, struct cpmInode *ino, mode_t mode);
197 void cpmUtime(struct cpmInode *ino, struct utimbuf *times);
198 int cpmSync(struct cpmSuperBlock *sb);
199 void cpmUmount(struct cpmSuperBlock *sb);
200 int cpmCheckDs(struct cpmSuperBlock *sb);
201
202 #ifdef __cplusplus
203         }
204 #endif
205
206 #endif