summaryrefslogtreecommitdiff
path: root/debian/patches/fs_unification0004-YYY-Unify-the-short-circuit-translator-logic.patch
blob: 299c639572e0899cedcd1bf3372cce4f78b84905 (plain)
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
From 2d8dcefc3206aed702cd188b77fca36dc592d137 Mon Sep 17 00:00:00 2001
From: Justus Winter <justus@gnupg.org>
Date: Mon, 18 Apr 2016 21:53:28 +0200
Subject: [PATCH hurd 4/5] YYY Unify the short-circuit translator logic

* libdiskfs/dir-lookup.c (short_circuited_callback1): Drop function.
* libdiskfs/trans-callback.c
* libfshelp/fetch-root.c
* libfshelp/fshelp.h
* libnetfs/dir-lookup.c
* libnetfs/trans-callback.c
---
 libdiskfs/dir-lookup.c     | 61 ++++++++++++----------------------------------
 libdiskfs/fsys-getroot.c   | 13 +++++++---
 libdiskfs/trans-callback.c |  4 ++-
 libfshelp/fetch-root.c     | 39 +++++++++++++++++++++++++++++
 libfshelp/fshelp.h         | 16 ++++++++++++
 libnetfs/dir-lookup.c      | 53 +++++++---------------------------------
 libnetfs/fsys-getroot.c    |  7 +++++-
 libnetfs/trans-callback.c  |  4 ++-
 8 files changed, 101 insertions(+), 96 deletions(-)

diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index 72ada0f..8b43e27 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -20,6 +20,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <sys/file.h>
+#include <hurd/fshelp.h>
 #include <hurd/fsys.h>
 #include <hurd/paths.h>
 
@@ -225,43 +226,6 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	  mach_port_t dirport;
 	  struct iouser *user;
 
-	  /* A callback function for short-circuited translators.
-	     S_ISLNK and S_IFSOCK are handled elsewhere.  */
-	  error_t short_circuited_callback1 (void *cookie1, void *cookie2,
-					     uid_t *uid, gid_t *gid,
-					     char **argz, size_t *argz_len)
-	    {
-	      struct node *node = cookie1;
-
-	      switch (node->dn_stat.st_mode & S_IFMT)
-		{
-		case S_IFCHR:
-		case S_IFBLK:
-		  if (asprintf (argz, "%s%c%d%c%d",
-				(S_ISCHR (node->dn_stat.st_mode)
-				 ? _HURD_CHRDEV : _HURD_BLKDEV),
-				0, major (node->dn_stat.st_rdev),
-				0, minor (node->dn_stat.st_rdev)) < 0)
-		    return ENOMEM;
-		  *argz_len = strlen (*argz) + 1;
-		  *argz_len += strlen (*argz + *argz_len) + 1;
-		  *argz_len += strlen (*argz + *argz_len) + 1;
-		  break;
-		case S_IFIFO:
-		  if (asprintf (argz, "%s", _HURD_FIFO) < 0)
-		    return ENOMEM;
-		  *argz_len = strlen (*argz) + 1;
-		  break;
-		default:
-		  return ENOENT;
-		}
-
-	      *uid = node->dn_stat.st_uid;
-	      *gid = node->dn_stat.st_gid;
-
-	      return 0;
-	    }
-
 	  /* Create an unauthenticated port for DNP, and then
 	     unlock it. */
 	  err = iohelp_create_empty_iouser (&user);
@@ -292,14 +256,21 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	  boolean_t register_translator =
 	    np->transbox.active == MACH_PORT_NULL;
 
-	  err = fshelp_fetch_root (&np->transbox, dircred->po,
-				     dirport, dircred->user,
-				     lastcomp ? flags : 0,
-				     ((np->dn_stat.st_mode & S_IPTRANS)
-				      ? _diskfs_translator_callback1
-				      : short_circuited_callback1),
-				     _diskfs_translator_callback2,
-				     do_retry, retry_name, retry_port);
+	  struct fshelp_stat_cookie2 cookie = {
+	    .statp = &np->dn_stat,
+	    .modep = &np->dn_stat.st_mode,
+	    .next = dircred->po,
+	  };
+	  err = fshelp_fetch_root (&np->transbox,
+				   &cookie,
+				   dirport,
+				   dircred->user,
+				   lastcomp ? flags : 0,
+				   ((np->dn_stat.st_mode & S_IPTRANS)
+				    ? _diskfs_translator_callback1
+				    : fshelp_short_circuited_callback1),
+				   _diskfs_translator_callback2,
+				   do_retry, retry_name, retry_port);
 
 	  /* fetch_root copies DIRPORT for success, so we always should
 	     deallocate our send right.  */
diff --git a/libdiskfs/fsys-getroot.c b/libdiskfs/fsys-getroot.c
index 401f103..6f93888 100644
--- a/libdiskfs/fsys-getroot.c
+++ b/libdiskfs/fsys-getroot.c
@@ -21,6 +21,7 @@
 
 #include "priv.h"
 #include "fsys_S.h"
+#include <hurd/fshelp.h>
 #include <hurd/fsys.h>
 #include <fcntl.h>
 
@@ -78,11 +79,15 @@ diskfs_S_fsys_getroot (struct diskfs_control *pt,
        || fshelp_translated (&diskfs_root_node->transbox))
       && !(flags & O_NOTRANS))
     {
+      struct fshelp_stat_cookie2 cookie = {
+	.next = &peropen_context,
+      };
+
       err = fshelp_fetch_root (&diskfs_root_node->transbox,
-				 &peropen_context, dotdot, &user, flags,
-				 _diskfs_translator_callback1,
-				 _diskfs_translator_callback2,
-				 retry, retryname, returned_port);
+			       &cookie, dotdot, &user, flags,
+			       _diskfs_translator_callback1,
+			       _diskfs_translator_callback2,
+			       retry, retryname, returned_port);
       if (err != ENOENT)
 	{
 	  pthread_mutex_unlock (&diskfs_root_node->lock);
diff --git a/libdiskfs/trans-callback.c b/libdiskfs/trans-callback.c
index 283b184..15e8f9a 100644
--- a/libdiskfs/trans-callback.c
+++ b/libdiskfs/trans-callback.c
@@ -20,6 +20,7 @@
 
 #include "priv.h"
 #include <fcntl.h>
+#include <hurd/fshelp.h>
 
 /* Callback function needed for calls to fshelp_fetch_root.  See
    <hurd/fshelp.h> for the interface description.  */
@@ -56,6 +57,7 @@ _diskfs_translator_callback2_fn (void *cookie1, void *cookie2,
 				 mach_msg_type_name_t *underlying_type)
 {
   struct node *np = cookie1;
+  struct fshelp_stat_cookie2 *statc = cookie2;
   struct protid *cred;
   struct peropen *po;
   error_t err;
@@ -66,7 +68,7 @@ _diskfs_translator_callback2_fn (void *cookie1, void *cookie2,
   if (err)
     return err;
 
-  err = diskfs_make_peropen (np, flags, cookie2, &po);
+  err = diskfs_make_peropen (np, flags, statc->next, &po);
   if (! err)
     {
       err = diskfs_create_protid (po, user, &cred);
diff --git a/libfshelp/fetch-root.c b/libfshelp/fetch-root.c
index eb0f315..dfd7477 100644
--- a/libfshelp/fetch-root.c
+++ b/libfshelp/fetch-root.c
@@ -20,6 +20,7 @@
 
 #include <assert.h>
 #include <hurd/fsys.h>
+#include <hurd/paths.h>
 #include <hurd/ports.h>
 #include <stdlib.h>
 #include <string.h>
@@ -197,3 +198,41 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
 
   return err;
 }
+
+/* A callback function for short-circuited translators.  S_ISLNK and
+   S_IFSOCK must be handled elsewhere.  */
+error_t
+fshelp_short_circuited_callback1 (void *cookie1, void *cookie2,
+				  uid_t *uid, gid_t *gid,
+				  char **argz, size_t *argz_len)
+{
+  struct fshelp_stat_cookie2 *statc = cookie2;
+
+  switch (*statc->modep & S_IFMT)
+    {
+    case S_IFCHR:
+    case S_IFBLK:
+      if (asprintf (argz, "%s%c%d%c%d",
+		    (S_ISCHR (*statc->modep)
+		     ? _HURD_CHRDEV : _HURD_BLKDEV),
+		    0, major (statc->statp->st_rdev),
+		    0, minor (statc->statp->st_rdev)) < 0)
+	return ENOMEM;
+      *argz_len = strlen (*argz) + 1;
+      *argz_len += strlen (*argz + *argz_len) + 1;
+      *argz_len += strlen (*argz + *argz_len) + 1;
+      break;
+    case S_IFIFO:
+      if (asprintf (argz, "%s", _HURD_FIFO) < 0)
+	return ENOMEM;
+      *argz_len = strlen (*argz) + 1;
+      break;
+    default:
+      return ENOENT;
+    }
+
+  *uid = statc->statp->st_uid;
+  *gid = statc->statp->st_gid;
+
+  return 0;
+}
diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h
index d04c056..ecd9335 100644
--- a/libfshelp/fshelp.h
+++ b/libfshelp/fshelp.h
@@ -148,6 +148,22 @@ typedef error_t (*fshelp_fetch_root_callback1_t) (void *cookie1, void *cookie2,
 						  uid_t *uid, gid_t *gid,
 						  char **argz, size_t *argz_len);
 
+/* A cookie for fshelp_short_circuited_callback1.  Such a structure
+   must be passed to the call to fshelp_fetch_root.  */
+struct fshelp_stat_cookie2
+{
+  io_statbuf_t *statp;
+  mode_t *modep;
+  void *next;
+};
+
+/* A callback function for short-circuited translators.  S_ISLNK and
+   S_IFSOCK must be handled elsewhere.  */
+error_t fshelp_short_circuited_callback1 (void *cookie1, void *cookie2,
+					  uid_t *uid, gid_t *gid,
+					  char **argz, size_t *argz_len);
+
+
 /* This routine is called by fshelp_fetch_root to fetch more information.
    Return an unauthenticated node for the file itself in *UNDERLYING and
    *UNDERLYING_TYPE (opened with FLAGS).  COOKIE1 is the cookie passed in
diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c
index caeb151..3bcc745 100644
--- a/libnetfs/dir-lookup.c
+++ b/libnetfs/dir-lookup.c
@@ -207,48 +207,6 @@ netfs_S_dir_lookup (struct protid *dircred,
 	{
 	  mach_port_t dirport;
 
-	  /* A callback function for short-circuited translators.
-	     S_ISLNK and S_IFSOCK are handled elsewhere. */
-	  error_t short_circuited_callback1 (void *cookie1, void *cookie2,
-					     uid_t *uid, gid_t *gid,
-					     char **argz, size_t *argz_len)
-	    {
-	      struct node *np = cookie1;
-	      error_t err;
-
-	      err = netfs_validate_stat (np, dircred->user);
-	      if (err)
-		return err;
-
-	      switch (np->nn_translated & S_IFMT)
-		{
-		case S_IFCHR:
-		case S_IFBLK:
-		  if (asprintf (argz, "%s%c%d%c%d",
-				(S_ISCHR (np->nn_translated)
-				 ? _HURD_CHRDEV : _HURD_BLKDEV),
-				0, major (np->nn_stat.st_rdev),
-				0, minor (np->nn_stat.st_rdev)) < 0)
-		    return ENOMEM;
-		  *argz_len = strlen (*argz) + 1;
-		  *argz_len += strlen (*argz + *argz_len) + 1;
-		  *argz_len += strlen (*argz + *argz_len) + 1;
-		  break;
-		case S_IFIFO:
-		  if (asprintf (argz, "%s", _HURD_FIFO) < 0)
-		    return ENOMEM;
-		  *argz_len = strlen (*argz) + 1;
-		  break;
-		default:
-		  return ENOENT;
-		}
-
-	      *uid = np->nn_stat.st_uid;
-	      *gid = np->nn_stat.st_gid;
-
-	      return 0;
-	    }
-
 	  /* Create an unauthenticated port for DNP, and then
 	     unlock it. */
 	  err = iohelp_create_empty_iouser (&user);
@@ -267,6 +225,12 @@ netfs_S_dir_lookup (struct protid *dircred,
 	  boolean_t register_translator = 0;
 	  if (! err)
 	    {
+	      struct fshelp_stat_cookie2 cookie = {
+		.statp = &np->nn_stat,
+		.modep = &np->nn_translated,
+		.next = dircred->po,
+	      };
+
 	      dirport = ports_get_send_right (newpi);
 
 	      /* Check if an active translator is currently running.  If
@@ -275,13 +239,14 @@ netfs_S_dir_lookup (struct protid *dircred,
 		 translators.  */
 	      register_translator = np->transbox.active == MACH_PORT_NULL;
 
-	      err = fshelp_fetch_root (&np->transbox, dircred->po,
+	      err = fshelp_fetch_root (&np->transbox,
+				       &cookie,
 				       dirport,
 				       dircred->user,
 				       lastcomp ? flags : 0,
 				       ((np->nn_translated & S_IPTRANS)
 					? _netfs_translator_callback1
-					: short_circuited_callback1),
+					: fshelp_short_circuited_callback1),
 				       _netfs_translator_callback2,
 				       do_retry, retry_name, retry_port);
 	      /* fetch_root copies DIRPORT for success, so we always should
diff --git a/libnetfs/fsys-getroot.c b/libnetfs/fsys-getroot.c
index 2d02120..d919110 100644
--- a/libnetfs/fsys-getroot.c
+++ b/libnetfs/fsys-getroot.c
@@ -23,6 +23,7 @@
 #include "misc.h"
 #include "callbacks.h"
 #include <fcntl.h>
+#include <hurd/fshelp.h>
 
 error_t
 netfs_S_fsys_getroot (struct netfs_control *pt,
@@ -67,8 +68,12 @@ netfs_S_fsys_getroot (struct netfs_control *pt,
        || fshelp_translated (&netfs_root_node->transbox))
       && !(flags & O_NOTRANS))
     {
+      struct fshelp_stat_cookie2 cookie = {
+	.next = &peropen_context,
+      };
+
       err = fshelp_fetch_root (&netfs_root_node->transbox,
-			       &peropen_context, dotdot, cred, flags,
+			       &cookie, dotdot, cred, flags,
 			       _netfs_translator_callback1,
 			       _netfs_translator_callback2,
 			       do_retry, retry_name, retry_port);
diff --git a/libnetfs/trans-callback.c b/libnetfs/trans-callback.c
index ed21aa2..99f4dc0 100644
--- a/libnetfs/trans-callback.c
+++ b/libnetfs/trans-callback.c
@@ -20,6 +20,7 @@
 
 #include "priv.h"
 #include <fcntl.h>
+#include <hurd/fshelp.h>
 
 /* Callback function needed for calls to fshelp_fetch_root.  See
    <hurd/fshelp.h> for the interface description.  */
@@ -57,6 +58,7 @@ _netfs_translator_callback2_fn (void *cookie1, void *cookie2, int flags,
   error_t err;
   struct protid *cred;
   struct node *node = cookie1;
+  struct fshelp_stat_cookie2 *statc = cookie2;
   struct iouser *user;
   struct peropen *po;
 
@@ -65,7 +67,7 @@ _netfs_translator_callback2_fn (void *cookie1, void *cookie2, int flags,
   if (err)
     return err;
 
-  po = netfs_make_peropen (node, flags, cookie2);
+  po = netfs_make_peropen (node, flags, statc->next);
   if (! po)
     {
       err = errno;
-- 
2.1.4