Rev 2404 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2404 | Rev 2435 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 1987,1997, Prentice Hall |
2 | * Copyright (c) 1987,1997, Prentice Hall |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use of the MINIX operating system in source and |
5 | * Redistribution and use of the MINIX operating system in source and |
6 | * binary forms, with or without modification, are permitted provided |
6 | * binary forms, with or without modification, are permitted provided |
7 | * that the following conditions are met: |
7 | * that the following conditions are met: |
8 | 8 | ||
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | 11 | ||
12 | * - Redistributions in binary form must reproduce the above |
12 | * - Redistributions in binary form must reproduce the above |
13 | * copyright notice, this list of conditions and the following |
13 | * copyright notice, this list of conditions and the following |
14 | * disclaimer in the documentation and/or other materials provided |
14 | * disclaimer in the documentation and/or other materials provided |
15 | * with the distribution. |
15 | * with the distribution. |
16 | 16 | ||
17 | * - Neither the name of Prentice Hall nor the names of the software |
17 | * - Neither the name of Prentice Hall nor the names of the software |
18 | * authors or contributors may be used to endorse or promote |
18 | * authors or contributors may be used to endorse or promote |
19 | * products derived from this software without specific prior |
19 | * products derived from this software without specific prior |
20 | * written permission. |
20 | * written permission. |
21 | 21 | ||
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND |
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND |
23 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
23 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
24 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
24 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
26 | * IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE |
26 | * IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE |
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
32 | * 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, |
33 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 | */ |
34 | */ |
35 | - | ||
36 | 35 | ||
37 | /* This file contains the code for performing four system calls relating to |
- | |
38 | * status and directories. |
36 | /** @addtogroup FileSystemImpl |
- | 37 | * @{ |
|
39 | */ |
38 | */ |
40 | 39 | ||
41 | /* Methods: |
40 | /** |
42 | * do_chdir: perform the CHDIR system call |
41 | * @file stadir.c |
43 | * do_stat: perform the STAT system call |
42 | * @brief This file contains the code for performing four system calls relating to |
44 | * do_fstat: perform the FSTAT system call |
43 | * status and directories. |
45 | */ |
44 | */ |
46 | 45 | ||
47 | 46 | ||
48 | #include "fs.h" |
47 | #include "fs.h" |
49 | #include "stat.h" |
48 | #include "stat.h" |
50 | #include "file.h" |
49 | #include "file.h" |
51 | #include "fproc.h" |
50 | #include "fproc.h" |
52 | #include "inode.h" |
51 | #include "inode.h" |
53 | #include "param.h" |
52 | #include "param.h" |
54 | 53 | ||
55 | 54 | ||
56 | static int change(inode_t **iip, char *name_ptr, int len); |
55 | static int change(inode_t **iip, char *name_ptr, int len); |
57 | static int stat_inode(inode_t *rip, filp_t *fil_ptr, char *user_addr); |
56 | static int stat_inode(inode_t *rip, filp_t *fil_ptr, char *user_addr); |
58 | 57 | ||
- | 58 | /** |
|
- | 59 | * Perform the CHDIR system call |
|
- | 60 | */ |
|
59 | int do_chdir() |
61 | int do_chdir() |
60 | { |
62 | { |
61 | 63 | ||
62 | /* Perform the chdir(file_name) system call */ |
64 | /* Perform the chdir(file_name) system call */ |
63 | int r; |
65 | int r; |
64 | 66 | ||
65 | r = change(&fp->fp_workdir, file_name, strlen(file_name)+1); |
67 | r = change(&fp->fp_workdir, file_name, strlen(file_name)+1); |
66 | 68 | ||
67 | return r; |
69 | return r; |
68 | } |
70 | } |
- | 71 | ||
- | 72 | /** |
|
- | 73 | * Execute changing the current directory |
|
69 | 74 | */ |
|
70 | int change(inode_t **iip, char *name_ptr, int len) |
75 | int change(inode_t **iip, char *name_ptr, int len) |
71 | { |
76 | { |
72 | 77 | ||
73 | /* |
78 | /* |
74 | * iip: pointer to the inode pointer for the dir |
79 | * iip: pointer to the inode pointer for the dir |
75 | * name_ptr: pointer to the directory name to change to |
80 | * name_ptr: pointer to the directory name to change to |
76 | * len: length of the directory name string |
81 | * len: length of the directory name string |
77 | */ |
82 | */ |
78 | 83 | ||
79 | /* Do the actual work for chdir() and chroot(). */ |
84 | /* Do the actual work for chdir() and chroot(). */ |
80 | 85 | ||
81 | inode_t *rip; |
86 | inode_t *rip; |
82 | register int r; |
87 | register int r; |
83 | 88 | ||
84 | r = OK; |
89 | r = OK; |
85 | 90 | ||
86 | /* Try to open the new directory. */ |
91 | /* Try to open the new directory. */ |
87 | if (fetch_name(name_ptr, len) != OK) |
92 | if (fetch_name(name_ptr, len) != OK) |
88 | return err_code; |
93 | return err_code; |
89 | 94 | ||
90 | if ((rip = eat_path(user_path)) == NIL_INODE) |
95 | if ((rip = eat_path(user_path)) == NIL_INODE) |
91 | return err_code; |
96 | return err_code; |
92 | 97 | ||
93 | /* It must be a directory and also be searchable. */ |
98 | /* It must be a directory and also be searchable. */ |
94 | if ((rip->i_mode & I_TYPE) != I_DIRECTORY) |
99 | if ((rip->i_mode & I_TYPE) != I_DIRECTORY) |
95 | r = FS_ENOTDIR; |
100 | r = FS_ENOTDIR; |
96 | 101 | ||
97 | /* If error, return inode. */ |
102 | /* If error, return inode. */ |
98 | if (r != OK) { |
103 | if (r != OK) { |
99 | put_inode(rip); |
104 | put_inode(rip); |
100 | return r; |
105 | return r; |
101 | } |
106 | } |
102 | 107 | ||
103 | /* Everything is OK. Make the change. */ |
108 | /* Everything is OK. Make the change. */ |
104 | put_inode(*iip); /* release the old directory */ |
109 | put_inode(*iip); /* release the old directory */ |
105 | *iip = rip; /* acquire the new one */ |
110 | *iip = rip; /* acquire the new one */ |
106 | 111 | ||
107 | return OK; |
112 | return OK; |
108 | } |
113 | } |
109 | 114 | ||
- | 115 | /** |
|
- | 116 | * Perform the STAT system call |
|
- | 117 | */ |
|
110 | int do_stat() |
118 | int do_stat() |
111 | { |
119 | { |
112 | 120 | ||
113 | /* Perform the stat(name, buf) system call. */ |
121 | /* Perform the stat(name, buf) system call. */ |
114 | 122 | ||
115 | register inode_t *rip; |
123 | register inode_t *rip; |
116 | register int r; |
124 | register int r; |
117 | 125 | ||
118 | /* Both stat() and fstat() use the same routine to do the real work. That |
126 | /* Both stat() and fstat() use the same routine to do the real work. That |
119 | * routine expects an inode, so acquire it temporarily. |
127 | * routine expects an inode, so acquire it temporarily. |
120 | */ |
128 | */ |
121 | 129 | ||
122 | if (fetch_name(file_name, strlen(file_name)+1) != OK) |
130 | if (fetch_name(file_name, strlen(file_name)+1) != OK) |
123 | return err_code; |
131 | return err_code; |
124 | 132 | ||
125 | if ((rip = eat_path(user_path)) == NIL_INODE) |
133 | if ((rip = eat_path(user_path)) == NIL_INODE) |
126 | return err_code; |
134 | return err_code; |
127 | 135 | ||
128 | r = stat_inode(rip, NIL_FILP, fp->buffer); /* actually do the work.*/ |
136 | r = stat_inode(rip, NIL_FILP, fp->buffer); /* actually do the work.*/ |
129 | put_inode(rip); /* release the inode */ |
137 | put_inode(rip); /* release the inode */ |
130 | 138 | ||
131 | return r; |
139 | return r; |
132 | } |
140 | } |
133 | 141 | ||
- | 142 | /** |
|
- | 143 | * Perform the FSTAT system call |
|
- | 144 | */ |
|
134 | int do_fstat() |
145 | int do_fstat() |
135 | { |
146 | { |
136 | 147 | ||
137 | /* Perform the fstat(fd, buf) system call. */ |
148 | /* Perform the fstat(fd, buf) system call. */ |
138 | 149 | ||
139 | register filp_t *rfilp; |
150 | register filp_t *rfilp; |
140 | 151 | ||
141 | 152 | ||
142 | /* Is the file descriptor valid? */ |
153 | /* Is the file descriptor valid? */ |
143 | if ((rfilp = get_filp(fd)) == NIL_FILP) |
154 | if ((rfilp = get_filp(fd)) == NIL_FILP) |
144 | return err_code; |
155 | return err_code; |
145 | 156 | ||
146 | if (rfilp->filp_ino == NIL_INODE) |
157 | if (rfilp->filp_ino == NIL_INODE) |
147 | return FS_ENOENT; |
158 | return FS_ENOENT; |
148 | 159 | ||
149 | return(stat_inode(rfilp->filp_ino, NIL_FILP, fp->buffer)); |
160 | return(stat_inode(rfilp->filp_ino, NIL_FILP, fp->buffer)); |
150 | } |
161 | } |
151 | 162 | ||
- | 163 | /** |
|
- | 164 | * Execute the actual STAT operation |
|
- | 165 | */ |
|
152 | int stat_inode(register inode_t *rip, filp_t *fil_ptr, char *user_addr) |
166 | int stat_inode(register inode_t *rip, filp_t *fil_ptr, char *user_addr) |
153 | { |
167 | { |
154 | 168 | ||
155 | /* |
169 | /* |
156 | * rip: pointer to inode to stat |
170 | * rip: pointer to inode to stat |
157 | * fil_ptr: filp pointer, supplied by 'fstat' |
171 | * fil_ptr: filp pointer, supplied by 'fstat' |
158 | * user_addr: user space address where stat buf goes |
172 | * user_addr: user space address where stat buf goes |
159 | */ |
173 | */ |
160 | 174 | ||
161 | /* Common code for stat and fstat system calls. */ |
175 | /* Common code for stat and fstat system calls. */ |
162 | 176 | ||
163 | stat_t statbuf; |
177 | stat_t statbuf; |
164 | 178 | ||
165 | /* Fill in the statbuf struct. */ |
179 | /* Fill in the statbuf struct. */ |
166 | statbuf.st_ino = rip->i_num; |
180 | statbuf.st_ino = rip->i_num; |
167 | statbuf.st_mode = rip->i_mode; |
181 | statbuf.st_mode = rip->i_mode; |
168 | statbuf.st_nlink = rip->i_nlinks & BYTE; |
182 | statbuf.st_nlink = rip->i_nlinks & BYTE; |
169 | statbuf.st_size = rip->i_size; |
183 | statbuf.st_size = rip->i_size; |
170 | 184 | ||
171 | /* Copy infomations to userspace. */ |
185 | /* Copy infomations to userspace. */ |
172 | memcpy(user_addr, &statbuf, sizeof(statbuf)); |
186 | memcpy(user_addr, &statbuf, sizeof(statbuf)); |
173 | 187 | ||
174 | return OK; |
188 | return OK; |
175 | } |
189 | } |
176 | 190 | ||
- | 191 | ||
- | 192 | /** |
|
- | 193 | * } |
|
- | 194 | */ |
|
- | 195 | ||
177 | 196 |