1 /* Declarations of file name translation functions for the GNU Hurd.
2    Copyright (C) 1995-2021 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #ifndef _HURD_LOOKUP_H
20 #define _HURD_LOOKUP_H	1
21 
22 #include <errno.h>
23 #include <bits/types/error_t.h>
24 #include <hurd/hurd_types.h>
25 
26 /* These functions all take two callback functions as the first two arguments.
27    The first callback function USE_INIT_PORT is called as follows:
28 
29    error_t use_init_port (int which, error_t (*operate) (mach_port_t));
30 
31    WHICH is nonnegative value less than INIT_PORT_MAX, indicating which
32    init port is required.  The callback function should call *OPERATE
33    with a send right to the appropriate init port.  No user reference
34    is consumed; the right will only be used after *OPERATE returns if
35    *OPERATE has added its own user reference.
36 
37    LOOKUP is a function to do the actual filesystem lookup.  It is passed the
38    same arguments that the dir_lookup rpc accepts, and if 0, __dir_lookup is
39    used.
40 
41    The second callback function GET_DTABLE_PORT should behave like `getdport'.
42 
43    All these functions return zero on success or an error code on failure.  */
44 
45 
46 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).  If
47    successful, returns zero and store the port to FILE in *PORT; otherwise
48    returns an error code. */
49 
50 error_t __hurd_file_name_lookup (error_t (*use_init_port)
51 				   (int which,
52 				    error_t (*operate) (mach_port_t)),
53 				 file_t (*get_dtable_port) (int fd),
54 				 error_t (*lookup)
55 				   (file_t dir, const char *name, int flags, mode_t mode,
56 				    retry_type *do_retry, string_t retry_name,
57 				    mach_port_t *result),
58 				 const char *file_name,
59 				 int flags, mode_t mode,
60 				 file_t *result);
61 error_t hurd_file_name_lookup (error_t (*use_init_port)
62 			         (int which,
63 				  error_t (*operate) (mach_port_t)),
64 			       file_t (*get_dtable_port) (int fd),
65 			       error_t (*lookup)
66 				 (file_t dir, const char *name, int flags, mode_t mode,
67 				  retry_type *do_retry, string_t retry_name,
68 				  mach_port_t *result),
69 			       const char *file_name,
70 			       int flags, mode_t mode,
71 			       file_t *result);
72 
73 
74 /* Split FILE into a directory and a name within the directory.  Look up a
75    port for the directory and store it in *DIR; store in *NAME a pointer
76    into FILE where the name within directory begins.  */
77 
78 error_t __hurd_file_name_split (error_t (*use_init_port)
79 				  (int which,
80 				   error_t (*operate) (mach_port_t)),
81 				file_t (*get_dtable_port) (int fd),
82 				error_t (*lookup) (file_t dir, const char *name,
83 						   int flags, mode_t mode,
84 				   retry_type *do_retry, string_t retry_name,
85 				   mach_port_t *result),
86 				const char *file_name,
87 				file_t *dir, char **name);
88 error_t hurd_file_name_split (error_t (*use_init_port)
89 			        (int which,
90 				 error_t (*operate) (mach_port_t)),
91 			      file_t (*get_dtable_port) (int fd),
92 			      error_t (*lookup) (file_t dir, const char *name,
93 						 int flags, mode_t mode,
94 				 retry_type *do_retry, string_t retry_name,
95 				 mach_port_t *result),
96 			      const char *file_name,
97 			      file_t *dir, char **name);
98 
99 /* Split DIRECTORY into a parent directory and a name within the directory.
100    This is the same as hurd_file_name_split, but ignores trailing slashes.  */
101 
102 error_t __hurd_directory_name_split (error_t (*use_init_port)
103 				  (int which,
104 				   error_t (*operate) (mach_port_t)),
105 				file_t (*get_dtable_port) (int fd),
106 				error_t (*lookup) (file_t dir, const char *name,
107 						   int flags, mode_t mode,
108 				   retry_type *do_retry, string_t retry_name,
109 				   mach_port_t *result),
110 				const char *directory_name,
111 				file_t *dir, char **name);
112 error_t hurd_directory_name_split (error_t (*use_init_port)
113 				   (int which,
114 				    error_t (*operate) (mach_port_t)),
115 				   file_t (*get_dtable_port) (int fd),
116 				   error_t (*lookup) (file_t dir, const char *name,
117 						      int flags, mode_t mode,
118 				    retry_type *do_retry, string_t retry_name,
119 				    mach_port_t *result),
120 				   const char *directory_name,
121 				   file_t *dir, char **name);
122 
123 
124 /* Process the values returned by `dir_lookup' et al, and loop doing
125    `dir_lookup' calls until one returns FS_RETRY_NONE.  The arguments
126    should be those just passed to and/or returned from `dir_lookup',
127    `fsys_getroot', or `file_invoke_translator'.  This function consumes the
128    reference in *RESULT even if it returns an error.  */
129 
130 error_t __hurd_file_name_lookup_retry (error_t (*use_init_port)
131 				         (int which,
132 					  error_t (*operate) (mach_port_t)),
133 				       file_t (*get_dtable_port) (int fd),
134 				       error_t (*lookup)
135 				         (file_t dir, const char *name,
136 					  int flags, mode_t mode,
137 					  retry_type *do_retry,
138 					  string_t retry_name,
139 					  mach_port_t *result),
140 				       enum retry_type doretry,
141 				       char retryname[1024],
142 				       int flags, mode_t mode,
143 				       file_t *result);
144 error_t hurd_file_name_lookup_retry (error_t (*use_init_port)
145 				       (int which,
146 					error_t (*operate) (mach_port_t)),
147 				     file_t (*get_dtable_port) (int fd),
148 				     error_t (*lookup)
149 				       (file_t dir, const char *name,
150 					int flags, mode_t mode,
151 					retry_type *do_retry,
152 					string_t retry_name,
153 					mach_port_t *result),
154 				     enum retry_type doretry,
155 				     char retryname[1024],
156 				     int flags, mode_t mode,
157 				     file_t *result);
158 
159 
160 /* If FILE_NAME contains a '/', or PATH is NULL, call FUN with FILE_NAME, and
161    return the result (if PREFIXED_NAME is non-NULL, setting *PREFIXED_NAME to
162    NULL).  Otherwise, call FUN repeatedly with FILE_NAME prefixed with each
163    successive `:' separated element of PATH, returning whenever FUN returns
164    0 (if PREFIXED_NAME is non-NULL, setting *PREFIXED_NAME to the resulting
165    prefixed path).  If FUN never returns 0, return the first non-ENOENT
166    return value, or ENOENT if there is none.  */
167 error_t file_name_path_scan (const char *file_name, const char *path,
168 			     error_t (*fun)(const char *name),
169 			     char **prefixed_name);
170 
171 /* Lookup FILE_NAME and return the node opened with FLAGS & MODE in result
172    (see hurd_file_name_lookup for details), but a simple filename (without
173    any directory prefixes) will be consecutively prefixed with the pathnames
174    in the `:' separated list PATH until one succeeds in a successful lookup.
175    If none succeed, then the first error that wasn't ENOENT is returned, or
176    ENOENT if no other errors were returned.  If PREFIXED_NAME is non-NULL,
177    then if RESULT is looked up directly, *PREFIXED_NAME is set to NULL, and
178    if it is looked up using a prefix from PATH, *PREFIXED_NAME is set to
179    malloced storage containing the prefixed name.  */
180 error_t hurd_file_name_path_lookup (error_t (*use_init_port)
181 				    (int which,
182 				     error_t (*operate) (mach_port_t)),
183 				    file_t (*get_dtable_port) (int fd),
184 				    error_t (*lookup)
185 				      (file_t dir, const char *name,
186 				       int flags, mode_t mode,
187 				       retry_type *do_retry,
188 				       string_t retry_name,
189 				       mach_port_t *result),
190 				    const char *file_name, const char *path,
191 				    int flags, mode_t mode,
192 				    file_t *result, char **prefixed_name);
193 
194 #endif	/* hurd/lookup.h */
195