1 /*
2 * The ARAnyM MetaDOS driver.
3 *
4 * 2002 STan
5 *
6 * Based on:
7 * filesys.h,v 1.8 2001/06/13 20:21:15 fna Exp
8 *
9 * This file has been modified as part of the FreeMiNT project. See
10 * the file Changes.MH for details and dates.
11 */
12
13 # ifndef _filesys_h
14 # define _filesys_h
15
16 typedef struct proc PROC;
17
18 #include "mint/fsops.h"
19 #include "mint/file.h"
20 #include "mint/filedesc.h"
21
22 struct ucred;
23
24 # define DIRSEP(p) (((p) == '\\') || ((p) == '/'))
25 # define MAX_LINKS 4
26 # define follow_links ((char *) -1L)
27
28
29 /*
30 * external variables
31 */
32 extern FILESYS *active_fs;
33 extern FILESYS *drives[NUM_DRIVES];
34 extern int aliasdrv[NUM_DRIVES];
35 extern long dosdrvs;
36
37
38 /*
39 * exported functions
40 */
41 long getxattr (FILESYS *fs, fcookie *fc, XATTR *xattr);
42 long getstat64 (FILESYS *fs, fcookie *fc, STAT *ptr);
43
44 void kill_cache(fcookie *dir, char *name);
45 long cache_lookup(fcookie *dir, char *name, fcookie *res);
46 void cache_init(void);
47 void clobber_cookie(fcookie *fc);
48 void init_filesys(void);
49 char *xfs_name(fcookie *fc);
50 void xfs_add(FILESYS *fs);
51 void close_filesys(void);
52 long _s_ync(void);
53 long _cdecl sys_s_ync(void);
54 long _cdecl sys_fsync(short fh);
55 long _cdecl relpath2cookie(struct proc *p, fcookie *dir, const char *path, char *lastnm,
56 fcookie *res, int depth);
57 long _cdecl path2cookie(struct proc *p, const char *path, char *lastname, fcookie *res);
58 void _cdecl release_cookie(fcookie *fc);
59 void dup_cookie(fcookie *new, fcookie *old);
60 int _cdecl denyshare(FILEPTR *list, FILEPTR *newfileptr);
61 int denyaccess(struct ucred *cred, XATTR *, ushort);
62 LOCK *denylock(ushort pid, LOCK *list, LOCK *newlock);
63 long dir_access(struct ucred *cred, fcookie *, ushort, ushort *);
64 int has_wild(const char *name);
65 void copy8_3(char *dest, const char *src);
66 int pat_match(const char *name, const char *template);
67 int samefile(fcookie *, fcookie *);
68
69
70 # ifndef NONBLOCKING_DMA
71 # define xfs_lock(fs, dev, func)
72 # define xfs_unlock(fs, dev, func)
73 # else
74 # ifdef DEBUG_INFO
75 # define xfs_lock(fs, dev, func) \
76 ({ \
77 if (!(fs->fsflags & FS_REENTRANT_L2)) \
78 xfs_block(fs, dev, func); \
79 })
80 # define xfs_unlock(fs, dev, func) \
81 ({ \
82 if (!(fs->fsflags & FS_REENTRANT_L2)) \
83 xfs_deblock(fs, dev, func); \
84 })
85 # else
86 # define xfs_lock(fs, dev, func) \
87 ({ \
88 if (!(fs->fsflags & FS_REENTRANT_L2)) \
89 xfs_block(fs, dev, NULL); \
90 })
91 # define xfs_unlock(fs, dev, func) \
92 ({ \
93 if (!(fs->fsflags & FS_REENTRANT_L2)) \
94 xfs_deblock(fs, dev, NULL); \
95 })
96 # endif /* DEBUG_INFO */
97 # endif
98
99 INLINE long
xfs_root(FILESYS * fs,int drv,fcookie * fc)100 xfs_root(FILESYS *fs, int drv, fcookie *fc)
101 {
102 long r;
103
104 xfs_lock(fs, drv, "xfs_root");
105 r = (*fs->root)(drv, fc);
106 xfs_unlock(fs, drv, "xfs_root");
107
108 return r;
109 }
110
111 INLINE long
xfs_lookup(FILESYS * fs,fcookie * dir,const char * name,fcookie * fc)112 xfs_lookup(FILESYS *fs, fcookie *dir, const char *name, fcookie *fc)
113 {
114 long r;
115
116 xfs_lock(fs, dir->dev, "xfs_lookup");
117 r = (*fs->lookup)(dir, name, fc);
118 xfs_unlock(fs, dir->dev, "xfs_lokup");
119
120 return r;
121 }
122
123 INLINE DEVDRV *
xfs_getdev(FILESYS * fs,fcookie * fc,long * devsp)124 xfs_getdev(FILESYS *fs, fcookie *fc, long *devsp)
125 {
126 return (*fs->getdev)(fc, devsp);
127 }
128
129 INLINE long
xfs_getxattr(FILESYS * fs,fcookie * fc,XATTR * xattr)130 xfs_getxattr(FILESYS *fs, fcookie *fc, XATTR *xattr)
131 {
132 if (fs->getxattr)
133 {
134 long r;
135
136 xfs_lock(fs, fc->dev, "xfs_getxattr");
137 r = (*fs->getxattr)(fc, xattr);
138 xfs_unlock(fs, fc->dev, "xfs_getxattr");
139
140 return r;
141 }
142
143 return getxattr(fs, fc, xattr);
144 }
145
146 INLINE long
xfs_chattr(FILESYS * fs,fcookie * fc,int attr)147 xfs_chattr(FILESYS *fs, fcookie *fc, int attr)
148 {
149 long r;
150
151 xfs_lock(fs, fc->dev, "xfs_chattr");
152 r = (*fs->chattr)(fc, attr);
153 xfs_unlock(fs, fc->dev, "xfs_chatr");
154
155 return r;
156 }
157 INLINE long
xfs_chown(FILESYS * fs,fcookie * fc,int uid,int gid)158 xfs_chown(FILESYS *fs, fcookie *fc, int uid, int gid)
159 {
160 long r;
161
162 xfs_lock(fs, fc->dev, "xfs_chown");
163 r = (*fs->chown)(fc, uid, gid);
164 xfs_unlock(fs, fc->dev, "xfs_chown");
165
166 return r;
167 }
168
169 INLINE long
xfs_chmode(FILESYS * fs,fcookie * fc,unsigned mode)170 xfs_chmode(FILESYS *fs, fcookie *fc, unsigned mode)
171 {
172 long r;
173
174 xfs_lock(fs, fc->dev, "xfs_chmod");
175 r = (*fs->chmode)(fc, mode);
176 xfs_unlock(fs, fc->dev, "xfs_chmod");
177
178 return r;
179 }
180
181 INLINE long
xfs_mkdir(FILESYS * fs,fcookie * dir,const char * name,unsigned mode)182 xfs_mkdir(FILESYS *fs, fcookie *dir, const char *name, unsigned mode)
183 {
184 long r;
185
186 xfs_lock(fs, dir->dev, "xfs_mkdir");
187 r = (*fs->mkdir)(dir, name, mode);
188 xfs_unlock(fs, dir->dev, "xfs_mkdir");
189
190 return r;
191 }
192 INLINE long
xfs_rmdir(FILESYS * fs,fcookie * dir,const char * name)193 xfs_rmdir(FILESYS *fs, fcookie *dir, const char *name)
194 {
195 long r;
196
197 xfs_lock(fs, dir->dev, "xfs_rmdir");
198 r = (*fs->rmdir)(dir, name);
199 xfs_unlock(fs, dir->dev, "xfs_rmdir");
200
201 return r;
202 }
203 INLINE long
xfs_creat(FILESYS * fs,fcookie * dir,const char * name,unsigned mode,int attr,fcookie * fc)204 xfs_creat(FILESYS *fs, fcookie *dir, const char *name, unsigned mode, int attr, fcookie *fc)
205 {
206 long r;
207
208 xfs_lock(fs, dir->dev, "xfs_creat");
209 r = (*fs->creat)(dir, name, mode, attr, fc);
210 xfs_unlock(fs, dir->dev, "xfs_creat");
211
212 return r;
213 }
214 INLINE long
xfs_remove(FILESYS * fs,fcookie * dir,const char * name)215 xfs_remove(FILESYS *fs, fcookie *dir, const char *name)
216 {
217 long r;
218
219 xfs_lock(fs, dir->dev, "xfs_remove");
220 r = (*fs->remove)(dir, name);
221 xfs_unlock(fs, dir->dev, "xfs_remove");
222
223 return r;
224 }
225 INLINE long
xfs_getname(FILESYS * fs,fcookie * root,fcookie * dir,char * buf,int len)226 xfs_getname(FILESYS *fs, fcookie *root, fcookie *dir, char *buf, int len)
227 {
228 long r;
229
230 xfs_lock(fs, root->dev, "xfs_getname");
231 r = (*fs->getname)(root, dir, buf, len);
232 xfs_unlock(fs, root->dev, "xfs_getname");
233
234 return r;
235 }
236 INLINE long
xfs_rename(FILESYS * fs,fcookie * olddir,char * oldname,fcookie * newdir,const char * newname)237 xfs_rename(FILESYS *fs, fcookie *olddir, char *oldname, fcookie *newdir, const char *newname)
238 {
239 long r;
240
241 xfs_lock(fs, olddir->dev, "xfs_rename");
242 r = (*fs->rename)(olddir, oldname, newdir, newname);
243 xfs_unlock(fs, olddir->dev, "xfs_rename");
244
245 return r;
246 }
247
248 INLINE long
xfs_opendir(FILESYS * fs,DIR * dirh,int flags)249 xfs_opendir(FILESYS *fs, DIR *dirh, int flags)
250 {
251 long r;
252
253 xfs_lock(fs, dirh->fc.dev, "xfs_opendir");
254 r = (*fs->opendir)(dirh, flags);
255 xfs_unlock(fs, dirh->fc.dev, "xfs_opendir");
256
257 return r;
258 }
259 INLINE long
xfs_readdir(FILESYS * fs,DIR * dirh,char * nm,int nmlen,fcookie * fc)260 xfs_readdir(FILESYS *fs, DIR *dirh, char *nm, int nmlen, fcookie *fc)
261 {
262 long r;
263
264 xfs_lock(fs, dirh->fc.dev, "xfs_readdir");
265 r = (*fs->readdir)(dirh, nm, nmlen, fc);
266 xfs_unlock(fs, dirh->fc.dev, "xfs_readdir");
267
268 return r;
269 }
270 INLINE long
xfs_rewinddir(FILESYS * fs,DIR * dirh)271 xfs_rewinddir(FILESYS *fs, DIR *dirh)
272 {
273 long r;
274
275 xfs_lock(fs, dirh->fc.dev, "xfs_rewinddir");
276 r = (*fs->rewinddir)(dirh);
277 xfs_unlock(fs, dirh->fc.dev, "xfs_rwinddir");
278
279 return r;
280 }
281 INLINE long
xfs_closedir(FILESYS * fs,DIR * dirh)282 xfs_closedir(FILESYS *fs, DIR *dirh)
283 {
284 long r;
285
286 xfs_lock(fs, dirh->fc.dev, "xfs_closedir");
287 r = (*fs->closedir)(dirh);
288 xfs_unlock(fs, dirh->fc.dev, "xfs_closedir");
289
290 return r;
291 }
292
293 INLINE long
xfs_pathconf(FILESYS * fs,fcookie * dir,int which)294 xfs_pathconf(FILESYS *fs, fcookie *dir, int which)
295 {
296 return (*fs->pathconf)(dir, which);
297 }
298 INLINE long
xfs_dfree(FILESYS * fs,fcookie * dir,long * buf)299 xfs_dfree(FILESYS *fs, fcookie *dir, long *buf)
300 {
301 long r;
302
303 xfs_lock(fs, dir->dev, "xfs_dfree");
304 r = (*fs->dfree)(dir, buf);
305 xfs_unlock(fs, dir->dev, "xfs_dfree");
306
307 return r;
308 }
309 INLINE long
xfs_writelabel(FILESYS * fs,fcookie * dir,const char * name)310 xfs_writelabel(FILESYS *fs, fcookie *dir, const char *name)
311 {
312 long r;
313
314 xfs_lock(fs, dir->dev, "xfs_writelabel");
315 r = (*fs->writelabel)(dir, name);
316 xfs_unlock(fs, dir->dev, "xfs_writelabel");
317
318 return r;
319 }
320 INLINE long
xfs_readlabel(FILESYS * fs,fcookie * dir,char * name,int namelen)321 xfs_readlabel(FILESYS *fs, fcookie *dir, char *name, int namelen)
322 {
323 long r;
324
325 xfs_lock(fs, dir->dev, "xfs_readlabel");
326 r = (*fs->readlabel)(dir, name, namelen);
327 xfs_unlock(fs, dir->dev, "xfs_readlabel");
328
329 return r;
330 }
331
332 INLINE long
xfs_symlink(FILESYS * fs,fcookie * dir,const char * name,const char * to)333 xfs_symlink(FILESYS *fs, fcookie *dir, const char *name, const char *to)
334 {
335 long r;
336
337 xfs_lock(fs, dir->dev, "xfs_symlink");
338 r = (*fs->symlink)(dir, name , to);
339 xfs_unlock(fs, dir->dev, "xfs_symlink");
340
341 return r;
342 }
343 INLINE long
xfs_readlink(FILESYS * fs,fcookie * fc,char * buf,int len)344 xfs_readlink(FILESYS *fs, fcookie *fc, char *buf, int len)
345 {
346 long r;
347
348 xfs_lock(fs, fc->dev, "xfs_readlink");
349 r = (*fs->readlink)(fc, buf, len);
350 xfs_unlock(fs, fc->dev, "xfs_readlink");
351
352 return r;
353 }
354 INLINE long
xfs_hardlink(FILESYS * fs,fcookie * fromdir,const char * fromname,fcookie * todir,const char * toname)355 xfs_hardlink(FILESYS *fs, fcookie *fromdir, const char *fromname, fcookie *todir, const char *toname)
356 {
357 long r;
358
359 xfs_lock(fs, fromdir->dev, "xfs_hardlink");
360 r = (*fs->hardlink)(fromdir, fromname, todir, toname);
361 xfs_unlock(fs, fromdir->dev, "xfs_hardlink");
362
363 return r;
364 }
365 INLINE long
xfs_fscntl(FILESYS * fs,fcookie * dir,const char * name,int cmd,long arg)366 xfs_fscntl(FILESYS *fs, fcookie *dir, const char *name, int cmd, long arg)
367 {
368 long r;
369
370 xfs_lock(fs, dir->dev, "xfs_fscntl");
371 r = (*fs->fscntl)(dir, name, cmd, arg);
372 xfs_unlock(fs, dir->dev, "xfs_fscntl");
373
374 return r;
375 }
376 INLINE long
xfs_dskchng(FILESYS * fs,int drv,int mode)377 xfs_dskchng(FILESYS *fs, int drv, int mode)
378 {
379 long r;
380
381 xfs_lock(fs, drv, "xfs_dskchng");
382 r = (*fs->dskchng)(drv, mode);
383 xfs_unlock(fs, drv, "xfs_dskchng");
384
385 return r;
386 }
387
388 INLINE long
xfs_release(FILESYS * fs,fcookie * fc)389 xfs_release(FILESYS *fs, fcookie *fc)
390 {
391 return (*fs->release)(fc);
392 }
393 INLINE long
xfs_dupcookie(FILESYS * fs,fcookie * dst,fcookie * src)394 xfs_dupcookie(FILESYS *fs, fcookie *dst, fcookie *src)
395 {
396 return (*fs->dupcookie)(dst, src);
397 }
398
399 INLINE long
xfs_mknod(FILESYS * fs,fcookie * dir,const char * name,ulong mode)400 xfs_mknod(FILESYS *fs, fcookie *dir, const char *name, ulong mode)
401 {
402 long r;
403
404 xfs_lock(fs, dir->dev, "xfs_mknod");
405 r = (*fs->mknod)(dir, name, mode);
406 xfs_unlock(fs, dir->dev, "xfs_mknod");
407
408 return r;
409 }
410 INLINE long
xfs_unmount(FILESYS * fs,int drv)411 xfs_unmount(FILESYS *fs, int drv)
412 {
413 long r;
414
415 xfs_lock(fs, drv, "xfs_unmount");
416 r = (*fs->unmount)(drv);
417 xfs_unlock(fs, drv, "xfs_unmount");
418
419 return r;
420 }
421 INLINE long
xfs_stat64(FILESYS * fs,fcookie * fc,STAT * stat)422 xfs_stat64(FILESYS *fs, fcookie *fc, STAT *stat)
423 {
424 if (fs->fsflags & FS_EXT_3)
425 {
426 long r;
427
428 xfs_lock(fs, fc->dev, "xfs_stat64");
429 r = (*fs->stat64)(fc, stat);
430 xfs_unlock(fs, fc->dev, "xfs_stat64");
431
432 return r;
433 }
434
435 return getstat64(fs, fc, stat);
436 }
437
438
439 INLINE long
xdd_open(FILEPTR * f)440 xdd_open(FILEPTR *f)
441 {
442 long r;
443
444 xfs_lock(f->fc.fs, f->fc.dev, "xdd_open");
445 r = (f->dev->open)(f);
446 xfs_unlock(f->fc.fs, f->fc.dev, "xdd_open");
447
448 return r;
449 }
450 INLINE long
xdd_write(FILEPTR * f,const char * buf,long bytes)451 xdd_write(FILEPTR *f, const char *buf, long bytes)
452 {
453 long r;
454
455 xfs_lock(f->fc.fs, f->fc.dev, "xdd_write");
456 r = (f->dev->write)(f, buf, bytes);
457 xfs_unlock(f->fc.fs, f->fc.dev, "xdd_write");
458
459 return r;
460 }
461 INLINE long
xdd_read(FILEPTR * f,char * buf,long bytes)462 xdd_read(FILEPTR *f, char *buf, long bytes)
463 {
464 long r;
465
466 xfs_lock(f->fc.fs, f->fc.dev, "xdd_read");
467 r = (f->dev->read)(f, buf, bytes);
468 xfs_unlock(f->fc.fs, f->fc.dev, "xdd_read");
469
470 return r;
471 }
472 INLINE long
xdd_lseek(FILEPTR * f,long where,int whence)473 xdd_lseek(FILEPTR *f, long where, int whence)
474 {
475 long r;
476
477 xfs_lock(f->fc.fs, f->fc.dev, "xdd_lseek");
478 r = (f->dev->lseek)(f, where, whence);
479 xfs_unlock(f->fc.fs, f->fc.dev, "xdd_lseek");
480
481 return r;
482 }
483 INLINE long
xdd_ioctl(FILEPTR * f,int mode,void * buf)484 xdd_ioctl(FILEPTR *f, int mode, void *buf)
485 {
486 long r;
487
488 xfs_lock(f->fc.fs, f->fc.dev, "xdd_ioctl");
489 r = (f->dev->ioctl)(f, mode, buf);
490 xfs_unlock(f->fc.fs, f->fc.dev, "xdd_ioctl");
491
492 return r;
493 }
494 INLINE long
xdd_datime(FILEPTR * f,ushort * timeptr,int rwflag)495 xdd_datime(FILEPTR *f, ushort *timeptr, int rwflag)
496 {
497 long r;
498
499 xfs_lock(f->fc.fs, f->fc.dev, "xdd_datime");
500 r = (f->dev->datime)(f, timeptr, rwflag);
501 xfs_unlock(f->fc.fs, f->fc.dev, "xdd_datime");
502
503 return r;
504 }
505 INLINE long
xdd_close(FILEPTR * f,int pid)506 xdd_close(FILEPTR *f, int pid)
507 {
508 long r;
509
510 xfs_lock(f->fc.fs, f->fc.dev, "xdd_close");
511 r = (f->dev->close)(f, pid);
512 xfs_unlock(f->fc.fs, f->fc.dev, "xdd_close");
513
514 return r;
515 }
516
517
518 # endif /* _filesys_h */
519