Changeset 5cde90f in mainline for uspace/lib/libfs/libfs.c


Ignore:
Timestamp:
2010-02-19T17:16:46Z (14 years ago)
Author:
Pavel Rimsky <pavel@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
617652f
Parents:
b86d436 (diff), f41aa81 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Synchronizing with head (which has just been synchronized with this branch).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libfs/libfs.c

    rb86d436 r5cde90f  
    3737#include "libfs.h"
    3838#include "../../srv/vfs/vfs.h"
     39#include <macros.h>
    3940#include <errno.h>
    4041#include <async.h>
     
    161162        /* Accept the phone */
    162163        callid = async_get_call(&call);
    163         int mountee_phone = (int)IPC_GET_ARG1(call);
     164        int mountee_phone = (int) IPC_GET_ARG1(call);
    164165        if ((IPC_GET_METHOD(call) != IPC_M_CONNECTION_CLONE) ||
    165166            (mountee_phone < 0)) {
     
    172173        ipc_answer_0(callid, EOK);
    173174       
    174         res = async_data_write_receive(&callid, NULL);
    175         if (!res) {
    176                 ipc_hangup(mountee_phone);
    177                 ipc_answer_0(callid, EINVAL);
    178                 ipc_answer_0(rid, EINVAL);
    179                 return;
    180         }
    181        
    182175        fs_node_t *fn;
    183176        res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
    184177        if ((res != EOK) || (!fn)) {
    185178                ipc_hangup(mountee_phone);
    186                 ipc_answer_0(callid, combine_rc(res, ENOENT));
     179                async_data_write_void(combine_rc(res, ENOENT));
    187180                ipc_answer_0(rid, combine_rc(res, ENOENT));
    188181                return;
     
    192185                ipc_hangup(mountee_phone);
    193186                (void) ops->node_put(fn);
    194                 ipc_answer_0(callid, EBUSY);
     187                async_data_write_void(EBUSY);
    195188                ipc_answer_0(rid, EBUSY);
    196189                return;
     
    201194                ipc_hangup(mountee_phone);
    202195                (void) ops->node_put(fn);
    203                 ipc_answer_0(callid, rc);
     196                async_data_write_void(rc);
    204197                ipc_answer_0(rid, rc);
    205198                return;
     
    207200       
    208201        ipc_call_t answer;
    209         aid_t msg = async_send_1(mountee_phone, VFS_OUT_MOUNTED, mr_dev_handle,
    210             &answer);
    211         ipc_forward_fast(callid, mountee_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
    212         async_wait_for(msg, &rc);
     202        rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED,
     203            mr_dev_handle, &answer);
    213204       
    214205        if (rc == EOK) {
     
    224215        ipc_answer_3(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer),
    225216            IPC_GET_ARG3(answer));
     217}
     218
     219void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *request)
     220{
     221        dev_handle_t mp_dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     222        fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*request);
     223        fs_node_t *fn;
     224        int res;
     225
     226        res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
     227        if ((res != EOK) || (!fn)) {
     228                ipc_answer_0(rid, combine_rc(res, ENOENT));
     229                return;
     230        }
     231
     232        /*
     233         * We are clearly expecting to find the mount point active.
     234         */
     235        if (!fn->mp_data.mp_active) {
     236                (void) ops->node_put(fn);
     237                ipc_answer_0(rid, EINVAL);
     238                return;
     239        }
     240
     241        /*
     242         * Tell the mounted file system to unmount.
     243         */
     244        res = async_req_1_0(fn->mp_data.phone, VFS_OUT_UNMOUNTED,
     245            fn->mp_data.dev_handle);
     246
     247        /*
     248         * If everything went well, perform the clean-up on our side.
     249         */
     250        if (res == EOK) {
     251                ipc_hangup(fn->mp_data.phone);
     252                fn->mp_data.mp_active = false;
     253                fn->mp_data.fs_handle = 0;
     254                fn->mp_data.dev_handle = 0;
     255                fn->mp_data.phone = 0;
     256                /* Drop the reference created in libfs_mount(). */
     257                (void) ops->node_put(fn);
     258        }
     259
     260        (void) ops->node_put(fn);
     261        ipc_answer_0(rid, res);
    226262}
    227263
     
    304340                on_error(rc, goto out_with_answer);
    305341               
    306                 if ((tmp) && (tmp->mp_data.mp_active)) {
     342                /*
     343                 * If the matching component is a mount point, there are two
     344                 * legitimate semantics of the lookup operation. The first is
     345                 * the commonly used one in which the lookup crosses each mount
     346                 * point into the mounted file system. The second semantics is
     347                 * used mostly during unmount() and differs from the first one
     348                 * only in that the last mount point in the looked up path,
     349                 * which is also its last component, is not crossed.
     350                 */
     351
     352                if ((tmp) && (tmp->mp_data.mp_active) &&
     353                    (!(lflag & L_MP) || (next <= last))) {
    307354                        if (next > last)
    308355                                next = last = first;
     
    352399                                                ipc_answer_0(rid, rc);
    353400                                        } else {
    354                                                 ipc_answer_5(rid, EOK,
    355                                                     fs_handle, dev_handle,
     401                                                aoff64_t size = ops->size_get(fn);
     402                                                ipc_answer_5(rid, fs_handle,
     403                                                    dev_handle,
    356404                                                    ops->index_get(fn),
    357                                                     ops->size_get(fn),
     405                                                    LOWER32(size),
     406                                                    UPPER32(size),
    358407                                                    ops->lnkcnt_get(fn));
    359408                                                (void) ops->node_put(fn);
     
    432481                                        ipc_answer_0(rid, rc);
    433482                                } else {
    434                                         ipc_answer_5(rid, EOK,
    435                                             fs_handle, dev_handle,
     483                                        aoff64_t size = ops->size_get(fn);
     484                                        ipc_answer_5(rid, fs_handle,
     485                                            dev_handle,
    436486                                            ops->index_get(fn),
    437                                             ops->size_get(fn),
     487                                            LOWER32(size),
     488                                            UPPER32(size),
    438489                                            ops->lnkcnt_get(fn));
    439490                                        (void) ops->node_put(fn);
     
    455506                unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
    456507                rc = ops->unlink(par, cur, component);
    457                 ipc_answer_5(rid, (ipcarg_t) rc, fs_handle, dev_handle,
    458                     ops->index_get(cur), ops->size_get(cur), old_lnkcnt);
     508               
     509                if (rc == EOK) {
     510                        aoff64_t size = ops->size_get(cur);
     511                        ipc_answer_5(rid, fs_handle, dev_handle,
     512                            ops->index_get(cur), LOWER32(size), UPPER32(size),
     513                            old_lnkcnt);
     514                } else
     515                        ipc_answer_0(rid, rc);
     516               
    459517                goto out;
    460518        }
     
    475533                goto out;
    476534        }
     535
     536        if ((lflag & L_ROOT) && par) {
     537                ipc_answer_0(rid, EINVAL);
     538                goto out;
     539        }
    477540       
    478541out_with_answer:
     
    482545                        rc = ops->node_open(cur);
    483546               
    484                 ipc_answer_5(rid, rc, fs_handle, dev_handle,
    485                     ops->index_get(cur), ops->size_get(cur),
    486                     ops->lnkcnt_get(cur));
     547                if (rc == EOK) {
     548                        aoff64_t size = ops->size_get(cur);
     549                        ipc_answer_5(rid, fs_handle, dev_handle,
     550                            ops->index_get(cur), LOWER32(size), UPPER32(size),
     551                            ops->lnkcnt_get(cur));
     552                } else
     553                        ipc_answer_0(rid, rc);
     554               
    487555        } else
    488556                ipc_answer_0(rid, rc);
     
    551619        dev_handle_t dev_handle = IPC_GET_ARG1(*request);
    552620        fs_index_t index = IPC_GET_ARG2(*request);
     621       
    553622        fs_node_t *fn;
    554         int rc;
    555        
    556         rc = ops->node_get(&fn, dev_handle, index);
     623        int rc = ops->node_get(&fn, dev_handle, index);
    557624        on_error(rc, answer_and_return(rid, rc));
    558625       
     
    563630       
    564631        rc = ops->node_open(fn);
    565         ipc_answer_3(rid, rc, ops->size_get(fn), ops->lnkcnt_get(fn),
     632        aoff64_t size = ops->size_get(fn);
     633        ipc_answer_4(rid, rc, LOWER32(size), UPPER32(size), ops->lnkcnt_get(fn),
    566634            (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
    567635       
Note: See TracChangeset for help on using the changeset viewer.