Subversion Repositories HelenOS

Rev

Rev 3386 | Rev 4263 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3386 Rev 4153
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_ops.c
34
 * @file vfs_ops.c
35
 * @brief   Operations that VFS offers to its clients.
35
 * @brief Operations that VFS offers to its clients.
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>
Line 53... Line 53...
53
#include <vfs/canonify.h>
53
#include <vfs/canonify.h>
54
 
54
 
55
/* Forward declarations of static functions. */
55
/* Forward declarations of static functions. */
56
static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, size_t);
56
static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, size_t);
57
 
57
 
-
 
58
/** Pending mount structure. */
-
 
59
typedef struct {
-
 
60
    link_t link;
-
 
61
    char *fs_name;            /**< File system name */
-
 
62
    char *mp;                 /**< Mount point */
-
 
63
    ipc_callid_t callid;      /**< Call ID waiting for the mount */
-
 
64
    ipc_callid_t rid;         /**< Request ID */
-
 
65
    dev_handle_t dev_handle;  /**< Device handle */
-
 
66
} pending_req_t;
-
 
67
 
-
 
68
LIST_INITIALIZE(pending_req);
-
 
69
 
58
/**
70
/**
59
 * This rwlock prevents the race between a triplet-to-VFS-node resolution and a
71
 * This rwlock prevents the race between a triplet-to-VFS-node resolution and a
60
 * concurrent VFS operation which modifies the file system namespace.
72
 * concurrent VFS operation which modifies the file system namespace.
61
 */
73
 */
62
RWLOCK_INITIALIZE(namespace_rwlock);
74
RWLOCK_INITIALIZE(namespace_rwlock);
Line 65... Line 77...
65
vfs_pair_t rootfs = {
77
vfs_pair_t rootfs = {
66
    .fs_handle = 0,
78
    .fs_handle = 0,
67
    .dev_handle = 0
79
    .dev_handle = 0
68
};
80
};
69
 
81
 
70
void vfs_mount(ipc_callid_t rid, ipc_call_t *request)
82
static void vfs_mount_internal(ipc_callid_t rid, dev_handle_t dev_handle,
-
 
83
    fs_handle_t fs_handle, char *mp)
71
{
84
{
-
 
85
    /* Resolve the path to the mountpoint. */
72
    dev_handle_t dev_handle;
86
    vfs_lookup_res_t mp_res;
73
    vfs_node_t *mp_node = NULL;
87
    vfs_node_t *mp_node = NULL;
74
    ipc_callid_t callid;
-
 
75
    ipc_call_t data;
-
 
76
    int rc;
88
    int rc;
77
    int phone;
89
    int phone;
78
    size_t size;
-
 
79
 
-
 
80
    /*
-
 
81
     * We expect the library to do the device-name to device-handle
-
 
82
     * translation for us, thus the device handle will arrive as ARG1
-
 
83
     * in the request.
-
 
84
     */
-
 
85
    dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
-
 
86
 
-
 
87
    /*
-
 
88
     * For now, don't make use of ARG2 and ARG3, but they can be used to
-
 
89
     * carry mount options in the future.
-
 
90
     */
-
 
91
 
-
 
92
    /*
-
 
93
     * Now, we expect the client to send us data with the name of the file
-
 
94
     * system.
-
 
95
     */
-
 
96
    if (!ipc_data_write_receive(&callid, &size)) {
-
 
97
        ipc_answer_0(callid, EINVAL);
-
 
98
        ipc_answer_0(rid, EINVAL);
-
 
99
        return;
-
 
100
    }
-
 
101
 
-
 
102
    /*
-
 
103
     * Don't receive more than is necessary for storing a full file system
-
 
104
     * name.
-
 
105
     */
-
 
106
    if (size < 1 || size > FS_NAME_MAXLEN) {
-
 
107
        ipc_answer_0(callid, EINVAL);
-
 
108
        ipc_answer_0(rid, EINVAL);
-
 
109
        return;
-
 
110
    }
-
 
111
 
-
 
112
    /* Deliver the file system name. */
-
 
113
    char fs_name[FS_NAME_MAXLEN + 1];
-
 
114
    (void) ipc_data_write_finalize(callid, fs_name, size);
-
 
115
    fs_name[size] = '\0';
-
 
116
   
-
 
117
    /*
-
 
118
     * Wait for IPC_M_PING so that we can return an error if we don't know
-
 
119
     * fs_name.
-
 
120
     */
-
 
121
    callid = async_get_call(&data);
-
 
122
    if (IPC_GET_METHOD(data) != IPC_M_PING) {
-
 
123
        ipc_answer_0(callid, ENOTSUP);
-
 
124
        ipc_answer_0(rid, ENOTSUP);
-
 
125
        return;
-
 
126
    }
-
 
127
 
-
 
128
    /*
-
 
129
     * Check if we know a file system with the same name as is in fs_name.
-
 
130
     * This will also give us its file system handle.
-
 
131
     */
-
 
132
    fs_handle_t fs_handle = fs_name_to_handle(fs_name, true);
-
 
133
    if (!fs_handle) {
-
 
134
        ipc_answer_0(callid, ENOENT);
-
 
135
        ipc_answer_0(rid, ENOENT);
-
 
136
        return;
-
 
137
    }
-
 
138
 
-
 
139
    /* Acknowledge that we know fs_name. */
-
 
140
    ipc_answer_0(callid, EOK);
-
 
141
 
-
 
142
    /* Now, we want the client to send us the mount point. */
-
 
143
    if (!ipc_data_write_receive(&callid, &size)) {
-
 
144
        ipc_answer_0(callid, EINVAL);
-
 
145
        ipc_answer_0(rid, EINVAL);
-
 
146
        return;
-
 
147
    }
-
 
148
 
-
 
149
    /* Check whether size is reasonable wrt. the mount point. */
-
 
150
    if (size < 1 || size > MAX_PATH_LEN) {
-
 
151
        ipc_answer_0(callid, EINVAL);
-
 
152
        ipc_answer_0(rid, EINVAL);
-
 
153
        return;
-
 
154
    }
-
 
155
    /* Allocate buffer for the mount point data being received. */
-
 
156
    uint8_t *buf;
-
 
157
    buf = malloc(size + 1);
-
 
158
    if (!buf) {
-
 
159
        ipc_answer_0(callid, ENOMEM);
-
 
160
        ipc_answer_0(rid, ENOMEM);
-
 
161
        return;
-
 
162
    }
-
 
163
 
-
 
164
    /* Deliver the mount point. */
-
 
165
    (void) ipc_data_write_finalize(callid, buf, size);
-
 
166
    buf[size] = '\0';
-
 
167
 
-
 
168
    /* Resolve the path to the mountpoint. */
-
 
169
    vfs_lookup_res_t mp_res;
-
 
170
    futex_down(&rootfs_futex);
90
    futex_down(&rootfs_futex);
171
    if (rootfs.fs_handle) {
91
    if (rootfs.fs_handle) {
172
        /* We already have the root FS. */
92
        /* We already have the root FS. */
173
        rwlock_write_lock(&namespace_rwlock);
93
        rwlock_write_lock(&namespace_rwlock);
174
        if ((size == 1) && (buf[0] == '/')) {
94
        if ((strlen(mp) == 1) && (mp[0] == '/')) {
175
            /* Trying to mount root FS over root FS */
95
            /* Trying to mount root FS over root FS */
176
            rwlock_write_unlock(&namespace_rwlock);
96
            rwlock_write_unlock(&namespace_rwlock);
177
            futex_up(&rootfs_futex);
97
            futex_up(&rootfs_futex);
178
            free(buf);
-
 
179
            ipc_answer_0(rid, EBUSY);
98
            ipc_answer_0(rid, EBUSY);
180
            return;
99
            return;
181
        }
100
        }
-
 
101
       
182
        rc = vfs_lookup_internal(buf, L_DIRECTORY, &mp_res, NULL);
102
        rc = vfs_lookup_internal(mp, L_DIRECTORY, &mp_res, NULL);
183
        if (rc != EOK) {
103
        if (rc != EOK) {
184
            /* The lookup failed for some reason. */
104
            /* The lookup failed for some reason. */
185
            rwlock_write_unlock(&namespace_rwlock);
105
            rwlock_write_unlock(&namespace_rwlock);
186
            futex_up(&rootfs_futex);
106
            futex_up(&rootfs_futex);
187
            free(buf);
-
 
188
            ipc_answer_0(rid, rc);
107
            ipc_answer_0(rid, rc);
189
            return;
108
            return;
190
        }
109
        }
-
 
110
       
191
        mp_node = vfs_node_get(&mp_res);
111
        mp_node = vfs_node_get(&mp_res);
192
        if (!mp_node) {
112
        if (!mp_node) {
193
            rwlock_write_unlock(&namespace_rwlock);
113
            rwlock_write_unlock(&namespace_rwlock);
194
            futex_up(&rootfs_futex);
114
            futex_up(&rootfs_futex);
195
            free(buf);
-
 
196
            ipc_answer_0(rid, ENOMEM);
115
            ipc_answer_0(rid, ENOMEM);
197
            return;
116
            return;
198
        }
117
        }
-
 
118
       
199
        /*
119
        /*
200
         * Now we hold a reference to mp_node.
120
         * Now we hold a reference to mp_node.
201
         * It will be dropped upon the corresponding VFS_UNMOUNT.
121
         * It will be dropped upon the corresponding VFS_UNMOUNT.
202
         * This prevents the mount point from being deleted.
122
         * This prevents the mount point from being deleted.
203
         */
123
         */
204
        rwlock_write_unlock(&namespace_rwlock);
124
        rwlock_write_unlock(&namespace_rwlock);
205
    } else {
125
    } else {
206
        /* We still don't have the root file system mounted. */
126
        /* We still don't have the root file system mounted. */
207
        if ((size == 1) && (buf[0] == '/')) {
127
        if ((strlen(mp) == 1) && (mp[0] == '/')) {
208
            vfs_lookup_res_t mr_res;
128
            vfs_lookup_res_t mr_res;
209
            vfs_node_t *mr_node;
129
            vfs_node_t *mr_node;
210
            ipcarg_t rindex;
130
            ipcarg_t rindex;
211
            ipcarg_t rsize;
131
            ipcarg_t rsize;
212
            ipcarg_t rlnkcnt;
132
            ipcarg_t rlnkcnt;
213
       
133
           
214
            /*
134
            /*
215
             * For this simple, but important case,
135
             * For this simple, but important case,
216
             * we are almost done.
136
             * we are almost done.
217
             */
137
             */
218
            free(buf);
-
 
219
           
138
           
220
            /* Tell the mountee that it is being mounted. */
139
            /* Tell the mountee that it is being mounted. */
221
            phone = vfs_grab_phone(fs_handle);
140
            phone = vfs_grab_phone(fs_handle);
222
            rc = async_req_1_3(phone, VFS_MOUNTED,
141
            rc = async_req_1_3(phone, VFS_MOUNTED,
223
                (ipcarg_t) dev_handle, &rindex, &rsize, &rlnkcnt);
142
                (ipcarg_t) dev_handle, &rindex, &rsize, &rlnkcnt);
Line 226... Line 145...
226
            if (rc != EOK) {
145
            if (rc != EOK) {
227
                futex_up(&rootfs_futex);
146
                futex_up(&rootfs_futex);
228
                ipc_answer_0(rid, rc);
147
                ipc_answer_0(rid, rc);
229
                return;
148
                return;
230
            }
149
            }
231
 
150
           
232
            mr_res.triplet.fs_handle = fs_handle;
151
            mr_res.triplet.fs_handle = fs_handle;
233
            mr_res.triplet.dev_handle = dev_handle;
152
            mr_res.triplet.dev_handle = dev_handle;
234
            mr_res.triplet.index = (fs_index_t) rindex;
153
            mr_res.triplet.index = (fs_index_t) rindex;
235
            mr_res.size = (size_t) rsize;
154
            mr_res.size = (size_t) rsize;
236
            mr_res.lnkcnt = (unsigned) rlnkcnt;
155
            mr_res.lnkcnt = (unsigned) rlnkcnt;
-
 
156
            mr_res.type = VFS_NODE_DIRECTORY;
237
 
157
           
238
            rootfs.fs_handle = fs_handle;
158
            rootfs.fs_handle = fs_handle;
239
            rootfs.dev_handle = dev_handle;
159
            rootfs.dev_handle = dev_handle;
240
            futex_up(&rootfs_futex);
160
            futex_up(&rootfs_futex);
241
 
161
           
242
            /* Add reference to the mounted root. */
162
            /* Add reference to the mounted root. */
243
            mr_node = vfs_node_get(&mr_res);
163
            mr_node = vfs_node_get(&mr_res);
244
            assert(mr_node);
164
            assert(mr_node);
245
 
165
           
246
            ipc_answer_0(rid, rc);
166
            ipc_answer_0(rid, rc);
247
            return;
167
            return;
248
        } else {
168
        } else {
249
            /*
169
            /*
250
             * We can't resolve this without the root filesystem
170
             * We can't resolve this without the root filesystem
251
             * being mounted first.
171
             * being mounted first.
252
             */
172
             */
253
            futex_up(&rootfs_futex);
173
            futex_up(&rootfs_futex);
254
            free(buf);
-
 
255
            ipc_answer_0(rid, ENOENT);
174
            ipc_answer_0(rid, ENOENT);
256
            return;
175
            return;
257
        }
176
        }
258
    }
177
    }
259
    futex_up(&rootfs_futex);
178
    futex_up(&rootfs_futex);
260
   
179
   
261
    free(buf);  /* The buffer is not needed anymore. */
-
 
262
   
-
 
263
    /*
180
    /*
264
     * At this point, we have all necessary pieces: file system and device
181
     * At this point, we have all necessary pieces: file system and device
265
     * handles, and we know the mount point VFS node.
182
     * handles, and we know the mount point VFS node.
266
     */
183
     */
267
 
184
   
268
    phone = vfs_grab_phone(mp_res.triplet.fs_handle);
185
    phone = vfs_grab_phone(mp_res.triplet.fs_handle);
269
    rc = async_req_4_0(phone, VFS_MOUNT,
186
    rc = async_req_4_0(phone, VFS_MOUNT,
270
        (ipcarg_t) mp_res.triplet.dev_handle,
187
        (ipcarg_t) mp_res.triplet.dev_handle,
271
        (ipcarg_t) mp_res.triplet.index,
188
        (ipcarg_t) mp_res.triplet.index,
272
        (ipcarg_t) fs_handle,
189
        (ipcarg_t) fs_handle,
273
        (ipcarg_t) dev_handle);
190
        (ipcarg_t) dev_handle);
274
    vfs_release_phone(phone);
191
    vfs_release_phone(phone);
275
 
192
   
276
    if (rc != EOK) {
193
    if (rc != EOK) {
277
        /* Mount failed, drop reference to mp_node. */
194
        /* Mount failed, drop reference to mp_node. */
278
        if (mp_node)
195
        if (mp_node)
279
            vfs_node_put(mp_node);
196
            vfs_node_put(mp_node);
280
    }
197
    }
281
   
198
   
282
    ipc_answer_0(rid, rc);
199
    ipc_answer_0(rid, rc);
283
}
200
}
284
 
201
 
-
 
202
/** Process pending mount requests */
-
 
203
void vfs_process_pending_mount()
-
 
204
{
-
 
205
    link_t *cur;
-
 
206
   
-
 
207
loop:
-
 
208
    for (cur = pending_req.next; cur != &pending_req; cur = cur->next) {
-
 
209
        pending_req_t *pr = list_get_instance(cur, pending_req_t, link);
-
 
210
       
-
 
211
        fs_handle_t fs_handle = fs_name_to_handle(pr->fs_name, true);
-
 
212
        if (!fs_handle)
-
 
213
            continue;
-
 
214
       
-
 
215
        /* Acknowledge that we know fs_name. */
-
 
216
        ipc_answer_0(pr->callid, EOK);
-
 
217
       
-
 
218
        /* Do the mount */
-
 
219
        vfs_mount_internal(pr->rid, pr->dev_handle, fs_handle, pr->mp);
-
 
220
       
-
 
221
        free(pr->fs_name);
-
 
222
        free(pr->mp);
-
 
223
        list_remove(cur);
-
 
224
        free(pr);
-
 
225
        goto loop;
-
 
226
    }
-
 
227
}
-
 
228
 
-
 
229
void vfs_mount(ipc_callid_t rid, ipc_call_t *request)
-
 
230
{
-
 
231
    /*
-
 
232
     * We expect the library to do the device-name to device-handle
-
 
233
     * translation for us, thus the device handle will arrive as ARG1
-
 
234
     * in the request.
-
 
235
     */
-
 
236
    dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
-
 
237
   
-
 
238
    /*
-
 
239
     * Mount flags are passed as ARG2.
-
 
240
     */
-
 
241
    unsigned int flags = (unsigned int) IPC_GET_ARG2(*request);
-
 
242
   
-
 
243
    /*
-
 
244
     * For now, don't make use of ARG3, but it can be used to
-
 
245
     * carry mount options in the future.
-
 
246
     */
-
 
247
   
-
 
248
    /* We want the client to send us the mount point. */
-
 
249
    ipc_callid_t callid;
-
 
250
    size_t size;
-
 
251
    if (!ipc_data_write_receive(&callid, &size)) {
-
 
252
        ipc_answer_0(callid, EINVAL);
-
 
253
        ipc_answer_0(rid, EINVAL);
-
 
254
        return;
-
 
255
    }
-
 
256
   
-
 
257
    /* Check whether size is reasonable wrt. the mount point. */
-
 
258
    if ((size < 1) || (size > MAX_PATH_LEN)) {
-
 
259
        ipc_answer_0(callid, EINVAL);
-
 
260
        ipc_answer_0(rid, EINVAL);
-
 
261
        return;
-
 
262
    }
-
 
263
   
-
 
264
    /* Allocate buffer for the mount point data being received. */
-
 
265
    char *mp = malloc(size + 1);
-
 
266
    if (!mp) {
-
 
267
        ipc_answer_0(callid, ENOMEM);
-
 
268
        ipc_answer_0(rid, ENOMEM);
-
 
269
        return;
-
 
270
    }
-
 
271
   
-
 
272
    /* Deliver the mount point. */
-
 
273
    ipcarg_t retval = ipc_data_write_finalize(callid, mp, size);
-
 
274
    if (retval != EOK) {
-
 
275
        ipc_answer_0(rid, EREFUSED);
-
 
276
        free(mp);
-
 
277
        return;
-
 
278
    }
-
 
279
    mp[size] = '\0';
-
 
280
   
-
 
281
    /*
-
 
282
     * Now, we expect the client to send us data with the name of the file
-
 
283
     * system.
-
 
284
     */
-
 
285
    if (!ipc_data_write_receive(&callid, &size)) {
-
 
286
        ipc_answer_0(callid, EINVAL);
-
 
287
        ipc_answer_0(rid, EINVAL);
-
 
288
        free(mp);
-
 
289
        return;
-
 
290
    }
-
 
291
   
-
 
292
    /*
-
 
293
     * Don't receive more than is necessary for storing a full file system
-
 
294
     * name.
-
 
295
     */
-
 
296
    if ((size < 1) || (size > FS_NAME_MAXLEN)) {
-
 
297
        ipc_answer_0(callid, EINVAL);
-
 
298
        ipc_answer_0(rid, EINVAL);
-
 
299
        free(mp);
-
 
300
        return;
-
 
301
    }
-
 
302
   
-
 
303
    /*
-
 
304
     * Allocate buffer for file system name.
-
 
305
     */
-
 
306
    char *fs_name = (char *) malloc(size + 1);
-
 
307
    if (fs_name == NULL) {
-
 
308
        ipc_answer_0(callid, ENOMEM);
-
 
309
        ipc_answer_0(rid, EREFUSED);
-
 
310
        free(mp);
-
 
311
        return;
-
 
312
    }
-
 
313
   
-
 
314
    /* Deliver the file system name. */
-
 
315
    retval = ipc_data_write_finalize(callid, fs_name, size);
-
 
316
    if (retval != EOK) {
-
 
317
        ipc_answer_0(rid, EREFUSED);
-
 
318
        free(mp);
-
 
319
        free(fs_name);
-
 
320
        return;
-
 
321
    }
-
 
322
    fs_name[size] = '\0';
-
 
323
   
-
 
324
    /*
-
 
325
     * Check if we know a file system with the same name as is in fs_name.
-
 
326
     * This will also give us its file system handle.
-
 
327
     */
-
 
328
    fs_handle_t fs_handle = fs_name_to_handle(fs_name, true);
-
 
329
    if (!fs_handle) {
-
 
330
        if (flags & IPC_FLAG_BLOCKING) {
-
 
331
            /* Blocking mount, add to pending list */
-
 
332
            pending_req_t *pr = (pending_req_t *) malloc(sizeof(pending_req_t));
-
 
333
            if (!pr) {
-
 
334
                ipc_answer_0(callid, ENOMEM);
-
 
335
                ipc_answer_0(rid, ENOMEM);
-
 
336
                free(mp);
-
 
337
                free(fs_name);
-
 
338
                return;
-
 
339
            }
-
 
340
           
-
 
341
            pr->fs_name = fs_name;
-
 
342
            pr->mp = mp;
-
 
343
            pr->callid = callid;
-
 
344
            pr->rid = rid;
-
 
345
            pr->dev_handle = dev_handle;
-
 
346
            list_append(&pr->link, &pending_req);
-
 
347
            return;
-
 
348
        }
-
 
349
       
-
 
350
        ipc_answer_0(callid, ENOENT);
-
 
351
        ipc_answer_0(rid, ENOENT);
-
 
352
        free(mp);
-
 
353
        free(fs_name);
-
 
354
        return;
-
 
355
    }
-
 
356
   
-
 
357
    /* Acknowledge that we know fs_name. */
-
 
358
    ipc_answer_0(callid, EOK);
-
 
359
   
-
 
360
    /* Do the mount */
-
 
361
    vfs_mount_internal(rid, dev_handle, fs_handle, mp);
-
 
362
    free(mp);
-
 
363
    free(fs_name);
-
 
364
}
-
 
365
 
285
void vfs_open(ipc_callid_t rid, ipc_call_t *request)
366
void vfs_open(ipc_callid_t rid, ipc_call_t *request)
286
{
367
{
287
    if (!vfs_files_init()) {
368
    if (!vfs_files_init()) {
288
        ipc_answer_0(rid, ENOMEM);
369
        ipc_answer_0(rid, ENOMEM);
289
        return;
370
        return;
Line 300... Line 381...
300
    int lflag = IPC_GET_ARG1(*request);
381
    int lflag = IPC_GET_ARG1(*request);
301
    int oflag = IPC_GET_ARG2(*request);
382
    int oflag = IPC_GET_ARG2(*request);
302
    int mode = IPC_GET_ARG3(*request);
383
    int mode = IPC_GET_ARG3(*request);
303
    size_t len;
384
    size_t len;
304
 
385
 
-
 
386
    /*
-
 
387
     * Make sure that we are called with exactly one of L_FILE and
-
 
388
     * L_DIRECTORY.
-
 
389
     */
-
 
390
    if ((lflag & (L_FILE | L_DIRECTORY)) == 0 ||
-
 
391
        (lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) {
-
 
392
        ipc_answer_0(rid, EINVAL);
-
 
393
        return;
-
 
394
    }
-
 
395
 
305
    if (oflag & O_CREAT)
396
    if (oflag & O_CREAT)
306
        lflag |= L_CREATE;
397
        lflag |= L_CREATE;
307
    if (oflag & O_EXCL)
398
    if (oflag & O_EXCL)
308
        lflag |= L_EXCLUSIVE;
399
        lflag |= L_EXCLUSIVE;
309
 
400
 
Line 454... Line 545...
454
    /*
545
    /*
455
     * Lock the open file structure so that no other thread can manipulate
546
     * Lock the open file structure so that no other thread can manipulate
456
     * the same open file at a time.
547
     * the same open file at a time.
457
     */
548
     */
458
    futex_down(&file->lock);
549
    futex_down(&file->lock);
459
   
550
 
460
    /*
551
    /*
461
     * Lock the file's node so that no other client can read/write to it at
552
     * Lock the file's node so that no other client can read/write to it at
462
     * the same time.
553
     * the same time.
463
     */
554
     */
464
    if (read)
555
    if (read)
465
        rwlock_read_lock(&file->node->contents_rwlock);
556
        rwlock_read_lock(&file->node->contents_rwlock);
466
    else
557
    else
467
        rwlock_write_lock(&file->node->contents_rwlock);
558
        rwlock_write_lock(&file->node->contents_rwlock);
-
 
559
 
-
 
560
    if (file->node->type == VFS_NODE_DIRECTORY) {
-
 
561
        /*
-
 
562
         * Make sure that no one is modifying the namespace
-
 
563
         * while we are in readdir().
-
 
564
         */
-
 
565
        assert(read);
-
 
566
        rwlock_read_lock(&namespace_rwlock);
-
 
567
    }
468
   
568
   
469
    int fs_phone = vfs_grab_phone(file->node->fs_handle);  
569
    int fs_phone = vfs_grab_phone(file->node->fs_handle);  
470
   
570
   
471
    /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */
571
    /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */
472
    aid_t msg;
572
    aid_t msg;
Line 488... Line 588...
488
   
588
   
489
    /* Wait for reply from the FS server. */
589
    /* Wait for reply from the FS server. */
490
    ipcarg_t rc;
590
    ipcarg_t rc;
491
    async_wait_for(msg, &rc);
591
    async_wait_for(msg, &rc);
492
    size_t bytes = IPC_GET_ARG1(answer);
592
    size_t bytes = IPC_GET_ARG1(answer);
-
 
593
 
-
 
594
    if (file->node->type == VFS_NODE_DIRECTORY)
-
 
595
        rwlock_read_unlock(&namespace_rwlock);
493
   
596
   
494
    /* Unlock the VFS node. */
597
    /* Unlock the VFS node. */
495
    if (read)
598
    if (read)
496
        rwlock_read_unlock(&file->node->contents_rwlock);
599
        rwlock_read_unlock(&file->node->contents_rwlock);
497
    else {
600
    else {