Rev 4551 | Rev 4566 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4551 | Rev 4555 | ||
|---|---|---|---|
| Line 40... | Line 40... | ||
| 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 <adt/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 | link_t 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 | * |
| Line 90... | Line 90... | ||
| 90 | va_start(ap, altroot); |
90 | va_start(ap, altroot); |
| 91 | index = va_arg(ap, fs_index_t); |
91 | index = va_arg(ap, fs_index_t); |
| 92 | va_end(ap); |
92 | va_end(ap); |
| 93 | } |
93 | } |
| 94 | 94 | ||
| 95 | futex_down(&plb_futex); |
95 | fibril_mutex_lock(&plb_mutex); |
| 96 | 96 | ||
| 97 | plb_entry_t entry; |
97 | plb_entry_t entry; |
| 98 | link_initialize(&entry.plb_link); |
98 | link_initialize(&entry.plb_link); |
| 99 | entry.len = len; |
99 | entry.len = len; |
| 100 | 100 | ||
| Line 117... | Line 117... | ||
| 117 | if (first <= last) { |
117 | if (first <= last) { |
| 118 | if ((last - first) + 1 < len) { |
118 | if ((last - first) + 1 < len) { |
| 119 | /* |
119 | /* |
| 120 | * The buffer cannot absorb the path. |
120 | * The buffer cannot absorb the path. |
| 121 | */ |
121 | */ |
| 122 | futex_up(&plb_futex); |
122 | fibril_mutex_unlock(&plb_mutex); |
| 123 | return ELIMIT; |
123 | return ELIMIT; |
| 124 | } |
124 | } |
| 125 | } else { |
125 | } else { |
| 126 | if (PLB_SIZE - ((first - last) + 1) < len) { |
126 | if (PLB_SIZE - ((first - last) + 1) < len) { |
| 127 | /* |
127 | /* |
| 128 | * The buffer cannot absorb the path. |
128 | * The buffer cannot absorb the path. |
| 129 | */ |
129 | */ |
| 130 | futex_up(&plb_futex); |
130 | fibril_mutex_unlock(&plb_mutex); |
| 131 | return ELIMIT; |
131 | return ELIMIT; |
| 132 | } |
132 | } |
| 133 | } |
133 | } |
| 134 | 134 | ||
| 135 | /* |
135 | /* |
| Line 144... | Line 144... | ||
| 144 | * 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 |
| 145 | * buffer. |
145 | * buffer. |
| 146 | */ |
146 | */ |
| 147 | list_append(&entry.plb_link, &plb_head); |
147 | list_append(&entry.plb_link, &plb_head); |
| 148 | 148 | ||
| 149 | futex_up(&plb_futex); |
149 | fibril_mutex_unlock(&plb_mutex); |
| 150 | 150 | ||
| 151 | /* |
151 | /* |
| 152 | * Copy the path into PLB. |
152 | * Copy the path into PLB. |
| 153 | */ |
153 | */ |
| 154 | size_t cnt1 = min(len, (PLB_SIZE - first) + 1); |
154 | size_t cnt1 = min(len, (PLB_SIZE - first) + 1); |
| Line 166... | Line 166... | ||
| 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 | vfs_release_phone(phone); |
| 170 | 170 | ||
| 171 | futex_down(&plb_futex); |
171 | fibril_mutex_lock(&plb_mutex); |
| 172 | list_remove(&entry.plb_link); |
172 | list_remove(&entry.plb_link); |
| 173 | /* |
173 | /* |
| 174 | * Erasing the path from PLB will come handy for debugging purposes. |
174 | * Erasing the path from PLB will come handy for debugging purposes. |
| 175 | */ |
175 | */ |
| 176 | memset(&plb[first], 0, cnt1); |
176 | memset(&plb[first], 0, cnt1); |
| 177 | memset(plb, 0, cnt2); |
177 | memset(plb, 0, cnt2); |
| 178 | futex_up(&plb_futex); |
178 | fibril_mutex_unlock(&plb_mutex); |
| 179 | 179 | ||
| 180 | if ((rc == EOK) && (result)) { |
180 | if ((rc == EOK) && (result)) { |
| 181 | result->triplet.fs_handle = (fs_handle_t) IPC_GET_ARG1(answer); |
181 | result->triplet.fs_handle = (fs_handle_t) IPC_GET_ARG1(answer); |
| 182 | result->triplet.dev_handle = (dev_handle_t) IPC_GET_ARG2(answer); |
182 | result->triplet.dev_handle = (dev_handle_t) IPC_GET_ARG2(answer); |
| 183 | result->triplet.index = (fs_index_t) IPC_GET_ARG3(answer); |
183 | result->triplet.index = (fs_index_t) IPC_GET_ARG3(answer); |