1 /*
2 * UAE - The Un*x Amiga Emulator
3 *
4 * Library of functions to make emulated filesystem as independent as
5 * possible of the host filesystem's capabilities.
6 *
7 * Copyright 1999 Bernd Schmidt
8 */
9
10 #ifndef FSDB_FILE
11 #define FSDB_FILE "_UAEFSDB.___"
12 #endif
13
14 #ifndef FSDB_DIR_SEPARATOR
15 #define FSDB_DIR_SEPARATOR '/'
16 #endif
17
18 /* AmigaOS errors */
19 #define ERROR_NO_FREE_STORE 103
20 #define ERROR_OBJECT_IN_USE 202
21 #define ERROR_OBJECT_EXISTS 203
22 #define ERROR_DIR_NOT_FOUND 204
23 #define ERROR_OBJECT_NOT_AROUND 205
24 #define ERROR_ACTION_NOT_KNOWN 209
25 #define ERROR_INVALID_LOCK 211
26 #define ERROR_OBJECT_WRONG_TYPE 212
27 #define ERROR_DISK_WRITE_PROTECTED 214
28 #define ERROR_DIRECTORY_NOT_EMPTY 216
29 #define ERROR_DEVICE_NOT_MOUNTED 218
30 #define ERROR_SEEK_ERROR 219
31 #define ERROR_DISK_IS_FULL 221
32 #define ERROR_DELETE_PROTECTED 222
33 #define ERROR_WRITE_PROTECTED 223
34 #define ERROR_READ_PROTECTED 224
35 #define ERROR_NO_MORE_ENTRIES 232
36 #define ERROR_NOT_IMPLEMENTED 236
37
38 #define A_FIBF_SCRIPT (1<<6)
39 #define A_FIBF_PURE (1<<5)
40 #define A_FIBF_ARCHIVE (1<<4)
41 #define A_FIBF_READ (1<<3)
42 #define A_FIBF_WRITE (1<<2)
43 #define A_FIBF_EXECUTE (1<<1)
44 #define A_FIBF_DELETE (1<<0)
45
46 /* AmigaOS "keys" */
47 typedef struct a_inode_struct {
48 /* Circular list of recycleable a_inodes. */
49 struct a_inode_struct *next, *prev;
50 /* This a_inode's relatives in the directory structure. */
51 struct a_inode_struct *parent;
52 struct a_inode_struct *child, *sibling;
53 /* AmigaOS name, and host OS name. The host OS name is a full path, the
54 * AmigaOS name is relative to the parent. */
55 char *aname;
56 char *nname;
57 /* AmigaOS file comment, or NULL if file has none. */
58 char *comment;
59 /* AmigaOS protection bits. */
60 int amigaos_mode;
61 /* Unique number for identification. */
62 uae_u32 uniq;
63 /* For a directory that is being ExNext()ed, the number of child ainos
64 which must be kept locked in core. */
65 unsigned long locked_children;
66 /* How many ExNext()s are going on in this directory? */
67 unsigned long exnext_count;
68 /* AmigaOS locking bits. */
69 int shlock;
70 long db_offset;
71 unsigned int dir:1;
72 unsigned int elock:1;
73 /* Nonzero if this came from an entry in our database. */
74 unsigned int has_dbentry:1;
75 /* Nonzero if this will need an entry in our database. */
76 unsigned int needs_dbentry:1;
77 /* This a_inode possibly needs writing back to the database. */
78 unsigned int dirty:1;
79 /* If nonzero, this represents a deleted file; the corresponding
80 * entry in the database must be cleared. */
81 unsigned int deleted:1;
82 } a_inode;
83
84 extern char *nname_begin (char *);
85
86 extern char *build_nname (const char *d, const char *n);
87 extern char *build_aname (const char *d, const char *n);
88
89 /* Filesystem-independent functions. */
90 extern void fsdb_clean_dir (a_inode *);
91 extern char *fsdb_search_dir (const char *dirname, char *rel);
92 extern void fsdb_dir_writeback (a_inode *);
93 extern int fsdb_used_as_nname (a_inode *base, const char *);
94 extern a_inode *fsdb_lookup_aino_aname (a_inode *base, const char *);
95 extern a_inode *fsdb_lookup_aino_nname (a_inode *base, const char *);
96
same_aname(const char * an1,const char * an2)97 STATIC_INLINE int same_aname (const char *an1, const char *an2)
98 {
99 return strcasecmp (an1, an2) == 0;
100 }
101
102 /* Filesystem-dependent functions. */
103 extern int fsdb_name_invalid (const char *n);
104 extern void fsdb_fill_file_attrs (a_inode *);
105 extern int fsdb_set_file_attrs (a_inode *, int);
106 extern int fsdb_mode_representable_p (const a_inode *);
107 extern char *fsdb_create_unique_nname (a_inode *base, const char *);
108