Subversion Repositories HelenOS

Rev

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

Rev 2749 Rev 2752
Line 73... Line 73...
73
    vfs_pair_t altroot = {
73
    vfs_pair_t altroot = {
74
        .fs_handle = fs_handle,
74
        .fs_handle = fs_handle,
75
        .dev_handle = dev_handle,
75
        .dev_handle = dev_handle,
76
    };
76
    };
77
 
77
 
78
    return vfs_lookup_internal("/", strlen("/"), L_DIRECTORY, result,
78
    return vfs_lookup_internal("/", L_DIRECTORY, result, &altroot);
79
        &altroot);
-
 
80
}
79
}
81
 
80
 
82
void vfs_mount(ipc_callid_t rid, ipc_call_t *request)
81
void vfs_mount(ipc_callid_t rid, ipc_call_t *request)
83
{
82
{
84
    int dev_handle;
83
    int dev_handle;
Line 147... Line 146...
147
        ipc_answer_0(rid, EINVAL);
146
        ipc_answer_0(rid, EINVAL);
148
        return;
147
        return;
149
    }
148
    }
150
    /* Allocate buffer for the mount point data being received. */
149
    /* Allocate buffer for the mount point data being received. */
151
    uint8_t *buf;
150
    uint8_t *buf;
152
    buf = malloc(size);
151
    buf = malloc(size + 1);
153
    if (!buf) {
152
    if (!buf) {
154
        ipc_answer_0(callid, ENOMEM);
153
        ipc_answer_0(callid, ENOMEM);
155
        ipc_answer_0(rid, ENOMEM);
154
        ipc_answer_0(rid, ENOMEM);
156
        return;
155
        return;
157
    }
156
    }
158
 
157
 
159
    /* Deliver the mount point. */
158
    /* Deliver the mount point. */
160
    (void) ipc_data_write_finalize(callid, buf, size);
159
    (void) ipc_data_write_finalize(callid, buf, size);
-
 
160
    buf[size] = '\0';
161
 
161
 
162
    /*
162
    /*
163
     * Lookup the root node of the filesystem being mounted.
163
     * Lookup the root node of the filesystem being mounted.
164
     * In this case, we don't need to take the namespace_futex as the root
164
     * In this case, we don't need to take the namespace_futex as the root
165
     * node cannot be removed. However, we do take a reference to it so
165
     * node cannot be removed. However, we do take a reference to it so
Line 184... Line 184...
184
    vfs_lookup_res_t mp_res;
184
    vfs_lookup_res_t mp_res;
185
    futex_down(&rootfs_futex);
185
    futex_down(&rootfs_futex);
186
    if (rootfs.fs_handle) {
186
    if (rootfs.fs_handle) {
187
        /* We already have the root FS. */
187
        /* We already have the root FS. */
188
        rwlock_write_lock(&namespace_rwlock);
188
        rwlock_write_lock(&namespace_rwlock);
189
        rc = vfs_lookup_internal(buf, size, L_DIRECTORY, &mp_res,
189
        rc = vfs_lookup_internal(buf, L_DIRECTORY, &mp_res, NULL);
190
            NULL);
-
 
191
        if (rc != EOK) {
190
        if (rc != EOK) {
192
            /* The lookup failed for some reason. */
191
            /* The lookup failed for some reason. */
193
            rwlock_write_unlock(&namespace_rwlock);
192
            rwlock_write_unlock(&namespace_rwlock);
194
            futex_up(&rootfs_futex);
193
            futex_up(&rootfs_futex);
195
            vfs_node_put(mr_node);  /* failed -> drop reference */
194
            vfs_node_put(mr_node);  /* failed -> drop reference */
Line 312... Line 311...
312
     * Now we are on the verge of accepting the path.
311
     * Now we are on the verge of accepting the path.
313
     *
312
     *
314
     * There is one optimization we could do in the future: copy the path
313
     * There is one optimization we could do in the future: copy the path
315
     * directly into the PLB using some kind of a callback.
314
     * directly into the PLB using some kind of a callback.
316
     */
315
     */
317
    char *path = malloc(len);
316
    char *path = malloc(len + 1);
318
   
317
   
319
    if (!path) {
318
    if (!path) {
320
        ipc_answer_0(callid, ENOMEM);
319
        ipc_answer_0(callid, ENOMEM);
321
        ipc_answer_0(rid, ENOMEM);
320
        ipc_answer_0(rid, ENOMEM);
322
        return;
321
        return;
Line 326... Line 325...
326
    if ((rc = ipc_data_write_finalize(callid, path, len))) {
325
    if ((rc = ipc_data_write_finalize(callid, path, len))) {
327
        ipc_answer_0(rid, rc);
326
        ipc_answer_0(rid, rc);
328
        free(path);
327
        free(path);
329
        return;
328
        return;
330
    }
329
    }
-
 
330
    path[len] = '\0';
331
   
331
   
332
    /*
332
    /*
333
     * Avoid the race condition in which the file can be deleted before we
333
     * Avoid the race condition in which the file can be deleted before we
334
     * find/create-and-lock the VFS node corresponding to the looked-up
334
     * find/create-and-lock the VFS node corresponding to the looked-up
335
     * triplet.
335
     * triplet.
Line 339... Line 339...
339
    else
339
    else
340
        rwlock_read_lock(&namespace_rwlock);
340
        rwlock_read_lock(&namespace_rwlock);
341
 
341
 
342
    /* The path is now populated and we can call vfs_lookup_internal(). */
342
    /* The path is now populated and we can call vfs_lookup_internal(). */
343
    vfs_lookup_res_t lr;
343
    vfs_lookup_res_t lr;
344
    rc = vfs_lookup_internal(path, len, lflag, &lr, NULL);
344
    rc = vfs_lookup_internal(path, lflag, &lr, NULL);
345
    if (rc) {
345
    if (rc) {
346
        if (lflag & L_CREATE)
346
        if (lflag & L_CREATE)
347
            rwlock_write_unlock(&namespace_rwlock);
347
            rwlock_write_unlock(&namespace_rwlock);
348
        else
348
        else
349
            rwlock_read_unlock(&namespace_rwlock);
349
            rwlock_read_unlock(&namespace_rwlock);
Line 634... Line 634...
634
     * Now we are on the verge of accepting the path.
634
     * Now we are on the verge of accepting the path.
635
     *
635
     *
636
     * There is one optimization we could do in the future: copy the path
636
     * There is one optimization we could do in the future: copy the path
637
     * directly into the PLB using some kind of a callback.
637
     * directly into the PLB using some kind of a callback.
638
     */
638
     */
639
    char *path = malloc(len);
639
    char *path = malloc(len + 1);
640
   
640
   
641
    if (!path) {
641
    if (!path) {
642
        ipc_answer_0(callid, ENOMEM);
642
        ipc_answer_0(callid, ENOMEM);
643
        ipc_answer_0(rid, ENOMEM);
643
        ipc_answer_0(rid, ENOMEM);
644
        return;
644
        return;
Line 648... Line 648...
648
    if ((rc = ipc_data_write_finalize(callid, path, len))) {
648
    if ((rc = ipc_data_write_finalize(callid, path, len))) {
649
        ipc_answer_0(rid, rc);
649
        ipc_answer_0(rid, rc);
650
        free(path);
650
        free(path);
651
        return;
651
        return;
652
    }
652
    }
-
 
653
    path[len] = '\0';
653
   
654
   
654
    rwlock_write_lock(&namespace_rwlock);
655
    rwlock_write_lock(&namespace_rwlock);
655
    int lflag = L_DIRECTORY | L_CREATE | L_EXCLUSIVE;
656
    int lflag = L_DIRECTORY | L_CREATE | L_EXCLUSIVE;
656
    rc = vfs_lookup_internal(path, len, lflag, NULL, NULL);
657
    rc = vfs_lookup_internal(path, lflag, NULL, NULL);
657
    rwlock_write_unlock(&namespace_rwlock);
658
    rwlock_write_unlock(&namespace_rwlock);
658
    free(path);
659
    free(path);
659
    ipc_answer_0(rid, rc);
660
    ipc_answer_0(rid, rc);
660
}
661
}
661
 
662
 
Line 676... Line 677...
676
     * Now we are on the verge of accepting the path.
677
     * Now we are on the verge of accepting the path.
677
     *
678
     *
678
     * There is one optimization we could do in the future: copy the path
679
     * There is one optimization we could do in the future: copy the path
679
     * directly into the PLB using some kind of a callback.
680
     * directly into the PLB using some kind of a callback.
680
     */
681
     */
681
    char *path = malloc(len);
682
    char *path = malloc(len + 1);
682
   
683
   
683
    if (!path) {
684
    if (!path) {
684
        ipc_answer_0(callid, ENOMEM);
685
        ipc_answer_0(callid, ENOMEM);
685
        ipc_answer_0(rid, ENOMEM);
686
        ipc_answer_0(rid, ENOMEM);
686
        return;
687
        return;
Line 690... Line 691...
690
    if ((rc = ipc_data_write_finalize(callid, path, len))) {
691
    if ((rc = ipc_data_write_finalize(callid, path, len))) {
691
        ipc_answer_0(rid, rc);
692
        ipc_answer_0(rid, rc);
692
        free(path);
693
        free(path);
693
        return;
694
        return;
694
    }
695
    }
-
 
696
    path[len] = '\0';
695
   
697
   
696
    rwlock_write_lock(&namespace_rwlock);
698
    rwlock_write_lock(&namespace_rwlock);
697
    lflag &= L_DIRECTORY;   /* sanitize lflag */
699
    lflag &= L_DIRECTORY;   /* sanitize lflag */
698
    vfs_lookup_res_t lr;
700
    vfs_lookup_res_t lr;
699
    rc = vfs_lookup_internal(path, len, lflag | L_DESTROY, &lr, NULL);
701
    rc = vfs_lookup_internal(path, lflag | L_DESTROY, &lr, NULL);
700
    free(path);
702
    free(path);
701
    if (rc != EOK) {
703
    if (rc != EOK) {
702
        rwlock_write_unlock(&namespace_rwlock);
704
        rwlock_write_unlock(&namespace_rwlock);
703
        ipc_answer_0(rid, rc);
705
        ipc_answer_0(rid, rc);
704
        return;
706
        return;