move to debhelper compat 13, hopefully fixes cross-building
[debian/cpmtools] / cpmfs.h
1 #ifndef CPMFS_H
2 #define CPMFS_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include "device.h"
9
10 /* CP/M file attributes */
11 #define CPM_ATTR_F1             1
12 #define CPM_ATTR_F2             2
13 #define CPM_ATTR_F3             4
14 #define CPM_ATTR_F4             8
15 /* F5-F8 are banned in CP/M 2 & 3, F7 is used by ZSDOS */
16 #define CPM_ATTR_RO             256     /* Read-only */
17 #define CPM_ATTR_SYS            512     /* System */
18 #define CPM_ATTR_ARCV           1024    /* Archive */
19 #define CPM_ATTR_PWDEL          2048    /* Password required to delete */
20 #define CPM_ATTR_PWWRITE        4096    /* Password required to write */
21 #define CPM_ATTR_PWREAD         8192    /* Password required to read */
22
23 typedef int cpm_attr_t;
24
25 struct cpmInode
26 {
27   ino_t ino;
28   mode_t mode;
29   off_t size;
30   cpm_attr_t attr;
31   time_t atime;
32   time_t mtime;
33   time_t ctime;
34   struct cpmSuperBlock *sb;
35 };
36
37 struct cpmFile
38 {
39   mode_t mode;
40   off_t pos;
41   struct cpmInode *ino;
42 };
43
44 struct cpmDirent
45 {
46   ino_t ino;
47   off_t off;
48   size_t reclen;
49   char name[2+8+1+3+1]; /* 00foobarxy.zzy\0 */
50 };
51
52 struct cpmStat
53 {
54   ino_t ino;
55   mode_t mode;
56   off_t size;
57   time_t atime;
58   time_t mtime;
59   time_t ctime;
60 };
61
62 /* Note: CPMFS_HI_USER should be split for systems with user numbers
63  * up to 31 and CP/M 3, which uses them, but for password entries and
64  * not for files.
65  */
66 #define CPMFS_HI_USER    (0x1<<0) /* has user numbers up to 31    */
67 #define CPMFS_CPM3_DATES (0x1<<1) /* has CP/M+ style time stamps  */
68 #define CPMFS_CPM3_OTHER (0x1<<2) /* has passwords and disc label */
69 #define CPMFS_DS_DATES   (0x1<<3) /* has datestamper timestamps   */
70 #define CPMFS_EXACT_SIZE (0x1<<4) /* has reverse exact file size  */
71
72 #define CPMFS_DR22  (CPMFS_HI_USER)
73 #define CPMFS_P2DOS (CPMFS_CPM3_DATES|CPMFS_HI_USER)
74 #define CPMFS_DR3   (CPMFS_CPM3_DATES|CPMFS_CPM3_OTHER|CPMFS_HI_USER)
75 #define CPMFS_ISX   (CPMFS_EXACT_SIZE)
76 #define CPMFS_ZSYS  (CPMFS_HI_USER)
77
78 struct dsEntry
79 {
80   char year;
81   char month;
82   char day;
83   char hour;
84   char minute;
85 };
86           
87 struct dsDate
88 {
89   struct dsEntry create;
90   struct dsEntry access;
91   struct dsEntry modify;
92   char checksum;
93 };
94
95 struct cpmSuperBlock
96 {
97   struct Device dev;
98   int uppercase;
99
100   int secLength;
101   int tracks;
102   int sectrk;
103   int blksiz;
104   int maxdir;
105   int dirblks;
106   int skew;
107   int bootsec;
108   int boottrk;
109   off_t offset;
110   int type;
111   int size;
112   int extents; /* logical extents per physical extent */
113   int *skewtab;
114   char libdskGeometry[256];
115
116   struct PhysDirectoryEntry *dir;
117   int alvSize;
118   int *alv;
119   int cnotatime;
120   char *label;
121   size_t labelLength;
122   char *passwd;
123   size_t passwdLength;
124   struct cpmInode *root;
125   int dirtyDirectory;
126   struct dsDate *ds;
127   int dirtyDs;
128 };
129
130 struct cpmStatFS
131 {
132   long f_bsize;
133   long f_blocks;
134   long f_bfree;
135   long f_bused;
136   long f_bavail;
137   long f_files;
138   long f_ffree;
139   long f_namelen;
140 };
141
142 extern char const cmd[];
143 extern char const *boo;
144
145 int match(char const *a, char const *pattern);
146 void cpmglob(int opti, int argc, char * const argv[], struct cpmInode *root, int *gargc, char ***gargv);
147 void cpmglobfree(char **dirent, int entries);
148
149 int cpmReadSuper(struct cpmSuperBlock *drive, struct cpmInode *root, const char *format, int uppercase);
150 int cpmNamei(const struct cpmInode *dir, const char *filename, struct cpmInode *i);
151 void cpmStatFS(const struct cpmInode *ino, struct cpmStatFS *buf);
152 int cpmUnlink(const struct cpmInode *dir, const char *fname);
153 int cpmRename(const struct cpmInode *dir, const char *old, const char *newname);
154 int cpmOpendir(struct cpmInode *dir, struct cpmFile *dirp);
155 int cpmReaddir(struct cpmFile *dir, struct cpmDirent *ent);
156 void cpmStat(const struct cpmInode *ino, struct cpmStat *buf);
157 int cpmAttrGet(struct cpmInode *ino, cpm_attr_t *attrib);
158 int cpmAttrSet(struct cpmInode *ino, cpm_attr_t attrib);
159 int cpmChmod(struct cpmInode *ino, mode_t mode);
160 int cpmOpen(struct cpmInode *ino, struct cpmFile *file, mode_t mode);
161 ssize_t cpmRead(struct cpmFile *file, char *buf, size_t count);
162 ssize_t cpmWrite(struct cpmFile *file, const char *buf, size_t count);
163 int cpmClose(struct cpmFile *file);
164 int cpmCreat(struct cpmInode *dir, const char *fname, struct cpmInode *ino, mode_t mode);
165 void cpmUtime(struct cpmInode *ino, struct utimbuf *times);
166 int cpmSync(struct cpmSuperBlock *sb);
167 int cpmUmount(struct cpmSuperBlock *sb);
168 int cpmCheckDs(struct cpmSuperBlock *sb);
169
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif