Rev 4153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4153 | Rev 4581 | ||
---|---|---|---|
Line 26... | Line 26... | ||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup fs |
29 | /** @addtogroup fs |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file vfs_lookup.c |
34 | * @file vfs_lookup.c |
35 | * @brief |
35 | * @brief |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include "vfs.h" |
38 | #include "vfs.h" |
39 | #include <ipc/ipc.h> |
39 | #include <ipc/ipc.h> |
40 | #include <async.h> |
40 | #include <async.h> |
41 | #include <errno.h> |
41 | #include <errno.h> |
42 | #include <string.h> |
42 | #include <string.h> |
43 | #include <stdarg.h> |
43 | #include <stdarg.h> |
44 | #include <bool.h> |
44 | #include <bool.h> |
45 | #include <futex.h> |
45 | #include <fibril_sync.h> |
46 | #include <libadt/list.h> |
46 | #include <adt/list.h> |
47 | #include <vfs/canonify.h> |
47 | #include <vfs/canonify.h> |
48 | 48 | ||
49 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
49 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
50 | 50 | ||
51 | futex_t plb_futex = FUTEX_INITIALIZER; |
51 | FIBRIL_MUTEX_INITIALIZE(plb_mutex); |
52 | link_t plb_head; /**< PLB entry ring buffer. */ |
52 | LIST_INITIALIZE(plb_head); /**< PLB entry ring buffer. */ |
53 | uint8_t *plb = NULL; |
53 | uint8_t *plb = NULL; |
54 | 54 | ||
55 | /** Perform a path lookup. |
55 | /** Perform a path lookup. |
56 | * |
56 | * |
57 | * @param path Path to be resolved; it must be a NULL-terminated |
57 | * @param path Path to be resolved; it must be a NULL-terminated |
58 | * string. |
58 | * string. |
59 | * @param lflag Flags to be used during lookup. |
59 | * @param lflag Flags to be used during lookup. |
60 | * @param result Empty structure where the lookup result will be stored. |
60 | * @param result Empty structure where the lookup result will be stored. |
61 | * Can be NULL. |
61 | * Can be NULL. |
62 | * @param altroot If non-empty, will be used instead of rootfs as the root |
62 | * @param altroot If non-empty, will be used instead of rootfs as the root |
63 | * of the whole VFS tree. |
63 | * of the whole VFS tree. |
- | 64 | * |
|
- | 65 | * @return EOK on success or an error code from errno.h. |
|
64 | * |
66 | * |
65 | * @return EOK on success or an error code from errno.h. |
- | |
66 | */ |
67 | */ |
67 | int vfs_lookup_internal(char *path, int lflag, vfs_lookup_res_t *result, |
68 | int vfs_lookup_internal(char *path, int lflag, vfs_lookup_res_t *result, |
68 | vfs_pair_t *altroot, ...) |
69 | vfs_pair_t *altroot, ...) |
69 | { |
70 | { |
70 | vfs_pair_t *root; |
71 | vfs_pair_t *root; |
Line 89... | Line 90... | ||
89 | va_start(ap, altroot); |
90 | va_start(ap, altroot); |
90 | index = va_arg(ap, fs_index_t); |
91 | index = va_arg(ap, fs_index_t); |
91 | va_end(ap); |
92 | va_end(ap); |
92 | } |
93 | } |
93 | 94 | ||
94 | futex_down(&plb_futex); |
95 | fibril_mutex_lock(&plb_mutex); |
95 | 96 | ||
96 | plb_entry_t entry; |
97 | plb_entry_t entry; |
97 | link_initialize(&entry.plb_link); |
98 | link_initialize(&entry.plb_link); |
98 | entry.len = len; |
99 | entry.len = len; |
99 | 100 | ||
Line 116... | Line 117... | ||
116 | if (first <= last) { |
117 | if (first <= last) { |
117 | if ((last - first) + 1 < len) { |
118 | if ((last - first) + 1 < len) { |
118 | /* |
119 | /* |
119 | * The buffer cannot absorb the path. |
120 | * The buffer cannot absorb the path. |
120 | */ |
121 | */ |
121 | futex_up(&plb_futex); |
122 | fibril_mutex_unlock(&plb_mutex); |
122 | return ELIMIT; |
123 | return ELIMIT; |
123 | } |
124 | } |
124 | } else { |
125 | } else { |
125 | if (PLB_SIZE - ((first - last) + 1) < len) { |
126 | if (PLB_SIZE - ((first - last) + 1) < len) { |
126 | /* |
127 | /* |
127 | * The buffer cannot absorb the path. |
128 | * The buffer cannot absorb the path. |
128 | */ |
129 | */ |
129 | futex_up(&plb_futex); |
130 | fibril_mutex_unlock(&plb_mutex); |
130 | return ELIMIT; |
131 | return ELIMIT; |
131 | } |
132 | } |
132 | } |
133 | } |
133 | 134 | ||
134 | /* |
135 | /* |
Line 143... | Line 144... | ||
143 | * Claim PLB space by inserting the entry into the PLB entry ring |
144 | * Claim PLB space by inserting the entry into the PLB entry ring |
144 | * buffer. |
145 | * buffer. |
145 | */ |
146 | */ |
146 | list_append(&entry.plb_link, &plb_head); |
147 | list_append(&entry.plb_link, &plb_head); |
147 | 148 | ||
148 | futex_up(&plb_futex); |
149 | fibril_mutex_unlock(&plb_mutex); |
149 | 150 | ||
150 | /* |
151 | /* |
151 | * Copy the path into PLB. |
152 | * Copy the path into PLB. |
152 | */ |
153 | */ |
153 | size_t cnt1 = min(len, (PLB_SIZE - first) + 1); |
154 | size_t cnt1 = min(len, (PLB_SIZE - first) + 1); |
Line 160... | Line 161... | ||
160 | int phone = vfs_grab_phone(root->fs_handle); |
161 | int phone = vfs_grab_phone(root->fs_handle); |
161 | aid_t req = async_send_5(phone, VFS_LOOKUP, (ipcarg_t) first, |
162 | aid_t req = async_send_5(phone, VFS_LOOKUP, (ipcarg_t) first, |
162 | (ipcarg_t) (first + len - 1) % PLB_SIZE, |
163 | (ipcarg_t) (first + len - 1) % PLB_SIZE, |
163 | (ipcarg_t) root->dev_handle, (ipcarg_t) lflag, (ipcarg_t) index, |
164 | (ipcarg_t) root->dev_handle, (ipcarg_t) lflag, (ipcarg_t) index, |
164 | &answer); |
165 | &answer); |
165 | vfs_release_phone(phone); |
- | |
166 | 166 | ||
167 | ipcarg_t rc; |
167 | ipcarg_t rc; |
168 | async_wait_for(req, &rc); |
168 | async_wait_for(req, &rc); |
- | 169 | vfs_release_phone(phone); |
|
169 | 170 | ||
170 | futex_down(&plb_futex); |
171 | fibril_mutex_lock(&plb_mutex); |
171 | list_remove(&entry.plb_link); |
172 | list_remove(&entry.plb_link); |
172 | /* |
173 | /* |
173 | * Erasing the path from PLB will come handy for debugging purposes. |
174 | * Erasing the path from PLB will come handy for debugging purposes. |
174 | */ |
175 | */ |
175 | memset(&plb[first], 0, cnt1); |
176 | memset(&plb[first], 0, cnt1); |
176 | memset(plb, 0, cnt2); |
177 | memset(plb, 0, cnt2); |
177 | futex_up(&plb_futex); |
178 | fibril_mutex_unlock(&plb_mutex); |
178 | 179 | ||
179 | if ((rc == EOK) && result) { |
180 | if ((rc == EOK) && (result)) { |
180 | result->triplet.fs_handle = (fs_handle_t) IPC_GET_ARG1(answer); |
181 | result->triplet.fs_handle = (fs_handle_t) IPC_GET_ARG1(answer); |
181 | result->triplet.dev_handle = (dev_handle_t) IPC_GET_ARG2(answer); |
182 | result->triplet.dev_handle = (dev_handle_t) IPC_GET_ARG2(answer); |
182 | result->triplet.index = (fs_index_t) IPC_GET_ARG3(answer); |
183 | result->triplet.index = (fs_index_t) IPC_GET_ARG3(answer); |
183 | result->size = (size_t) IPC_GET_ARG4(answer); |
184 | result->size = (size_t) IPC_GET_ARG4(answer); |
184 | result->lnkcnt = (unsigned) IPC_GET_ARG5(answer); |
185 | result->lnkcnt = (unsigned) IPC_GET_ARG5(answer); |
Line 191... | Line 192... | ||
191 | } |
192 | } |
192 | 193 | ||
193 | return rc; |
194 | return rc; |
194 | } |
195 | } |
195 | 196 | ||
- | 197 | /** Perform a node open operation. |
|
- | 198 | * |
|
- | 199 | * @return EOK on success or an error code from errno.h. |
|
- | 200 | * |
|
- | 201 | */ |
|
- | 202 | int vfs_open_node_internal(vfs_lookup_res_t *result) |
|
- | 203 | { |
|
- | 204 | int phone = vfs_grab_phone(result->triplet.fs_handle); |
|
- | 205 | ||
- | 206 | ipc_call_t answer; |
|
- | 207 | aid_t req = async_send_2(phone, VFS_OPEN_NODE, |
|
- | 208 | (ipcarg_t) result->triplet.dev_handle, |
|
- | 209 | (ipcarg_t) result->triplet.index, &answer); |
|
- | 210 | ||
- | 211 | ||
- | 212 | ipcarg_t rc; |
|
- | 213 | async_wait_for(req, &rc); |
|
- | 214 | vfs_release_phone(phone); |
|
- | 215 | ||
- | 216 | if (rc == EOK) { |
|
- | 217 | result->size = (size_t) IPC_GET_ARG1(answer); |
|
- | 218 | result->lnkcnt = (unsigned) IPC_GET_ARG2(answer); |
|
- | 219 | if (IPC_GET_ARG3(answer) & L_FILE) |
|
- | 220 | result->type = VFS_NODE_FILE; |
|
- | 221 | else if (IPC_GET_ARG3(answer) & L_DIRECTORY) |
|
- | 222 | result->type = VFS_NODE_DIRECTORY; |
|
- | 223 | else |
|
- | 224 | result->type = VFS_NODE_UNKNOWN; |
|
- | 225 | } |
|
- | 226 | ||
- | 227 | return rc; |
|
- | 228 | } |
|
- | 229 | ||
196 | /** |
230 | /** |
197 | * @} |
231 | * @} |
198 | */ |
232 | */ |