Rev 2404 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2404 | Rev 2435 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | /* This file contains the procedures that look up path names in the directory |
- | |
2 | * system and determine the inode number that goes with a given path name. |
- | |
3 | */ |
- | |
4 | /* |
1 | /* |
5 | * Copyright (c) 1987,1997, Prentice Hall |
2 | * Copyright (c) 1987,1997, Prentice Hall |
6 | * All rights reserved. |
3 | * All rights reserved. |
7 | * |
4 | * |
8 | * Redistribution and use of the MINIX operating system in source and |
5 | * Redistribution and use of the MINIX operating system in source and |
Line 33... | Line 30... | ||
33 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
34 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
35 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
36 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
37 | */ |
34 | */ |
38 | 35 | ||
- | 36 | /** @addtogroup FileSystemImpl |
|
- | 37 | * @{ |
|
- | 38 | */ |
|
39 | 39 | ||
- | 40 | /** |
|
40 | /* Methods: |
41 | * @file path.c |
41 | * eat_path: the 'main' routine of the path-to-inode conversion mechanism |
42 | * @brief This file contains the procedures that look up path names in the directory |
42 | * last_dir: find the final directory on a given path |
43 | * system and determine the inode number that goes with a given path name. |
43 | * advance: parse one component of a path name |
- | |
44 | * search_dir: search a directory for a string and return its inode number |
- | |
45 | * search_dir_ex: used for extended versions |
- | |
46 | */ |
44 | */ |
47 | 45 | ||
48 | 46 | ||
49 | #include <string.h> |
47 | #include <string.h> |
50 | #include "fs.h" |
48 | #include "fs.h" |
51 | #include "block.h" |
49 | #include "block.h" |
Line 55... | Line 53... | ||
55 | #include "super.h" |
53 | #include "super.h" |
56 | 54 | ||
57 | 55 | ||
58 | static char *get_name(char *old_name, char *string, int string_length); |
56 | static char *get_name(char *old_name, char *string, int string_length); |
59 | 57 | ||
- | 58 | /** |
|
- | 59 | * The 'main' routine of the path-to-inode conversion mechanism |
|
- | 60 | */ |
|
60 | inode_t *eat_path(char *path) |
61 | inode_t *eat_path(char *path) |
61 | { |
62 | { |
62 | 63 | ||
63 | /* Parse the path 'path' and put its inode in the inode table. If not possible, |
64 | /* Parse the path 'path' and put its inode in the inode table. If not possible, |
64 | * return NIL_INODE as function value and an error code in 'err_code'. |
65 | * return NIL_INODE as function value and an error code in 'err_code'. |
Line 90... | Line 91... | ||
90 | rip = advance(ldip, string, name_len); |
91 | rip = advance(ldip, string, name_len); |
91 | put_inode(ldip); |
92 | put_inode(ldip); |
92 | 93 | ||
93 | return rip; |
94 | return rip; |
94 | } |
95 | } |
95 | 96 | ||
- | 97 | /** |
|
- | 98 | * Find the final directory on a given path |
|
- | 99 | */ |
|
96 | inode_t *last_dir(char *path, char *string, int string_length) |
100 | inode_t *last_dir(char *path, char *string, int string_length) |
97 | { |
101 | { |
98 | 102 | ||
99 | /* Given a path, 'path', located in the fs address space, parse it as |
103 | /* Given a path, 'path', located in the fs address space, parse it as |
100 | * far as the last directory, fetch the inode for the last directory into |
104 | * far as the last directory, fetch the inode for the last directory into |
Line 149... | Line 153... | ||
149 | path = new_name; |
153 | path = new_name; |
150 | rip = new_ip; |
154 | rip = new_ip; |
151 | } |
155 | } |
152 | } |
156 | } |
153 | 157 | ||
- | 158 | /** |
|
- | 159 | * Parse one component of a path name |
|
- | 160 | */ |
|
154 | char *get_name(char *old_name, char *string, int string_length) |
161 | char *get_name(char *old_name, char *string, int string_length) |
155 | { |
162 | { |
156 | 163 | ||
157 | /* Given a pointer to a path name in fs space, 'old_name', copy the next |
164 | /* Given a pointer to a path name in fs space, 'old_name', copy the next |
158 | * component to 'string' and pad with zeros. A pointer to that part of |
165 | * component to 'string' and pad with zeros. A pointer to that part of |
Line 192... | Line 199... | ||
192 | return((char *) 0); |
199 | return((char *) 0); |
193 | } |
200 | } |
194 | 201 | ||
195 | return rnp; |
202 | return rnp; |
196 | } |
203 | } |
197 | 204 | ||
- | 205 | /** |
|
- | 206 | * |
|
- | 207 | */ |
|
198 | inode_t *advance(inode_t *dirp, char *string, int string_length) |
208 | inode_t *advance(inode_t *dirp, char *string, int string_length) |
199 | { |
209 | { |
200 | 210 | ||
201 | /* Given a directory and a component of a path, look up the component in |
211 | /* Given a directory and a component of a path, look up the component in |
202 | * the directory, find the inode, open it, and return a pointer to its inode |
212 | * the directory, find the inode, open it, and return a pointer to its inode |
Line 236... | Line 246... | ||
236 | return NIL_INODE; |
246 | return NIL_INODE; |
237 | 247 | ||
238 | return rip; /* return pointer to inode's component */ |
248 | return rip; /* return pointer to inode's component */ |
239 | } |
249 | } |
240 | 250 | ||
- | 251 | /** |
|
- | 252 | * Search a directory for a string and return its inode number |
|
- | 253 | */ |
|
241 | int search_dir(register inode_t *ldir_ptr, char string[NAME_MAX], ino_t *numb, int flag) |
254 | int search_dir(register inode_t *ldir_ptr, char string[NAME_MAX], ino_t *numb, int flag) |
242 | { |
255 | { |
243 | 256 | ||
244 | /* This function searches the directory whose inode is pointed to by 'ldip': |
257 | /* This function searches the directory whose inode is pointed to by 'ldip': |
245 | * if (flag == LOOK_UP) search for 'string' and return inode # in 'numb'; |
258 | * if (flag == LOOK_UP) search for 'string' and return inode # in 'numb'; |
Line 303... | Line 316... | ||
303 | 316 | ||
304 | /* The whole directory has now been searched. */ |
317 | /* The whole directory has now been searched. */ |
305 | return(flag == IS_EMPTY ? OK : FS_ENOENT); |
318 | return(flag == IS_EMPTY ? OK : FS_ENOENT); |
306 | } |
319 | } |
307 | 320 | ||
- | 321 | /** |
|
- | 322 | * Used for extended versions |
|
- | 323 | */ |
|
308 | int search_dir_ex(register inode_t *ldir_ptr, char string[NAME_MAX_EX], ino_t *numb, int flag) |
324 | int search_dir_ex(register inode_t *ldir_ptr, char string[NAME_MAX_EX], ino_t *numb, int flag) |
309 | { |
325 | { |
310 | 326 | ||
311 | /* Same as above, but for extened directory etries - 30 chars in name of file. */ |
327 | /* Same as above, but for extened directory etries - 30 chars in name of file. */ |
312 | 328 | ||
Line 367... | Line 383... | ||
367 | 383 | ||
368 | /* The whole directory has now been searched. */ |
384 | /* The whole directory has now been searched. */ |
369 | return(flag == IS_EMPTY ? OK : FS_ENOENT); |
385 | return(flag == IS_EMPTY ? OK : FS_ENOENT); |
370 | } |
386 | } |
371 | 387 | ||
- | 388 | ||
- | 389 | /** |
|
- | 390 | * } |
|
- | 391 | */ |
|
- | 392 |