summaryrefslogtreecommitdiff
path: root/debian/patches/fs_unification0003-libdiskfs-cosmetic-changes.patch
blob: 118b0a3459f8aa900696fc4bbd36bc175fb503e7 (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
From de30f3bac89b10612c4798c598ae88deb6cf4c5c Mon Sep 17 00:00:00 2001
From: Justus Winter <justus@gnupg.org>
Date: Mon, 18 Apr 2016 19:33:03 +0200
Subject: [PATCH hurd 3/5] libdiskfs: cosmetic changes

* libdiskfs/dir-lookup.c (diskfs_S_dir_lookup): Rename identifiers to
be more idiomatic and closer to libnetfs and the interface
specification.  Massage the code so that it aligns closer with the
dir_lookup server function in libnetfs.  It should not change the
behavior.
---
 libdiskfs/dir-lookup.c | 113 +++++++++++++++++++++++++------------------------
 1 file changed, 57 insertions(+), 56 deletions(-)

diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index c50970d..72ada0f 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -27,19 +27,19 @@
 #include "fs_S.h"
 
 /* Implement dir_lookup as described in <hurd/fs.defs>. */
-kern_return_t
+error_t
 diskfs_S_dir_lookup (struct protid *dircred,
-		     char *path,
+		     char *filename,
 		     int flags,
 		     mode_t mode,
-		     enum retry_type *retry,
-		     char *retryname,
-		     file_t *returned_port,
-		     mach_msg_type_name_t *returned_port_poly)
+		     retry_type *do_retry,
+		     char *retry_name,
+		     mach_port_t *retry_port,
+		     mach_msg_type_name_t *retry_port_type)
 {
   struct node *dnp;
   struct node *np;
-  int nsymlink = 0;
+  int nsymlinks = 0;
   char *nextname;
   char *relpath;
   int nextnamelen;
@@ -66,23 +66,23 @@ diskfs_S_dir_lookup (struct protid *dircred,
   excl = (flags & O_EXCL);
 
   /* Skip leading slashes */
-  while (path[0] == '/')
-    path++;
+  while (*filename == '/')
+    filename++;
 
-  /* Preserve the path relative to diruser->po->path.  */
-  relpath = strdup (path);
+  /* Preserve the path relative to dircred->po->path.  */
+  relpath = strdup (filename);
   if (! relpath)
     return ENOMEM;
 
-  /* Keep a pointer to the start of the path for length
+  /* Keep a pointer to the start of the filename for length
      calculations.  */
-  char *path_start = path;
+  char *filename_start = filename;
 
-  *returned_port_poly = MACH_MSG_TYPE_MAKE_SEND;
-  *retry = FS_RETRY_NORMAL;
-  retryname[0] = '\0';
+  *retry_port_type = MACH_MSG_TYPE_MAKE_SEND;
+  *do_retry = FS_RETRY_NORMAL;
+  *retry_name = '\0';
 
-  if (path[0] == '\0')
+  if (*filename == '\0')
     {
       /* Set things up in the state expected by the code from gotit: on. */
       dnp = 0;
@@ -93,9 +93,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
     }
 
   dnp = dircred->po->np;
-
   pthread_mutex_lock (&dnp->lock);
-  np = 0;
 
   diskfs_nref (dnp);		/* acquire a reference for later diskfs_nput */
 
@@ -104,7 +102,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
       assert (!lastcomp);
 
       /* Find the name of the next pathname component */
-      nextname = index (path, '/');
+      nextname = index (filename, '/');
 
       if (nextname)
 	{
@@ -132,10 +130,10 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	{
 	  if (!ds)
 	    ds = alloca (diskfs_dirstat_size);
-	  err = diskfs_lookup (dnp, path, CREATE, &np, ds, dircred);
+	  err = diskfs_lookup (dnp, filename, CREATE, &np, ds, dircred);
 	}
       else
-	err = diskfs_lookup (dnp, path, LOOKUP, &np, 0, dircred);
+	err = diskfs_lookup (dnp, filename, LOOKUP, &np, 0, dircred);
 
       if (lastcomp && create && excl && (!err || err == EAGAIN))
 	err = EEXIST;
@@ -158,13 +156,13 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	      else
 		{
 		  /* Punt the client up to the shadow root parent.  */
-		  *retry = FS_RETRY_REAUTH;
-		  *returned_port = dircred->po->shadow_root_parent;
-		  *returned_port_poly = MACH_MSG_TYPE_COPY_SEND;
+		  *do_retry = FS_RETRY_REAUTH;
+		  *retry_port = dircred->po->shadow_root_parent;
+		  *retry_port_type = MACH_MSG_TYPE_COPY_SEND;
 		  if (lastcomp && mustbedir) /* Trailing slash.  */
-		    strcpy (retryname, "/");
+		    strcpy (retry_name, "/");
 		  else if (!lastcomp)
-		    strcpy (retryname, nextname);
+		    strcpy (retry_name, nextname);
 		  err = 0;
 		  goto out;
 		}
@@ -174,13 +172,13 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	       shadow root, we can get here if its in a directory that was
 	    renamed out from under it...  */
 	    {
-	      *retry = FS_RETRY_REAUTH;
-	      *returned_port = dircred->po->root_parent;
-	      *returned_port_poly = MACH_MSG_TYPE_COPY_SEND;
+	      *do_retry = FS_RETRY_REAUTH;
+	      *retry_port = dircred->po->root_parent;
+	      *retry_port_type = MACH_MSG_TYPE_COPY_SEND;
 	      if (lastcomp && mustbedir) /* Trailing slash.  */
-		strcpy (retryname, "/");
+		strcpy (retry_name, "/");
 	      else if (!lastcomp)
-		strcpy (retryname, nextname);
+		strcpy (retry_name, nextname);
 	      err = 0;
 	      goto out;
 	    }
@@ -200,7 +198,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	    {
 	      mode &= ~(S_IFMT | S_ISPARE | S_ISVTX | S_ITRANS);
 	      mode |= S_IFREG;
-	      err = diskfs_create_node (dnp, path, mode, &np, dircred, ds);
+	      err = diskfs_create_node (dnp, filename, mode, &np, dircred, ds);
 	      if (diskfs_synchronous)
 		{
 		  diskfs_file_update (dnp, 1);
@@ -228,7 +226,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	  struct iouser *user;
 
 	  /* A callback function for short-circuited translators.
-	     Symlink & ifsock are handled elsewhere.  */
+	     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)
@@ -239,17 +237,19 @@ diskfs_S_dir_lookup (struct protid *dircred,
 		{
 		case S_IFCHR:
 		case S_IFBLK:
-		  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));
+		  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:
-		  asprintf (argz, "%s", _HURD_FIFO);
+		  if (asprintf (argz, "%s", _HURD_FIFO) < 0)
+		    return ENOMEM;
 		  *argz_len = strlen (*argz) + 1;
 		  break;
 		default:
@@ -299,7 +299,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 				      ? _diskfs_translator_callback1
 				      : short_circuited_callback1),
 				     _diskfs_translator_callback2,
-				     retry, retryname, returned_port);
+				     do_retry, retry_name, retry_port);
 
 	  /* fetch_root copies DIRPORT for success, so we always should
 	     deallocate our send right.  */
@@ -307,14 +307,14 @@ diskfs_S_dir_lookup (struct protid *dircred,
 
 	  if (err != ENOENT)
 	    {
-	      *returned_port_poly = MACH_MSG_TYPE_MOVE_SEND;
+	      *retry_port_type = MACH_MSG_TYPE_MOVE_SEND;
 	      if (!err)
 		{
-		  char *end = strchr (retryname, '\0');
+		  char *end = strchr (retry_name, '\0');
 		  if (mustbedir)
 		    *end++ = '/'; /* Trailing slash.  */
 		  else if (!lastcomp) {
-		    if (end != retryname)
+		    if (end != retry_name)
 		      *end++ = '/';
 		    strcpy (end, nextname);
 		  }
@@ -333,7 +333,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 		      char *end = nextname;
 		      while (*end != 0)
 			end--;
-		      translator_path[end - path_start] = '\0';
+		      translator_path[end - filename_start] = '\0';
 		    }
 
 		  if (dircred->po->path == NULL || !strcmp (dircred->po->path,"."))
@@ -363,7 +363,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	  err = 0;
 	  if (np != dnp)
 	    {
-	      if (!strcmp (path, ".."))
+	      if (!strcmp (filename, ".."))
 		pthread_mutex_lock (&dnp->lock);
 	      else
 		{
@@ -384,7 +384,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	{
 	  /* Handle symlink interpretation */
 
-	  if (nsymlink++ > diskfs_maxsymlinks)
+	  if (nsymlinks++ > diskfs_maxsymlinks)
 	    {
 	      err = ELOOP;
 	      goto out;
@@ -412,7 +412,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	    goto out;
 
 	  if (np->dn_stat.st_size == 0)	/* symlink to "" */
-	    path = nextname;
+	    filename = nextname;
 	  else
 	    {
 	      if (nextname)
@@ -432,13 +432,13 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	      if (pathbuf[0] == '/')
 		{
 		  /* Punt to the caller.  */
-		  *retry = FS_RETRY_MAGICAL;
-		  *returned_port = MACH_PORT_NULL;
-		  strcpy (retryname, pathbuf);
+		  *do_retry = FS_RETRY_MAGICAL;
+		  *retry_port = MACH_PORT_NULL;
+		  strcpy (retry_name, pathbuf);
 		  goto out;
 		}
 
-	      path = pathbuf;
+	      filename = pathbuf;
 	      mustbedir = 0;
 	    }
 
@@ -448,7 +448,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	  diskfs_nput (np);
 	  np = 0;
 
-	  if (path == 0)	/* symlink to "" was the last component */
+	  if (filename == 0)	/* symlink to "" was the last component */
 	    {
 	      np = dnp;
 	      dnp = 0;
@@ -458,7 +458,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
       else
 	{
 	  /* Handle normal nodes */
-	  path = nextname;
+	  filename = nextname;
 	  if (np == dnp)
 	    diskfs_nrele (dnp);
 	  else
@@ -471,7 +471,8 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	  else
 	    dnp = 0;
 	}
-    } while (path && *path);
+    }
+  while (filename && *filename);
 
   /* At this point, np is the node to return.  If newnode is set, then
      we just created this node.  */
@@ -553,7 +554,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
       if (! newpi->po->path)
 	err = errno;
 
-      *returned_port = ports_get_right (newpi);
+      *retry_port = ports_get_right (newpi);
       ports_port_deref (newpi);
       newpi = 0;
     }
-- 
2.1.4