Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_register.c

    reda925a r1e4cada  
    110110void vfs_register(ipc_callid_t rid, ipc_call_t *request)
    111111{
     112        ipc_callid_t callid;
     113        ipc_call_t call;
     114        int rc;
     115        size_t size;
     116
    112117        dprintf("Processing VFS_REGISTER request received from %p.\n",
    113118            request->in_phone_hash);
    114        
    115         vfs_info_t *vfs_info;
    116         int rc = async_data_write_accept((void **) &vfs_info, false,
    117             sizeof(vfs_info_t), sizeof(vfs_info_t), 0, NULL);
    118        
     119
     120        /*
     121         * The first call has to be IPC_M_DATA_SEND in which we receive the
     122         * VFS info structure from the client FS.
     123         */
     124        if (!async_data_write_receive(&callid, &size)) {
     125                /*
     126                 * The client doesn't obey the same protocol as we do.
     127                 */
     128                dprintf("Receiving of VFS info failed.\n");
     129                ipc_answer_0(callid, EINVAL);
     130                ipc_answer_0(rid, EINVAL);
     131                return;
     132        }
     133       
     134        dprintf("VFS info received, size = %d\n", size);
     135       
     136        /*
     137         * We know the size of the VFS info structure. See if the client
     138         * understands this easy concept too.
     139         */
     140        if (size != sizeof(vfs_info_t)) {
     141                /*
     142                 * The client is sending us something, which cannot be
     143                 * the info structure.
     144                 */
     145                dprintf("Received VFS info has bad size.\n");
     146                ipc_answer_0(callid, EINVAL);
     147                ipc_answer_0(rid, EINVAL);
     148                return;
     149        }
     150
     151        /*
     152         * Allocate and initialize a buffer for the fs_info structure.
     153         */
     154        fs_info_t *fs_info;
     155        fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
     156        if (!fs_info) {
     157                dprintf("Could not allocate memory for FS info.\n");
     158                ipc_answer_0(callid, ENOMEM);
     159                ipc_answer_0(rid, ENOMEM);
     160                return;
     161        }
     162        link_initialize(&fs_info->fs_link);
     163        fibril_mutex_initialize(&fs_info->phone_lock);
     164               
     165        rc = async_data_write_finalize(callid, &fs_info->vfs_info, size);
    119166        if (rc != EOK) {
    120167                dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
    121168                    rc);
     169                free(fs_info);
     170                ipc_answer_0(callid, rc);
    122171                ipc_answer_0(rid, rc);
    123172                return;
    124173        }
    125        
    126         /*
    127          * Allocate and initialize a buffer for the fs_info structure.
    128          */
    129         fs_info_t *fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
    130         if (!fs_info) {
    131                 dprintf("Could not allocate memory for FS info.\n");
    132                 ipc_answer_0(rid, ENOMEM);
    133                 return;
    134         }
    135        
    136         link_initialize(&fs_info->fs_link);
    137         fibril_mutex_initialize(&fs_info->phone_lock);
    138         fs_info->vfs_info = *vfs_info;
    139         free(vfs_info);
    140        
     174
    141175        dprintf("VFS info delivered.\n");
    142        
     176               
    143177        if (!vfs_info_sane(&fs_info->vfs_info)) {
    144178                free(fs_info);
    145                 ipc_answer_0(rid, EINVAL);
    146                 return;
    147         }
    148        
     179                ipc_answer_0(callid, EINVAL);
     180                ipc_answer_0(rid, EINVAL);
     181                return;
     182        }
     183               
    149184        fibril_mutex_lock(&fs_head_lock);
    150        
     185
    151186        /*
    152187         * Check for duplicit registrations.
     
    159194                fibril_mutex_unlock(&fs_head_lock);
    160195                free(fs_info);
     196                ipc_answer_0(callid, EEXISTS);
    161197                ipc_answer_0(rid, EEXISTS);
    162198                return;
    163199        }
    164        
     200
    165201        /*
    166202         * Add fs_info to the list of registered FS's.
     
    174210         * which to forward VFS requests to it.
    175211         */
    176         ipc_call_t call;
    177         ipc_callid_t callid = async_get_call(&call);
     212        callid = async_get_call(&call);
    178213        if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
    179214                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
     
    187222        fs_info->phone = IPC_GET_ARG5(call);
    188223        ipc_answer_0(callid, EOK);
    189        
     224
    190225        dprintf("Callback connection to FS created.\n");
    191        
     226
    192227        /*
    193228         * The client will want us to send him the address space area with PLB.
    194229         */
    195        
    196         size_t size;
     230
    197231        if (!async_share_in_receive(&callid, &size)) {
    198232                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
     
    219253                return;
    220254        }
    221        
     255
    222256        /*
    223257         * Commit to read-only sharing the PLB with the client.
     
    225259        (void) async_share_in_finalize(callid, plb,
    226260            AS_AREA_READ | AS_AREA_CACHEABLE);
    227        
     261
    228262        dprintf("Sharing PLB.\n");
    229        
     263
    230264        /*
    231265         * That was it. The FS has been registered.
Note: See TracChangeset for help on using the changeset viewer.