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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
diff --git a/libdiskfs/boot-start.c b/libdiskfs/boot-start.c
index 6d9a773..10bd2ee 100644
--- a/libdiskfs/boot-start.c
+++ b/libdiskfs/boot-start.c
@@ -426,17 +426,17 @@ diskfs_execboot_fsys_startup (mach_port_t port, int flags,
/* Called by init to get the privileged ports as described
in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_getpriv (mach_port_t port,
+diskfs_S_fsys_getpriv (control_t init_bootstrap_port,
mach_port_t reply, mach_msg_type_name_t reply_type,
mach_port_t *host_priv, mach_msg_type_name_t *hp_type,
mach_port_t *dev_master, mach_msg_type_name_t *dm_type,
mach_port_t *fstask, mach_msg_type_name_t *task_type)
{
error_t err;
- struct port_info *init_bootstrap_port =
- ports_lookup_port (diskfs_port_bucket, port, diskfs_initboot_class);
- if (!init_bootstrap_port)
+ if (!init_bootstrap_port
+ || init_bootstrap_port->pi.bucket != diskfs_port_bucket
+ || init_bootstrap_port->pi.class != diskfs_initboot_class)
return EOPNOTSUPP;
err = get_privileged_ports (host_priv, dev_master);
@@ -447,20 +447,17 @@ diskfs_S_fsys_getpriv (mach_port_t port,
*task_type = MACH_MSG_TYPE_COPY_SEND;
}
- ports_port_deref (init_bootstrap_port);
-
return err;
}
/* Called by init to give us ports to the procserver and authserver as
described in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_init (mach_port_t port,
+diskfs_S_fsys_init (control_t pt,
mach_port_t reply, mach_msg_type_name_t replytype,
mach_port_t procserver,
mach_port_t authhandle)
{
- struct port_infe *pt;
static int initdone = 0;
mach_port_t host, startup;
error_t err;
@@ -468,10 +465,12 @@ diskfs_S_fsys_init (mach_port_t port,
struct protid *rootpi;
struct peropen *rootpo;
- pt = ports_lookup_port (diskfs_port_bucket, port, diskfs_initboot_class);
- if (!pt)
+
+ if (!pt
+ || pt->pi.bucket != diskfs_port_bucket
+ || pt->pi.class != diskfs_initboot_class)
return EOPNOTSUPP;
- ports_port_deref (pt);
+
if (initdone)
return EOPNOTSUPP;
initdone = 1;
diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index db6a1d8..19859ac 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -121,6 +121,12 @@ struct node
int author_tracks_uid;
};
+/* XXX */
+struct diskfs_control
+{
+ struct port_info pi;
+};
+
/* Possibly lookup types for diskfs_lookup call */
enum lookup_type
{
@@ -795,8 +801,10 @@ error_t diskfs_start_protid (struct peropen *po, struct protid **cred);
void diskfs_finish_protid (struct protid *cred, struct iouser *user);
extern struct protid * diskfs_begin_using_protid_port (file_t port);
+extern struct diskfs_control * diskfs_begin_using_control_port (fsys_t port);
extern void diskfs_end_using_protid_port (struct protid *cred);
+extern void diskfs_end_using_control_port (struct diskfs_control *cred);
#if defined(__USE_EXTERN_INLINES) || defined(DISKFS_DEFINE_EXTERN_INLINE)
@@ -809,6 +817,13 @@ diskfs_begin_using_protid_port (file_t port)
return ports_lookup_port (diskfs_port_bucket, port, diskfs_protid_class);
}
+/* And for the fsys interface. */
+DISKFS_EXTERN_INLINE struct diskfs_control *
+diskfs_begin_using_control_port (fsys_t port)
+{
+ return ports_lookup_port (diskfs_port_bucket, port, diskfs_control_class);
+}
+
/* Called by MiG after server routines have been run; this
balances begin_using_protid_port, and is arranged for the io
and fs interfaces by fsmutations.h. */
@@ -819,6 +834,14 @@ diskfs_end_using_protid_port (struct protid *cred)
ports_port_deref (cred);
}
+/* And for the fsys interface. */
+DISKFS_EXTERN_INLINE void
+diskfs_end_using_control_port (struct diskfs_control *cred)
+{
+ if (cred)
+ ports_port_deref (cred);
+}
+
#endif /* Use extern inlines. */
/* Called when a protid CRED has no more references. (Because references\
diff --git a/libdiskfs/fsmutations.h b/libdiskfs/fsmutations.h
index 5026810..68b6ae3 100644
--- a/libdiskfs/fsmutations.h
+++ b/libdiskfs/fsmutations.h
@@ -23,6 +23,9 @@
#define IO_INTRAN protid_t diskfs_begin_using_protid_port (io_t)
#define IO_DESTRUCTOR diskfs_end_using_protid_port (protid_t)
+#define FSYS_INTRAN control_t diskfs_begin_using_control_port (fsys_t)
+#define FSYS_DESTRUCTOR diskfs_end_using_control_port (control_t)
+
#define FILE_IMPORTS import "priv.h";
#define IO_IMPORTS import "priv.h";
#define FSYS_IMPORTS import "priv.h";
diff --git a/libdiskfs/fsys-getfile.c b/libdiskfs/fsys-getfile.c
index 2fe9495..374033f 100644
--- a/libdiskfs/fsys-getfile.c
+++ b/libdiskfs/fsys-getfile.c
@@ -27,7 +27,7 @@
/* Return in FILE & FILE_TYPE the file in FSYS corresponding to the NFS file
handle HANDLE & HANDLE_LEN. */
error_t
-diskfs_S_fsys_getfile (mach_port_t fsys,
+diskfs_S_fsys_getfile (control_t pt,
mach_port_t reply, mach_msg_type_name_t reply_type,
uid_t *uids, mach_msg_type_number_t nuids,
gid_t *gids, mach_msg_type_number_t ngids,
@@ -41,15 +41,14 @@ diskfs_S_fsys_getfile (mach_port_t fsys,
struct protid *new_cred;
struct peropen *new_po;
struct iouser *user;
- struct port_info *pt =
- ports_lookup_port (diskfs_port_bucket, fsys, diskfs_control_class);
- if (!pt)
+ if (!pt
+ || pt->pi.bucket != diskfs_port_bucket
+ || pt->pi.class != diskfs_control_class)
return EOPNOTSUPP;
if (handle_len != sizeof *f)
{
- ports_port_deref (pt);
return EINVAL;
}
@@ -58,14 +57,12 @@ diskfs_S_fsys_getfile (mach_port_t fsys,
err = diskfs_cached_lookup (f->data.cache_id, &node);
if (err)
{
- ports_port_deref (pt);
return err;
}
if (node->dn_stat.st_gen != f->data.gen)
{
diskfs_nput (node);
- ports_port_deref (pt);
return ESTALE;
}
@@ -73,7 +70,6 @@ diskfs_S_fsys_getfile (mach_port_t fsys,
if (err)
{
diskfs_nput (node);
- ports_port_deref (pt);
return err;
}
@@ -98,7 +94,6 @@ diskfs_S_fsys_getfile (mach_port_t fsys,
iohelp_free_iouser (user);
diskfs_nput (node);
- ports_port_deref (pt);
if (! err)
{
diff --git a/libdiskfs/fsys-getroot.c b/libdiskfs/fsys-getroot.c
index 85e1167..bae2582 100644
--- a/libdiskfs/fsys-getroot.c
+++ b/libdiskfs/fsys-getroot.c
@@ -26,7 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Implement fsys_getroot as described in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_getroot (fsys_t controlport,
+diskfs_S_fsys_getroot (control_t pt,
mach_port_t reply,
mach_msg_type_name_t replytype,
mach_port_t dotdot,
@@ -40,8 +40,6 @@ diskfs_S_fsys_getroot (fsys_t controlport,
file_t *returned_port,
mach_msg_type_name_t *returned_port_poly)
{
- struct port_info *pt = ports_lookup_port (diskfs_port_bucket, controlport,
- diskfs_control_class);
error_t err = 0;
mode_t type;
struct protid *newpi;
@@ -55,7 +53,9 @@ diskfs_S_fsys_getroot (fsys_t controlport,
path: NULL,
};
- if (!pt)
+ if (!pt
+ || pt->pi.bucket != diskfs_port_bucket
+ || pt->pi.class != diskfs_control_class)
return EOPNOTSUPP;
flags &= O_HURD;
@@ -200,8 +200,6 @@ diskfs_S_fsys_getroot (fsys_t controlport,
pthread_mutex_unlock (&diskfs_root_node->lock);
pthread_rwlock_unlock (&diskfs_fsys_lock);
- ports_port_deref (pt);
-
drop_idvec ();
return err;
diff --git a/libdiskfs/fsys-goaway.c b/libdiskfs/fsys-goaway.c
index 2aabce8..b70c0e8 100644
--- a/libdiskfs/fsys-goaway.c
+++ b/libdiskfs/fsys-goaway.c
@@ -25,16 +25,16 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Implement fsys_goaway as described in <hurd/fsys.defs>. */
error_t
-diskfs_S_fsys_goaway (fsys_t controlport,
+diskfs_S_fsys_goaway (control_t pt,
mach_port_t reply,
mach_msg_type_name_t reply_type,
int flags)
{
- struct port_info *pt = ports_lookup_port (diskfs_port_bucket, controlport,
- diskfs_control_class);
error_t ret;
- if (!pt)
+ if (!pt
+ || pt->pi.bucket != diskfs_port_bucket
+ || pt->pi.class != diskfs_control_class)
return EOPNOTSUPP;
/* XXX FSYS_GOAWAY_NOWAIT not implemented. */
@@ -48,6 +48,5 @@ diskfs_S_fsys_goaway (fsys_t controlport,
exit (0);
}
- ports_port_deref (pt);
return ret;
}
diff --git a/libdiskfs/fsys-options.c b/libdiskfs/fsys-options.c
index bb18319..771a9c4 100644
--- a/libdiskfs/fsys-options.c
+++ b/libdiskfs/fsys-options.c
@@ -28,15 +28,17 @@
/* Implement fsys_set_options as described in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_set_options (fsys_t fsys,
+diskfs_S_fsys_set_options (control_t pt,
mach_port_t reply,
mach_msg_type_name_t replytype,
char *data, mach_msg_type_number_t len,
int do_children)
{
error_t err = 0;
- struct port_info *pt =
- ports_lookup_port (diskfs_port_bucket, fsys, diskfs_control_class);
+ if (!pt
+ || pt->pi.bucket != diskfs_port_bucket
+ || pt->pi.class != diskfs_control_class)
+ return EOPNOTSUPP;
error_t
helper (struct node *np)
@@ -60,9 +62,6 @@ diskfs_S_fsys_set_options (fsys_t fsys,
return error;
}
- if (!pt)
- return EOPNOTSUPP;
-
if (do_children)
{
pthread_rwlock_wrlock (&diskfs_fsys_lock);
@@ -77,13 +76,12 @@ diskfs_S_fsys_set_options (fsys_t fsys,
pthread_rwlock_unlock (&diskfs_fsys_lock);
}
- ports_port_deref (pt);
return err;
}
/* Implement fsys_get_options as described in <hurd/fsys.defs>. */
error_t
-diskfs_S_fsys_get_options (fsys_t fsys,
+diskfs_S_fsys_get_options (control_t port,
mach_port_t reply,
mach_msg_type_name_t replytype,
char **data, mach_msg_type_number_t *data_len)
@@ -91,10 +89,10 @@ diskfs_S_fsys_get_options (fsys_t fsys,
char *argz = 0;
size_t argz_len = 0;
error_t err;
- struct port_info *port =
- ports_lookup_port (diskfs_port_bucket, fsys, diskfs_control_class);
- if (!port)
+ if (!port
+ || port->pi.bucket != diskfs_port_bucket
+ || port->pi.class != diskfs_control_class)
return EOPNOTSUPP;
err = argz_add (&argz, &argz_len, program_invocation_name);
@@ -111,6 +109,5 @@ diskfs_S_fsys_get_options (fsys_t fsys,
else
free (argz);
- ports_port_deref (port);
return err;
}
diff --git a/libdiskfs/fsys-syncfs.c b/libdiskfs/fsys-syncfs.c
index beb8881..f2a8cd7 100644
--- a/libdiskfs/fsys-syncfs.c
+++ b/libdiskfs/fsys-syncfs.c
@@ -24,14 +24,17 @@
/* Implement fsys_syncfs as described in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_syncfs (fsys_t controlport,
+diskfs_S_fsys_syncfs (control_t pi,
mach_port_t reply,
mach_msg_type_name_t replytype,
int wait,
int children)
{
- struct port_info *pi = ports_lookup_port (diskfs_port_bucket, controlport,
- diskfs_control_class);
+ if (!pi
+ || pi->pi.bucket != diskfs_port_bucket
+ || pi->pi.class != diskfs_control_class)
+ return EOPNOTSUPP;
+
error_t
helper (struct node *np)
{
@@ -49,9 +52,6 @@ diskfs_S_fsys_syncfs (fsys_t controlport,
return 0;
}
- if (!pi)
- return EOPNOTSUPP;
-
pthread_rwlock_rdlock (&diskfs_fsys_lock);
if (children)
@@ -67,8 +67,5 @@ diskfs_S_fsys_syncfs (fsys_t controlport,
}
pthread_rwlock_unlock (&diskfs_fsys_lock);
-
- ports_port_deref (pi);
-
return 0;
}
diff --git a/libdiskfs/priv.h b/libdiskfs/priv.h
index bd23ab9..b41fa43 100644
--- a/libdiskfs/priv.h
+++ b/libdiskfs/priv.h
@@ -73,6 +73,7 @@ extern int _diskfs_diskdirty;
/* Needed for MiG. */
typedef struct protid *protid_t;
+typedef struct diskfs_control *control_t;
/* Actually read or write a file. The file size must already permit
the requested access. NP is the file to read/write. DATA is a buffer
|