Subversion Repositories HelenOS

Rev

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

Rev 4584 Rev 4585
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 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)
-
 
318
{
-
 
319
    futex_down(&vfs_phone_futex);
-
 
320
    async_serialize_start();
-
 
321
    vfs_connect();
-
 
322
   
-
 
323
    ipcarg_t device;
-
 
324
    ipcarg_t rc = async_req_1_1(vfs_phone, VFS_IN_DEVICE, fildes, &device);
-
 
325
   
-
 
326
    async_serialize_end();
-
 
327
    futex_up(&vfs_phone_futex);
-
 
328
   
-
 
329
    if (rc != EOK)
-
 
330
        return -1;
-
 
331
   
-
 
332
    return devmap_device_connect((dev_handle_t) device, 0);
-
 
333
}
-
 
334
 
-
 
335
int fd_node(int fildes, fdi_node_t *node)
-
 
336
{
-
 
337
    futex_down(&vfs_phone_futex);
-
 
338
    async_serialize_start();
-
 
339
    vfs_connect();
-
 
340
   
-
 
341
    ipcarg_t fs_handle;
-
 
342
    ipcarg_t dev_handle;
-
 
343
    ipcarg_t index;
-
 
344
    ipcarg_t rc = async_req_1_3(vfs_phone, VFS_IN_NODE, fildes, &fs_handle,
-
 
345
        &dev_handle, &index);
-
 
346
   
-
 
347
    async_serialize_end();
-
 
348
    futex_up(&vfs_phone_futex);
-
 
349
   
-
 
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;
-
 
357
}
-
 
358
 
-
 
359
int fsync(int fildes)
317
int fsync(int fildes)
360
{
318
{
361
    futex_down(&vfs_phone_futex);
319
    futex_down(&vfs_phone_futex);
362
    async_serialize_start();
320
    async_serialize_start();
363
    vfs_connect();
321
    vfs_connect();
Line 403... Line 361...
403
    async_serialize_end();
361
    async_serialize_end();
404
    futex_up(&vfs_phone_futex);
362
    futex_up(&vfs_phone_futex);
405
    return (int) rc;
363
    return (int) rc;
406
}
364
}
407
 
365
 
-
 
366
int fstat(int fildes, struct stat *stat)
-
 
367
{
-
 
368
    ipcarg_t rc;
-
 
369
    ipc_call_t answer;
-
 
370
    aid_t req;
-
 
371
 
-
 
372
    futex_down(&vfs_phone_futex);
-
 
373
    async_serialize_start();
-
 
374
    vfs_connect();
-
 
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));
-
 
378
    if (rc != EOK) {
-
 
379
        async_wait_for(req, NULL);
-
 
380
        async_serialize_end();
-
 
381
        futex_up(&vfs_phone_futex);
-
 
382
        return (ssize_t) rc;
-
 
383
    }
-
 
384
    async_wait_for(req, &rc);
-
 
385
    async_serialize_end();
-
 
386
    futex_up(&vfs_phone_futex);
-
 
387
 
-
 
388
    return rc;
-
 
389
}
-
 
390
 
408
DIR *opendir(const char *dirname)
391
DIR *opendir(const char *dirname)
409
{
392
{
410
    DIR *dirp = malloc(sizeof(DIR));
393
    DIR *dirp = malloc(sizeof(DIR));
411
    if (!dirp)
394
    if (!dirp)
412
        return NULL;
395
        return NULL;
Line 596... Line 579...
596
    str_cpy(buf, size, cwd_path);
579
    str_cpy(buf, size, cwd_path);
597
    futex_up(&cwd_futex);
580
    futex_up(&cwd_futex);
598
    return buf;
581
    return buf;
599
}
582
}
600
 
583
 
-
 
584
int fd_phone(int fildes)
-
 
585
{
-
 
586
    struct stat stat;
-
 
587
    int rc;
-
 
588
 
-
 
589
    rc = fstat(fildes, &stat);
-
 
590
 
-
 
591
    if (!stat.devfs_stat.device)
-
 
592
        return -1;
-
 
593
   
-
 
594
    return devmap_device_connect(stat.devfs_stat.device, 0);
-
 
595
}
-
 
596
 
-
 
597
int fd_node(int fildes, fdi_node_t *node)
-
 
598
{
-
 
599
    struct stat stat;
-
 
600
    int rc;
-
 
601
 
-
 
602
    rc = fstat(fildes, &stat);
-
 
603
   
-
 
604
    if (rc == EOK) {
-
 
605
        node->fs_handle = stat.fs_handle;
-
 
606
        node->dev_handle = stat.dev_handle;
-
 
607
        node->index = stat.index;
-
 
608
    }
-
 
609
   
-
 
610
    return rc;
-
 
611
}
-
 
612
 
601
/** @}
613
/** @}
602
 */
614
 */