Rev 2376 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2376 | Rev 2404 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* This file contains the procedures that look up path names in the directory |
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. |
2 | * system and determine the inode number that goes with a given path name. |
3 | */ |
3 | */ |
- | 4 | /* |
|
- | 5 | * Copyright (c) 1987,1997, Prentice Hall |
|
- | 6 | * All rights reserved. |
|
- | 7 | * |
|
- | 8 | * Redistribution and use of the MINIX operating system in source and |
|
- | 9 | * binary forms, with or without modification, are permitted provided |
|
- | 10 | * that the following conditions are met: |
|
- | 11 | ||
- | 12 | * - Redistributions of source code must retain the above copyright |
|
- | 13 | * notice, this list of conditions and the following disclaimer. |
|
- | 14 | ||
- | 15 | * - Redistributions in binary form must reproduce the above |
|
- | 16 | * copyright notice, this list of conditions and the following |
|
- | 17 | * disclaimer in the documentation and/or other materials provided |
|
- | 18 | * with the distribution. |
|
- | 19 | ||
- | 20 | * - Neither the name of Prentice Hall nor the names of the software |
|
- | 21 | * authors or contributors may be used to endorse or promote |
|
- | 22 | * products derived from this software without specific prior |
|
- | 23 | * written permission. |
|
- | 24 | ||
- | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND |
|
- | 26 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
- | 27 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
- | 28 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
- | 29 | * IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE |
|
- | 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
- | 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
- | 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|
- | 33 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
- | 34 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
- | 35 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
- | 36 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
- | 37 | */ |
|
- | 38 | ||
4 | 39 | ||
5 | /* Methods: |
40 | /* Methods: |
6 | * eat_path: the 'main' routine of the path-to-inode conversion mechanism |
41 | * eat_path: the 'main' routine of the path-to-inode conversion mechanism |
7 | * last_dir: find the final directory on a given path |
42 | * last_dir: find the final directory on a given path |
8 | * advance: parse one component of a path name |
43 | * advance: parse one component of a path name |
Line 39... | Line 74... | ||
39 | return NIL_INODE; |
74 | return NIL_INODE; |
40 | 75 | ||
41 | if (sp->s_extend) { |
76 | if (sp->s_extend) { |
42 | name_len = NAME_MAX_EX; |
77 | name_len = NAME_MAX_EX; |
43 | } |
78 | } |
44 | 79 | ||
45 | /* First open the path down to the final directory. */ |
80 | /* First open the path down to the final directory. */ |
46 | if ( (ldip = last_dir(path, string, name_len)) == NIL_INODE) |
81 | if ( (ldip = last_dir(path, string, name_len)) == NIL_INODE) |
47 | return NIL_INODE; /* we couldn't open final directory */ |
82 | return NIL_INODE; /* we couldn't open final directory */ |
- | 83 | ||
48 | 84 | ||
49 | /* The path consisting only of "/" is a special case, check for it. */ |
85 | /* The path consisting only of "/" is a special case, check for it. */ |
50 | if (string[0] == '\0') |
86 | if (string[0] == '\0') |
51 | return ldip; |
87 | return ldip; |
52 | 88 | ||
53 | /* Get final component of the path. */ |
89 | /* Get final component of the path. */ |
54 | rip = advance(ldip, string, name_len); |
90 | rip = advance(ldip, string, name_len); |
55 | put_inode(ldip); |
91 | put_inode(ldip); |
56 | 92 | ||
57 | return rip; |
93 | return rip; |
58 | } |
94 | } |
59 | 95 | ||
60 | inode_t *last_dir(char *path, char *string, int string_length) |
96 | inode_t *last_dir(char *path, char *string, int string_length) |
61 | { |
97 | { |
Line 86... | Line 122... | ||
86 | /* Scan the path component by component. */ |
122 | /* Scan the path component by component. */ |
87 | while (TRUE) { |
123 | while (TRUE) { |
88 | /* Extract one component. */ |
124 | /* Extract one component. */ |
89 | if ( (new_name = get_name(path, string, string_length)) == (char*) 0) { |
125 | if ( (new_name = get_name(path, string, string_length)) == (char*) 0) { |
90 | put_inode(rip); /* bad path in user space */ |
126 | put_inode(rip); /* bad path in user space */ |
- | 127 | ||
91 | return NIL_INODE; |
128 | return NIL_INODE; |
92 | } |
129 | } |
93 | if (*new_name == '\0') |
130 | if (*new_name == '\0') |
94 | { |
131 | { |
95 | if ( (rip->i_mode & I_TYPE) == I_DIRECTORY) |
132 | if ( (rip->i_mode & I_TYPE) == I_DIRECTORY) |
Line 215... | Line 252... | ||
215 | offset_t pos; |
252 | offset_t pos; |
216 | unsigned old_slots; |
253 | unsigned old_slots; |
217 | block_num_t b; |
254 | block_num_t b; |
218 | 255 | ||
219 | /* If 'ldir_ptr' is not a pointer to a dir inode, error. */ |
256 | /* If 'ldir_ptr' is not a pointer to a dir inode, error. */ |
220 | if ((ldir_ptr->i_mode & I_TYPE) != I_DIRECTORY) |
257 | if ((ldir_ptr->i_mode & I_TYPE) != I_DIRECTORY) { |
221 | return FS_ENOTDIR; |
258 | return FS_ENOTDIR; |
222 | 259 | } |
|
223 | r = OK; |
260 | r = OK; |
224 | 261 | ||
225 | /* Step through the directory one block at a time. */ |
262 | /* Step through the directory one block at a time. */ |
226 | old_slots = (unsigned)(ldir_ptr->i_size/DIR_ENTRY_SIZE); |
263 | old_slots = (unsigned)(ldir_ptr->i_size/DIR_ENTRY_SIZE); |
227 | match = 0; /* set when a string match occurs */ |
264 | match = 0; /* set when a string match occurs */ |
Line 242... | Line 279... | ||
242 | if (strcmp(dp->d_name, "." ) != 0 && |
279 | if (strcmp(dp->d_name, "." ) != 0 && |
243 | strcmp(dp->d_name, "..") != 0) |
280 | strcmp(dp->d_name, "..") != 0) |
244 | match = 1; |
281 | match = 1; |
245 | } |
282 | } |
246 | else { |
283 | else { |
247 | if (fs_strncmp(dp->d_name, string, NAME_MAX) == 0) |
284 | if (fs_strncmp(dp->d_name, string, NAME_MAX) == 0) { |
248 | match = 1; |
285 | match = 1; |
- | 286 | } |
|
249 | } |
287 | } |
250 | } |
288 | } |
251 | 289 | ||
252 | if (match) { |
290 | if (match) { |
253 | /* LOOK_UP or DELETE found what it wanted. */ |
291 | /* LOOK_UP or DELETE found what it wanted. */ |
Line 278... | Line 316... | ||
278 | offset_t pos; |
316 | offset_t pos; |
279 | unsigned old_slots; |
317 | unsigned old_slots; |
280 | block_num_t b; |
318 | block_num_t b; |
281 | 319 | ||
282 | /* If 'ldir_ptr' is not a pointer to a dir inode, error. */ |
320 | /* If 'ldir_ptr' is not a pointer to a dir inode, error. */ |
283 | if ( (ldir_ptr->i_mode & I_TYPE) != I_DIRECTORY) |
321 | if ( (ldir_ptr->i_mode & I_TYPE) != I_DIRECTORY) { |
284 | return FS_ENOTDIR; |
322 | return FS_ENOTDIR; |
285 | 323 | } |
|
286 | r = OK; |
324 | r = OK; |
287 | 325 | ||
288 | /* Step through the directory one block at a time. */ |
326 | /* Step through the directory one block at a time. */ |
289 | old_slots = (unsigned)(ldir_ptr->i_size/DIR_ENTRY_SIZE_EX); |
327 | old_slots = (unsigned)(ldir_ptr->i_size/DIR_ENTRY_SIZE_EX); |
290 | match = 0; /* set when a string match occurs */ |
328 | match = 0; /* set when a string match occurs */ |
Line 304... | Line 342... | ||
304 | /* If this test succeeds, dir is not empty. */ |
342 | /* If this test succeeds, dir is not empty. */ |
305 | if (strcmp(dp->d_name, "." ) != 0 && |
343 | if (strcmp(dp->d_name, "." ) != 0 && |
306 | strcmp(dp->d_name, "..") != 0) match = 1; |
344 | strcmp(dp->d_name, "..") != 0) match = 1; |
307 | } |
345 | } |
308 | else { |
346 | else { |
309 | if (fs_strncmp(dp->d_name, string, NAME_MAX_EX) == 0) |
347 | if (fs_strncmp(dp->d_name, string, NAME_MAX_EX) == 0) { |
310 | match = 1; |
348 | match = 1; |
- | 349 | } |
|
- | 350 | ||
311 | } |
351 | } |
312 | } |
352 | } |
313 | 353 | ||
314 | if (match) { |
354 | if (match) { |
315 | /* LOOK_UP or DELETE found what it wanted. */ |
355 | /* LOOK_UP or DELETE found what it wanted. */ |