Subversion Repositories HelenOS

Rev

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

Rev 2600 Rev 2619
Line 153... Line 153...
153
 
153
 
154
    /*
154
    /*
155
     * The first call has to be IPC_M_DATA_SEND in which we receive the
155
     * The first call has to be IPC_M_DATA_SEND in which we receive the
156
     * VFS info structure from the client FS.
156
     * VFS info structure from the client FS.
157
     */
157
     */
158
    if (!ipc_data_receive(&callid, &call, NULL, &size)) {
158
    if (!ipc_data_receive(&callid, NULL, &size)) {
159
        /*
159
        /*
160
         * The client doesn't obey the same protocol as we do.
160
         * The client doesn't obey the same protocol as we do.
161
         */
161
         */
162
        dprintf("Receiving of VFS info failed.\n");
162
        dprintf("Receiving of VFS info failed.\n");
163
        ipc_answer_fast_0(callid, EINVAL);
163
        ipc_answer_0(callid, EINVAL);
164
        ipc_answer_fast_0(rid, EINVAL);
164
        ipc_answer_0(rid, EINVAL);
165
        return;
165
        return;
166
    }
166
    }
167
   
167
   
168
    dprintf("VFS info received, size = %d\n", size);
168
    dprintf("VFS info received, size = %d\n", size);
169
   
169
   
Line 175... Line 175...
175
        /*
175
        /*
176
         * The client is sending us something, which cannot be
176
         * The client is sending us something, which cannot be
177
         * the info structure.
177
         * the info structure.
178
         */
178
         */
179
        dprintf("Received VFS info has bad size.\n");
179
        dprintf("Received VFS info has bad size.\n");
180
        ipc_answer_fast_0(callid, EINVAL);
180
        ipc_answer_0(callid, EINVAL);
181
        ipc_answer_fast_0(rid, EINVAL);
181
        ipc_answer_0(rid, EINVAL);
182
        return;
182
        return;
183
    }
183
    }
184
 
184
 
185
    /*
185
    /*
186
     * Allocate and initialize a buffer for the fs_info structure.
186
     * Allocate and initialize a buffer for the fs_info structure.
187
     */
187
     */
188
    fs_info_t *fs_info;
188
    fs_info_t *fs_info;
189
    fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
189
    fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
190
    if (!fs_info) {
190
    if (!fs_info) {
191
        dprintf("Could not allocate memory for FS info.\n");
191
        dprintf("Could not allocate memory for FS info.\n");
192
        ipc_answer_fast_0(callid, ENOMEM);
192
        ipc_answer_0(callid, ENOMEM);
193
        ipc_answer_fast_0(rid, ENOMEM);
193
        ipc_answer_0(rid, ENOMEM);
194
        return;
194
        return;
195
    }
195
    }
196
    link_initialize(&fs_info->fs_link);
196
    link_initialize(&fs_info->fs_link);
197
       
197
       
198
    rc = ipc_data_deliver(callid, &call, &fs_info->vfs_info, size);
198
    rc = ipc_data_deliver(callid, &fs_info->vfs_info, size);
199
    if (rc != EOK) {
199
    if (rc != EOK) {
200
        dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
200
        dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
201
            rc);
201
            rc);
202
        free(fs_info);
202
        free(fs_info);
203
        ipc_answer_fast_0(callid, rc);
203
        ipc_answer_0(callid, rc);
204
        ipc_answer_fast_0(rid, rc);
204
        ipc_answer_0(rid, rc);
205
        return;
205
        return;
206
    }
206
    }
207
 
207
 
208
    dprintf("VFS info delivered.\n");
208
    dprintf("VFS info delivered.\n");
209
       
209
       
210
    if (!vfs_info_sane(&fs_info->vfs_info)) {
210
    if (!vfs_info_sane(&fs_info->vfs_info)) {
211
        free(fs_info);
211
        free(fs_info);
212
        ipc_answer_fast_0(callid, EINVAL);
212
        ipc_answer_0(callid, EINVAL);
213
        ipc_answer_fast_0(rid, EINVAL);
213
        ipc_answer_0(rid, EINVAL);
214
        return;
214
        return;
215
    }
215
    }
216
       
216
       
217
    futex_down(&fs_head_futex);
217
    futex_down(&fs_head_futex);
218
 
218
 
Line 224... Line 224...
224
         * We already register a fs like this.
224
         * We already register a fs like this.
225
         */
225
         */
226
        dprintf("FS is already registered.\n");
226
        dprintf("FS is already registered.\n");
227
        futex_up(&fs_head_futex);
227
        futex_up(&fs_head_futex);
228
        free(fs_info);
228
        free(fs_info);
229
        ipc_answer_fast_0(callid, EEXISTS);
229
        ipc_answer_0(callid, EEXISTS);
230
        ipc_answer_fast_0(rid, EEXISTS);
230
        ipc_answer_0(rid, EEXISTS);
231
        return;
231
        return;
232
    }
232
    }
233
 
233
 
234
    /*
234
    /*
235
     * Add fs_info to the list of registered FS's.
235
     * Add fs_info to the list of registered FS's.
Line 246... Line 246...
246
    if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
246
    if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
247
        dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
247
        dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
248
        list_remove(&fs_info->fs_link);
248
        list_remove(&fs_info->fs_link);
249
        futex_up(&fs_head_futex);
249
        futex_up(&fs_head_futex);
250
        free(fs_info);
250
        free(fs_info);
251
        ipc_answer_fast_0(callid, EINVAL);
251
        ipc_answer_0(callid, EINVAL);
252
        ipc_answer_fast_0(rid, EINVAL);
252
        ipc_answer_0(rid, EINVAL);
253
        return;
253
        return;
254
    }
254
    }
255
    fs_info->phone = IPC_GET_ARG3(call);
255
    fs_info->phone = IPC_GET_ARG3(call);
256
    ipc_answer_fast_0(callid, EOK);
256
    ipc_answer_0(callid, EOK);
257
 
257
 
258
    dprintf("Callback connection to FS created.\n");
258
    dprintf("Callback connection to FS created.\n");
259
 
259
 
260
    /*
260
    /*
261
     * The client will want us to send him the address space area with PLB.
261
     * The client will want us to send him the address space area with PLB.
Line 265... Line 265...
265
        dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
265
        dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
266
        list_remove(&fs_info->fs_link);
266
        list_remove(&fs_info->fs_link);
267
        futex_up(&fs_head_futex);
267
        futex_up(&fs_head_futex);
268
        ipc_hangup(fs_info->phone);
268
        ipc_hangup(fs_info->phone);
269
        free(fs_info);
269
        free(fs_info);
270
        ipc_answer_fast_0(callid, EINVAL);
270
        ipc_answer_0(callid, EINVAL);
271
        ipc_answer_fast_0(rid, EINVAL);
271
        ipc_answer_0(rid, EINVAL);
272
        return;
272
        return;
273
    }
273
    }
274
   
274
   
275
    /*
275
    /*
276
     * We can only send the client address space area PLB_SIZE bytes long.
276
     * We can only send the client address space area PLB_SIZE bytes long.
Line 280... Line 280...
280
        dprintf("Client suggests wrong size of PFB, size = %d\n", size);
280
        dprintf("Client suggests wrong size of PFB, size = %d\n", size);
281
        list_remove(&fs_info->fs_link);
281
        list_remove(&fs_info->fs_link);
282
        futex_up(&fs_head_futex);
282
        futex_up(&fs_head_futex);
283
        ipc_hangup(fs_info->phone);
283
        ipc_hangup(fs_info->phone);
284
        free(fs_info);
284
        free(fs_info);
285
        ipc_answer_fast_0(callid, EINVAL);
285
        ipc_answer_0(callid, EINVAL);
286
        ipc_answer_fast_0(rid, EINVAL);
286
        ipc_answer_0(rid, EINVAL);
287
        return;
287
        return;
288
    }
288
    }
289
 
289
 
290
    /*
290
    /*
291
     * Commit to read-only sharing the PLB with the client.
291
     * Commit to read-only sharing the PLB with the client.
292
     */
292
     */
293
    ipc_answer_fast(callid, EOK, (ipcarg_t) plb,
293
    ipc_answer_2(callid, EOK, (ipcarg_t) plb,
294
        (ipcarg_t) (AS_AREA_READ | AS_AREA_CACHEABLE));
294
        (ipcarg_t) (AS_AREA_READ | AS_AREA_CACHEABLE));
295
 
295
 
296
    dprintf("Sharing PLB.\n");
296
    dprintf("Sharing PLB.\n");
297
 
297
 
298
    /*
298
    /*
299
     * That was it. The FS has been registered.
299
     * That was it. The FS has been registered.
300
     * In reply to the VFS_REGISTER request, we assign the client file
300
     * In reply to the VFS_REGISTER request, we assign the client file
301
     * system a global file system handle.
301
     * system a global file system handle.
302
     */
302
     */
303
    fs_info->fs_handle = (int) atomic_postinc(&fs_handle_next);
303
    fs_info->fs_handle = (int) atomic_postinc(&fs_handle_next);
304
    ipc_answer_fast_1(rid, EOK, (ipcarg_t) fs_info->fs_handle);
304
    ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle);
305
   
305
   
306
    futex_up(&fs_head_futex);
306
    futex_up(&fs_head_futex);
307
   
307
   
308
    dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n",
308
    dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n",
309
        FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle);
309
        FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle);