Rev 4425 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4425 | Rev 4564 | ||
---|---|---|---|
Line 48... | Line 48... | ||
48 | #include <bool.h> |
48 | #include <bool.h> |
49 | #include <errno.h> |
49 | #include <errno.h> |
50 | #include <async.h> |
50 | #include <async.h> |
51 | #include <align.h> |
51 | #include <align.h> |
52 | #include <async.h> |
52 | #include <async.h> |
53 | #include <futex.h> |
53 | #include <fibril_sync.h> |
54 | #include <stdio.h> |
54 | #include <stdio.h> |
55 | #include <devmap.h> |
55 | #include <devmap.h> |
56 | #include <ipc/bd.h> |
56 | #include <ipc/bd.h> |
57 | 57 | ||
58 | #define NAME "rd" |
58 | #define NAME "rd" |
Line 61... | Line 61... | ||
61 | static void *rd_addr; |
61 | static void *rd_addr; |
62 | /** Size of the ramdisk. */ |
62 | /** Size of the ramdisk. */ |
63 | static size_t rd_size; |
63 | static size_t rd_size; |
64 | 64 | ||
65 | /** |
65 | /** |
66 | * This futex protects the ramdisk's data. |
66 | * This rwlock protects the ramdisk's data. |
67 | * If we were to serve multiple requests (read + write or several writes) |
67 | * If we were to serve multiple requests (read + write or several writes) |
68 | * concurrently (i.e. from two or more threads), each read and write needs to be |
68 | * concurrently (i.e. from two or more threads), each read and write needs to be |
69 | * protected by this futex. |
69 | * protected by this rwlock. |
70 | */ |
70 | */ |
71 | atomic_t rd_futex = FUTEX_INITIALIZER; |
71 | fibril_rwlock_t rd_lock; |
72 | 72 | ||
73 | /** Handle one connection to ramdisk. |
73 | /** Handle one connection to ramdisk. |
74 | * |
74 | * |
75 | * @param iid Hash of the request that opened the connection. |
75 | * @param iid Hash of the request that opened the connection. |
76 | * @param icall Call data of the request that opened the connection. |
76 | * @param icall Call data of the request that opened the connection. |
Line 137... | Line 137... | ||
137 | * Reading past the end of the device. |
137 | * Reading past the end of the device. |
138 | */ |
138 | */ |
139 | retval = ELIMIT; |
139 | retval = ELIMIT; |
140 | break; |
140 | break; |
141 | } |
141 | } |
142 | futex_down(&rd_futex); |
142 | fibril_rwlock_read_lock(&rd_lock); |
143 | memcpy(fs_va, rd_addr + offset * block_size, block_size); |
143 | memcpy(fs_va, rd_addr + offset * block_size, block_size); |
144 | futex_up(&rd_futex); |
144 | fibril_rwlock_read_unlock(&rd_lock); |
145 | retval = EOK; |
145 | retval = EOK; |
146 | break; |
146 | break; |
147 | case BD_WRITE_BLOCK: |
147 | case BD_WRITE_BLOCK: |
148 | offset = IPC_GET_ARG1(call); |
148 | offset = IPC_GET_ARG1(call); |
149 | block_size = IPC_GET_ARG2(call); |
149 | block_size = IPC_GET_ARG2(call); |
Line 159... | Line 159... | ||
159 | * Writing past the end of the device. |
159 | * Writing past the end of the device. |
160 | */ |
160 | */ |
161 | retval = ELIMIT; |
161 | retval = ELIMIT; |
162 | break; |
162 | break; |
163 | } |
163 | } |
164 | futex_up(&rd_futex); |
164 | fibril_rwlock_write_lock(&rd_lock); |
165 | memcpy(rd_addr + offset * block_size, fs_va, block_size); |
165 | memcpy(rd_addr + offset * block_size, fs_va, block_size); |
166 | futex_down(&rd_futex); |
166 | fibril_rwlock_write_unlock(&rd_lock); |
167 | retval = EOK; |
167 | retval = EOK; |
168 | break; |
168 | break; |
169 | default: |
169 | default: |
170 | /* |
170 | /* |
171 | * The client doesn't speak the same protocol. |
171 | * The client doesn't speak the same protocol. |
Line 214... | Line 214... | ||
214 | if (devmap_device_register("initrd", &dev_handle) != EOK) { |
214 | if (devmap_device_register("initrd", &dev_handle) != EOK) { |
215 | devmap_hangup_phone(DEVMAP_DRIVER); |
215 | devmap_hangup_phone(DEVMAP_DRIVER); |
216 | printf(NAME ": Unable to register device\n"); |
216 | printf(NAME ": Unable to register device\n"); |
217 | return false; |
217 | return false; |
218 | } |
218 | } |
- | 219 | ||
- | 220 | fibril_rwlock_initialize(&rd_lock); |
|
219 | 221 | ||
220 | return true; |
222 | return true; |
221 | } |
223 | } |
222 | 224 | ||
223 | int main(int argc, char **argv) |
225 | int main(int argc, char **argv) |