File: dosdir.c

package info (click to toggle)
aranym 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,488 kB
  • sloc: cpp: 178,117; ansic: 170,405; perl: 5,637; sh: 5,547; asm: 2,282; makefile: 1,324; objc: 218
file content (236 lines) | stat: -rw-r--r-- 4,559 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <osbind.h>

#include "bosmeta.h"
#include "list.h"
#include "dosdir.h"

#if 0
#include "nfd.h"
#define TRACE(x) NFD(x)
#define DEBUG(x) NFD(x)
#else
#define TRACE(x)
#define DEBUG(x)
#endif


long __CDECL
sys_dl_opendir (DIR *dirh, LIST *list, int flag)
{
	DEBUG(("dl_opendir: %lx list=%lx\n", dirh, list));
	dirh->list = list;
	dirh->mode = flag;
	dirh->current = (FCOOKIE*)listRewind(dirh->list);
	return 0;
}

long __CDECL
sys_dl_readdir (DIR *dirh, char *buf, int len)
{
	dirh->current = (FCOOKIE *)listNext((LINKABLE*)dirh->current);
	DEBUG(("dl_readdir: %lx list=%lx: len %d, '%s'\n", dirh, dirh->list, len, dirh->current ? dirh->current->name : "ENMFILES"));
	if (!dirh->current)
		return -ENMFILES;

	/* Insert file index if needed */
	if (!dirh->mode) {
		*(long*)buf = (long)dirh->current;
		buf += 4;
		len -= 4;
	}
	if ( len <= 0 )
		return -ERANGE;

	strncpy(buf, dirh->current->name, len-1);
	return 0;
}

long __CDECL
sys_dl_closedir (DIR *dirh)
{
	DEBUG(("dl_closedir: %lx list=%lx\n", dirh, dirh->list));
	dirh->list = NULL;
	dirh->current = NULL;
	return 0;
}

long __CDECL
sys_dl_readlabel (char *buf, int buflen)
{
	strncpy(buf, "nfstderr", buflen-1);
	return 0;
}


long __CDECL
sys_d_free (MetaDOSDir long *buf, int d)
{
#if 1
	return -ENOSYS;
#else
	PROC *p = curproc;
	fcookie *dir = 0;

	d = (int)tolower(pathNameMD[0])-'a';
	dir = &p->p_cwd->root[d];
#endif
}

long __CDECL
sys_d_create (MetaDOSDir const char *path)
{
	return -EACCES;
}

long __CDECL
sys_d_delete (MetaDOSDir const char *path)
{
	return -EACCES;
}


long __CDECL
sys_f_xattr (MetaDOSFile int flag, const char *name, struct xattr *xattr)
{
	FCOOKIE *fc;
	long r = path2cookie (name, NULL, &fc);
	if (r)
	{
		DEBUG(("Fattrib(%s): error %ld", name, r));
		return r;
	}

	return getxattr( fc, xattr);
}

long __CDECL
sys_f_attrib (MetaDOSFile const char *name, int rwflag, int attr)
{
	FCOOKIE *fc;
	long r = path2cookie (name, NULL, &fc);
	if (r)
	{
		DEBUG(("Fattrib(%s): error %ld", name, r));
		return r;
	}

	return fc->attr;
}

long __CDECL
sys_f_delete (MetaDOSFile const char *name)
{
	return -EACCES;
}

long __CDECL
sys_f_rename (MetaDOSFile int junk, const char *old, const char *new)
{
	return -EACCES;
}

/*
 * GEMDOS extension: Dpathconf(name, which)
 *
 * returns information about filesystem-imposed limits; "name" is the name
 * of a file or directory about which the limit information is requested;
 * "which" is the limit requested, as follows:
 *  -1  max. value of "which" allowed
 *  0   internal limit on open files, if any
 *  1   max. number of links to a file  {LINK_MAX}
 *  2   max. path name length       {PATH_MAX}
 *  3   max. file name length       {NAME_MAX}
 *  4   no. of bytes in atomic write to FIFO {PIPE_BUF}
 *  5   file name truncation rules
 *  6   file name case translation rules
 *
 * unlimited values are returned as 0x7fffffffL
 *
 * see also Sysconf() in dos.c
 */
long __CDECL
sys_d_pathconf (MetaDOSDir const char *name, int which)
{
	/* FIXME? now from cookfs */
	switch (which)
	{
		case -1:	return 7;
		case 0:		return 0x7fffffffL;
		case 1:		return 1;
		case 2:		return PATH_MAX;
		case 3:		return PATH_MAX;
		case 4:		return 0;
		case 5:		return 0;
		case 6:		return 0;
		case 7:		return 0x00800000L;
		default:	return -ENOSYS;
	}
}

long __CDECL
sys_d_opendir (MetaDOSDir const char *name, int flag)
{
	DIR *dirh = (DIR *) dirMD;
	FCOOKIE *fc;
	long r = path2cookie( name, NULL, &fc);
	if (r)
	{
		DEBUG(("Dopendir(%s): path2cookie returned %ld", name, r));
		return r;
	}

	r = sys_dl_opendir( dirh, fc->folder, flag);
	if (r)
		return r;

	return (long)dirh;
}

long __CDECL
sys_d_readdir (MetaDOSDir int len, long handle, char *buf)
{
	DIR *dirh = (DIR *) dirMD;
	return sys_dl_readdir( dirh, buf, len);
}

long __CDECL
sys_d_xreaddir (MetaDOSDir int len, long handle, char *buf, struct xattr *xattr, long *xret)
{
	DIR *dirh = (DIR *) dirMD;
	long ret = sys_dl_readdir( dirh, buf, len);
	if ( ret )
		return ret;

	*xret = getxattr( dirh->current, xattr);
	return 0;
}

long __CDECL
sys_d_rewind (MetaDOSDir long handle)
{
	DIR *dirh = (DIR *) dirMD;
	dirh->current = (FCOOKIE *)listRewind(dirh->list);
	return 0;
}

long __CDECL
sys_d_closedir (MetaDOSDir long handle)
{
	return sys_dl_closedir( (DIR*)dirMD);
}

long __CDECL
sys_d_readlabel (MetaDOSDir const char *name, char *buf, int buflen)
{
	return sys_dl_readlabel(buf, buflen);
}

long __CDECL
sys_d_writelabel (MetaDOSDir const char *name, const char *label)
{
	return -ENOSYS;
}