Subversion Repositories HelenOS

Rev

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

Rev 4537 Rev 4668
Line 36... Line 36...
36
#include <vfs/canonify.h>
36
#include <vfs/canonify.h>
37
#include <stdlib.h>
37
#include <stdlib.h>
38
#include <unistd.h>
38
#include <unistd.h>
39
#include <dirent.h>
39
#include <dirent.h>
40
#include <fcntl.h>
40
#include <fcntl.h>
41
#include <sys/stat.h>
-
 
42
#include <stdio.h>
41
#include <stdio.h>
-
 
42
#include <sys/stat.h>
43
#include <sys/types.h>
43
#include <sys/types.h>
44
#include <ipc/ipc.h>
44
#include <ipc/ipc.h>
45
#include <ipc/services.h>
45
#include <ipc/services.h>
46
#include <async.h>
46
#include <async.h>
47
#include <atomic.h>
47
#include <atomic.h>
Line 135... Line 135...
135
   
135
   
136
    futex_down(&vfs_phone_futex);
136
    futex_down(&vfs_phone_futex);
137
    async_serialize_start();
137
    async_serialize_start();
138
    vfs_connect();
138
    vfs_connect();
139
   
139
   
140
    req = async_send_2(vfs_phone, VFS_MOUNT, dev_handle, flags, NULL);
140
    req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
141
    rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_size);
141
    rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_size);
142
    if (rc != EOK) {
142
    if (rc != EOK) {
143
        async_wait_for(req, NULL);
143
        async_wait_for(req, NULL);
144
        async_serialize_end();
144
        async_serialize_end();
145
        futex_up(&vfs_phone_futex);
145
        futex_up(&vfs_phone_futex);
Line 196... Line 196...
196
   
196
   
197
    futex_down(&vfs_phone_futex);
197
    futex_down(&vfs_phone_futex);
198
    async_serialize_start();
198
    async_serialize_start();
199
    vfs_connect();
199
    vfs_connect();
200
   
200
   
201
    req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer);
201
    req = async_send_3(vfs_phone, VFS_IN_OPEN, lflag, oflag, 0, &answer);
202
    rc = ipc_data_write_start(vfs_phone, pa, pa_size);
202
    rc = ipc_data_write_start(vfs_phone, pa, pa_size);
203
    if (rc != EOK) {
203
    if (rc != EOK) {
204
        async_wait_for(req, NULL);
204
        async_wait_for(req, NULL);
205
        async_serialize_end();
205
        async_serialize_end();
206
        futex_up(&vfs_phone_futex);
206
        futex_up(&vfs_phone_futex);
Line 228... Line 228...
228
    futex_down(&vfs_phone_futex);
228
    futex_down(&vfs_phone_futex);
229
    async_serialize_start();
229
    async_serialize_start();
230
    vfs_connect();
230
    vfs_connect();
231
   
231
   
232
    ipc_call_t answer;
232
    ipc_call_t answer;
233
    aid_t req = async_send_4(vfs_phone, VFS_OPEN_NODE, node->fs_handle,
233
    aid_t req = async_send_4(vfs_phone, VFS_IN_OPEN_NODE, node->fs_handle,
234
        node->dev_handle, node->index, oflag, &answer);
234
        node->dev_handle, node->index, oflag, &answer);
235
   
235
   
236
    ipcarg_t rc;
236
    ipcarg_t rc;
237
    async_wait_for(req, &rc);
237
    async_wait_for(req, &rc);
238
    async_serialize_end();
238
    async_serialize_end();
Line 250... Line 250...
250
   
250
   
251
    futex_down(&vfs_phone_futex);
251
    futex_down(&vfs_phone_futex);
252
    async_serialize_start();
252
    async_serialize_start();
253
    vfs_connect();
253
    vfs_connect();
254
   
254
   
255
    rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes);
255
    rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes);
256
   
256
   
257
    async_serialize_end();
257
    async_serialize_end();
258
    futex_up(&vfs_phone_futex);
258
    futex_up(&vfs_phone_futex);
259
   
259
   
260
    return (int)rc;
260
    return (int)rc;
Line 268... Line 268...
268
 
268
 
269
    futex_down(&vfs_phone_futex);
269
    futex_down(&vfs_phone_futex);
270
    async_serialize_start();
270
    async_serialize_start();
271
    vfs_connect();
271
    vfs_connect();
272
   
272
   
273
    req = async_send_1(vfs_phone, VFS_READ, fildes, &answer);
273
    req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer);
274
    rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte);
274
    rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte);
275
    if (rc != EOK) {
275
    if (rc != EOK) {
276
        async_wait_for(req, NULL);
276
        async_wait_for(req, NULL);
277
        async_serialize_end();
277
        async_serialize_end();
278
        futex_up(&vfs_phone_futex);
278
        futex_up(&vfs_phone_futex);
Line 295... Line 295...
295
 
295
 
296
    futex_down(&vfs_phone_futex);
296
    futex_down(&vfs_phone_futex);
297
    async_serialize_start();
297
    async_serialize_start();
298
    vfs_connect();
298
    vfs_connect();
299
   
299
   
300
    req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer);
300
    req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer);
301
    rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte);
301
    rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte);
302
    if (rc != EOK) {
302
    if (rc != EOK) {
303
        async_wait_for(req, NULL);
303
        async_wait_for(req, NULL);
304
        async_serialize_end();
304
        async_serialize_end();
305
        futex_up(&vfs_phone_futex);
305
        futex_up(&vfs_phone_futex);
Line 312... Line 312...
312
        return (ssize_t) IPC_GET_ARG1(answer);
312
        return (ssize_t) IPC_GET_ARG1(answer);
313
    else
313
    else
314
        return -1;
314
        return -1;
315
}
315
}
316
 
316
 
317
int fd_phone(int fildes)
317
int fsync(int fildes)
318
{
318
{
319
    futex_down(&vfs_phone_futex);
319
    futex_down(&vfs_phone_futex);
320
    async_serialize_start();
320
    async_serialize_start();
321
    vfs_connect();
321
    vfs_connect();
322
   
322
   
323
    ipcarg_t device;
-
 
324
    ipcarg_t rc = async_req_1_1(vfs_phone, VFS_DEVICE, fildes, &device);
323
    ipcarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes);
325
   
324
   
326
    async_serialize_end();
325
    async_serialize_end();
327
    futex_up(&vfs_phone_futex);
326
    futex_up(&vfs_phone_futex);
328
   
327
   
329
    if (rc != EOK)
-
 
330
        return -1;
328
    return (int) rc;
331
   
-
 
332
    return devmap_device_connect((dev_handle_t) device, 0);
-
 
333
}
329
}
334
 
330
 
335
int fd_node(int fildes, fdi_node_t *node)
331
off_t lseek(int fildes, off_t offset, int whence)
336
{
332
{
-
 
333
    ipcarg_t rc;
-
 
334
 
337
    futex_down(&vfs_phone_futex);
335
    futex_down(&vfs_phone_futex);
338
    async_serialize_start();
336
    async_serialize_start();
339
    vfs_connect();
337
    vfs_connect();
340
   
338
   
341
    ipcarg_t fs_handle;
-
 
342
    ipcarg_t dev_handle;
-
 
343
    ipcarg_t index;
339
    ipcarg_t newoffs;
344
    ipcarg_t rc = async_req_1_3(vfs_phone, VFS_NODE, fildes, &fs_handle,
340
    rc = async_req_3_1(vfs_phone, VFS_IN_SEEK, fildes, offset, whence,
345
        &dev_handle, &index);
341
        &newoffs);
346
   
342
 
347
    async_serialize_end();
343
    async_serialize_end();
348
    futex_up(&vfs_phone_futex);
344
    futex_up(&vfs_phone_futex);
-
 
345
 
-
 
346
    if (rc != EOK)
-
 
347
        return (off_t) -1;
349
   
348
   
350
    if (rc == EOK) {
-
 
351
        node->fs_handle = (fs_handle_t) fs_handle;
-
 
352
        node->dev_handle = (dev_handle_t) dev_handle;
-
 
353
        node->index = (fs_index_t) index;
-
 
354
    }
-
 
355
   
-
 
356
    return rc;
349
    return (off_t) newoffs;
357
}
350
}
358
 
351
 
359
int fsync(int fildes)
352
int ftruncate(int fildes, off_t length)
360
{
353
{
-
 
354
    ipcarg_t rc;
-
 
355
   
361
    futex_down(&vfs_phone_futex);
356
    futex_down(&vfs_phone_futex);
362
    async_serialize_start();
357
    async_serialize_start();
363
    vfs_connect();
358
    vfs_connect();
364
   
359
   
365
    ipcarg_t rc = async_req_1_0(vfs_phone, VFS_SYNC, fildes);
360
    rc = async_req_2_0(vfs_phone, VFS_IN_TRUNCATE, fildes, length);
366
   
-
 
367
    async_serialize_end();
361
    async_serialize_end();
368
    futex_up(&vfs_phone_futex);
362
    futex_up(&vfs_phone_futex);
369
   
-
 
370
    return (int) rc;
363
    return (int) rc;
371
}
364
}
372
 
365
 
373
off_t lseek(int fildes, off_t offset, int whence)
366
int fstat(int fildes, struct stat *stat)
374
{
367
{
375
    ipcarg_t rc;
368
    ipcarg_t rc;
-
 
369
    ipc_call_t answer;
-
 
370
    aid_t req;
376
 
371
 
377
    futex_down(&vfs_phone_futex);
372
    futex_down(&vfs_phone_futex);
378
    async_serialize_start();
373
    async_serialize_start();
379
    vfs_connect();
374
    vfs_connect();
380
   
375
   
-
 
376
    req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL);
-
 
377
    rc = ipc_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat));
381
    ipcarg_t newoffs;
378
    if (rc != EOK) {
-
 
379
        async_wait_for(req, NULL);
-
 
380
        async_serialize_end();
382
    rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence,
381
        futex_up(&vfs_phone_futex);
383
        &newoffs);
382
        return (ssize_t) rc;
384
 
383
    }
-
 
384
    async_wait_for(req, &rc);
385
    async_serialize_end();
385
    async_serialize_end();
386
    futex_up(&vfs_phone_futex);
386
    futex_up(&vfs_phone_futex);
387
 
387
 
388
    if (rc != EOK)
-
 
389
        return (off_t) -1;
388
    return rc;
390
   
-
 
391
    return (off_t) newoffs;
-
 
392
}
389
}
393
 
390
 
394
int ftruncate(int fildes, off_t length)
391
int stat(const char *path, struct stat *stat)
395
{
392
{
396
    ipcarg_t rc;
393
    ipcarg_t rc;
-
 
394
    aid_t req;
-
 
395
   
-
 
396
    size_t pa_size;
-
 
397
    char *pa = absolutize(path, &pa_size);
-
 
398
    if (!pa)
-
 
399
        return ENOMEM;
397
   
400
   
398
    futex_down(&vfs_phone_futex);
401
    futex_down(&vfs_phone_futex);
399
    async_serialize_start();
402
    async_serialize_start();
400
    vfs_connect();
403
    vfs_connect();
401
   
404
   
402
    rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length);
405
    req = async_send_0(vfs_phone, VFS_IN_STAT, NULL);
-
 
406
    rc = ipc_data_write_start(vfs_phone, pa, pa_size);
-
 
407
    if (rc != EOK) {
-
 
408
        async_wait_for(req, NULL);
-
 
409
        async_serialize_end();
-
 
410
        futex_up(&vfs_phone_futex);
-
 
411
        free(pa);
-
 
412
        return (int) rc;
-
 
413
    }
-
 
414
    rc = ipc_data_read_start(vfs_phone, stat, sizeof(struct stat));
-
 
415
    if (rc != EOK) {
-
 
416
        async_wait_for(req, NULL);
-
 
417
        async_serialize_end();
-
 
418
        futex_up(&vfs_phone_futex);
-
 
419
        free(pa);
-
 
420
        return (int) rc;
-
 
421
    }
-
 
422
    async_wait_for(req, &rc);
403
    async_serialize_end();
423
    async_serialize_end();
404
    futex_up(&vfs_phone_futex);
424
    futex_up(&vfs_phone_futex);
-
 
425
    free(pa);
405
    return (int) rc;
426
    return rc;
406
}
427
}
407
 
428
 
408
DIR *opendir(const char *dirname)
429
DIR *opendir(const char *dirname)
409
{
430
{
410
    DIR *dirp = malloc(sizeof(DIR));
431
    DIR *dirp = malloc(sizeof(DIR));
Line 450... Line 471...
450
   
471
   
451
    futex_down(&vfs_phone_futex);
472
    futex_down(&vfs_phone_futex);
452
    async_serialize_start();
473
    async_serialize_start();
453
    vfs_connect();
474
    vfs_connect();
454
   
475
   
455
    req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL);
476
    req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL);
456
    rc = ipc_data_write_start(vfs_phone, pa, pa_size);
477
    rc = ipc_data_write_start(vfs_phone, pa, pa_size);
457
    if (rc != EOK) {
478
    if (rc != EOK) {
458
        async_wait_for(req, NULL);
479
        async_wait_for(req, NULL);
459
        async_serialize_end();
480
        async_serialize_end();
460
        futex_up(&vfs_phone_futex);
481
        futex_up(&vfs_phone_futex);
Line 480... Line 501...
480
 
501
 
481
    futex_down(&vfs_phone_futex);
502
    futex_down(&vfs_phone_futex);
482
    async_serialize_start();
503
    async_serialize_start();
483
    vfs_connect();
504
    vfs_connect();
484
   
505
   
485
    req = async_send_0(vfs_phone, VFS_UNLINK, NULL);
506
    req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL);
486
    rc = ipc_data_write_start(vfs_phone, pa, pa_size);
507
    rc = ipc_data_write_start(vfs_phone, pa, pa_size);
487
    if (rc != EOK) {
508
    if (rc != EOK) {
488
        async_wait_for(req, NULL);
509
        async_wait_for(req, NULL);
489
        async_serialize_end();
510
        async_serialize_end();
490
        futex_up(&vfs_phone_futex);
511
        futex_up(&vfs_phone_futex);
Line 527... Line 548...
527
 
548
 
528
    futex_down(&vfs_phone_futex);
549
    futex_down(&vfs_phone_futex);
529
    async_serialize_start();
550
    async_serialize_start();
530
    vfs_connect();
551
    vfs_connect();
531
   
552
   
532
    req = async_send_0(vfs_phone, VFS_RENAME, NULL);
553
    req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL);
533
    rc = ipc_data_write_start(vfs_phone, olda, olda_size);
554
    rc = ipc_data_write_start(vfs_phone, olda, olda_size);
534
    if (rc != EOK) {
555
    if (rc != EOK) {
535
        async_wait_for(req, NULL);
556
        async_wait_for(req, NULL);
536
        async_serialize_end();
557
        async_serialize_end();
537
        futex_up(&vfs_phone_futex);
558
        futex_up(&vfs_phone_futex);
Line 596... Line 617...
596
    str_cpy(buf, size, cwd_path);
617
    str_cpy(buf, size, cwd_path);
597
    futex_up(&cwd_futex);
618
    futex_up(&cwd_futex);
598
    return buf;
619
    return buf;
599
}
620
}
600
 
621
 
-
 
622
int fd_phone(int fildes)
-
 
623
{
-
 
624
    struct stat stat;
-
 
625
    int rc;
-
 
626
 
-
 
627
    rc = fstat(fildes, &stat);
-
 
628
 
-
 
629
    if (!stat.devfs_stat.device)
-
 
630
        return -1;
-
 
631
   
-
 
632
    return devmap_device_connect(stat.devfs_stat.device, 0);
-
 
633
}
-
 
634
 
-
 
635
int fd_node(int fildes, fdi_node_t *node)
-
 
636
{
-
 
637
    struct stat stat;
-
 
638
    int rc;
-
 
639
 
-
 
640
    rc = fstat(fildes, &stat);
-
 
641
   
-
 
642
    if (rc == EOK) {
-
 
643
        node->fs_handle = stat.fs_handle;
-
 
644
        node->dev_handle = stat.dev_handle;
-
 
645
        node->index = stat.index;
-
 
646
    }
-
 
647
   
-
 
648
    return rc;
-
 
649
}
-
 
650
 
601
/** @}
651
/** @}
602
 */
652
 */