Rev 3424 | Rev 3536 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3424 | Rev 3425 | ||
---|---|---|---|
Line 57... | Line 57... | ||
57 | futex_t cwd_futex = FUTEX_INITIALIZER; |
57 | futex_t cwd_futex = FUTEX_INITIALIZER; |
58 | DIR *cwd_dir = NULL; |
58 | DIR *cwd_dir = NULL; |
59 | char *cwd_path = NULL; |
59 | char *cwd_path = NULL; |
60 | size_t cwd_len = 0; |
60 | size_t cwd_len = 0; |
61 | 61 | ||
62 | static char *absolutize(const char *path, size_t *retlen) |
62 | char *absolutize(const char *path, size_t *retlen) |
63 | { |
63 | { |
64 | char *ncwd_path; |
64 | char *ncwd_path; |
- | 65 | char *ncwd_path_nc; |
|
65 | 66 | ||
66 | futex_down(&cwd_futex); |
67 | futex_down(&cwd_futex); |
67 | size_t len = strlen(path); |
68 | size_t len = strlen(path); |
68 | if (*path != '/') { |
69 | if (*path != '/') { |
69 | if (!cwd_path) { |
70 | if (!cwd_path) { |
70 | futex_up(&cwd_futex); |
71 | futex_up(&cwd_futex); |
71 | return NULL; |
72 | return NULL; |
72 | } |
73 | } |
73 | ncwd_path = malloc(len + cwd_len + 1); |
74 | ncwd_path_nc = malloc(cwd_len + 1 + len + 1); |
74 | if (!ncwd_path) { |
75 | if (!ncwd_path_nc) { |
75 | futex_up(&cwd_futex); |
76 | futex_up(&cwd_futex); |
76 | return NULL; |
77 | return NULL; |
77 | } |
78 | } |
78 | strcpy(ncwd_path, cwd_path); |
79 | strcpy(ncwd_path_nc, cwd_path); |
79 | ncwd_path[cwd_len] = '/'; |
80 | ncwd_path_nc[cwd_len] = '/'; |
80 | ncwd_path[cwd_len + 1] = '\0'; |
81 | ncwd_path_nc[cwd_len + 1] = '\0'; |
81 | } else { |
82 | } else { |
82 | ncwd_path = malloc(len + 1); |
83 | ncwd_path_nc = malloc(len + 1); |
83 | if (!ncwd_path) { |
84 | if (!ncwd_path_nc) { |
84 | futex_up(&cwd_futex); |
85 | futex_up(&cwd_futex); |
85 | return NULL; |
86 | return NULL; |
86 | } |
87 | } |
87 | ncwd_path[0] = '\0'; |
88 | ncwd_path_nc[0] = '\0'; |
88 | } |
89 | } |
89 | strcat(ncwd_path, path); |
90 | strcat(ncwd_path_nc, path); |
90 | if (!canonify(ncwd_path, retlen)) { |
91 | ncwd_path = canonify(ncwd_path_nc, retlen); |
- | 92 | if (!ncwd_path) { |
|
- | 93 | futex_up(&cwd_futex); |
|
- | 94 | free(ncwd_path_nc); |
|
- | 95 | return NULL; |
|
- | 96 | } |
|
- | 97 | /* |
|
- | 98 | * We need to clone ncwd_path because canonify() works in-place and thus |
|
- | 99 | * the address in ncwd_path need not be the same as ncwd_path_nc, even |
|
- | 100 | * though they both point into the same dynamically allocated buffer. |
|
- | 101 | */ |
|
- | 102 | ncwd_path = strdup(ncwd_path); |
|
- | 103 | free(ncwd_path_nc); |
|
- | 104 | if (!ncwd_path) { |
|
91 | futex_up(&cwd_futex); |
105 | futex_up(&cwd_futex); |
92 | free(ncwd_path); |
- | |
93 | return NULL; |
106 | return NULL; |
94 | } |
107 | } |
95 | futex_up(&cwd_futex); |
108 | futex_up(&cwd_futex); |
96 | return ncwd_path; |
109 | return ncwd_path; |
97 | } |
110 | } |
Line 103... | Line 116... | ||
103 | return vfs_phone; |
116 | return vfs_phone; |
104 | } |
117 | } |
105 | 118 | ||
106 | static int device_get_handle(char *name, dev_handle_t *handle) |
119 | static int device_get_handle(char *name, dev_handle_t *handle) |
107 | { |
120 | { |
108 | int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0); |
121 | int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, |
- | 122 | 0); |
|
109 | if (phone < 0) |
123 | if (phone < 0) |
110 | return phone; |
124 | return phone; |
111 | 125 | ||
112 | ipc_call_t answer; |
126 | ipc_call_t answer; |
113 | aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0, |
127 | aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0, |
Line 169... | Line 183... | ||
169 | async_serialize_end(); |
183 | async_serialize_end(); |
170 | futex_up(&vfs_phone_futex); |
184 | futex_up(&vfs_phone_futex); |
171 | free(mpa); |
185 | free(mpa); |
172 | return (int) rc; |
186 | return (int) rc; |
173 | } |
187 | } |
- | 188 | /* Ask VFS whether it likes fs_name. */ |
|
- | 189 | rc = async_req_0_0(vfs_phone, IPC_M_PING); |
|
- | 190 | if (rc != EOK) { |
|
- | 191 | async_wait_for(req, NULL); |
|
- | 192 | async_serialize_end(); |
|
- | 193 | futex_up(&vfs_phone_futex); |
|
- | 194 | free(mpa); |
|
- | 195 | return (int) rc; |
|
- | 196 | } |
|
174 | rc = ipc_data_write_start(vfs_phone, (void *)mpa, mpa_len); |
197 | rc = ipc_data_write_start(vfs_phone, (void *)mpa, mpa_len); |
175 | if (rc != EOK) { |
198 | if (rc != EOK) { |
176 | async_wait_for(req, NULL); |
199 | async_wait_for(req, NULL); |
177 | async_serialize_end(); |
200 | async_serialize_end(); |
178 | futex_up(&vfs_phone_futex); |
201 | futex_up(&vfs_phone_futex); |
Line 220... | Line 243... | ||
220 | } |
243 | } |
221 | async_wait_for(req, &rc); |
244 | async_wait_for(req, &rc); |
222 | async_serialize_end(); |
245 | async_serialize_end(); |
223 | futex_up(&vfs_phone_futex); |
246 | futex_up(&vfs_phone_futex); |
224 | free(pa); |
247 | free(pa); |
- | 248 | ||
- | 249 | if (rc != EOK) |
|
- | 250 | return (int) rc; |
|
225 | return (int) IPC_GET_ARG1(answer); |
251 | return (int) IPC_GET_ARG1(answer); |
226 | } |
252 | } |
227 | 253 | ||
228 | int open(const char *path, int oflag, ...) |
254 | int open(const char *path, int oflag, ...) |
229 | { |
255 | { |
Line 283... | Line 309... | ||
283 | async_serialize_end(); |
309 | async_serialize_end(); |
284 | futex_up(&vfs_phone_futex); |
310 | futex_up(&vfs_phone_futex); |
285 | if (rc == EOK) |
311 | if (rc == EOK) |
286 | return (ssize_t) IPC_GET_ARG1(answer); |
312 | return (ssize_t) IPC_GET_ARG1(answer); |
287 | else |
313 | else |
288 | return -1; |
314 | return rc; |
289 | } |
315 | } |
290 | 316 | ||
291 | ssize_t write(int fildes, const void *buf, size_t nbyte) |
317 | ssize_t write(int fildes, const void *buf, size_t nbyte) |
292 | { |
318 | { |
293 | int res; |
319 | int res; |