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