Subversion Repositories HelenOS

Rev

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

Rev 4420 Rev 4537
Line 47... Line 47...
47
#include <atomic.h>
47
#include <atomic.h>
48
#include <futex.h>
48
#include <futex.h>
49
#include <errno.h>
49
#include <errno.h>
50
#include <string.h>
50
#include <string.h>
51
#include <devmap.h>
51
#include <devmap.h>
52
#include "../../../srv/vfs/vfs.h"
52
#include <ipc/vfs.h>
-
 
53
#include <ipc/devmap.h>
53
 
54
 
54
int vfs_phone = -1;
55
static int vfs_phone = -1;
55
futex_t vfs_phone_futex = FUTEX_INITIALIZER;
56
static futex_t vfs_phone_futex = FUTEX_INITIALIZER;
-
 
57
static futex_t cwd_futex = FUTEX_INITIALIZER;
56
 
58
 
57
futex_t cwd_futex = FUTEX_INITIALIZER;
-
 
58
DIR *cwd_dir = NULL;
59
DIR *cwd_dir = NULL;
59
char *cwd_path = NULL;
60
char *cwd_path = NULL;
60
size_t cwd_size = 0;
61
size_t cwd_size = 0;
61
 
62
 
62
char *absolutize(const char *path, size_t *retlen)
63
char *absolutize(const char *path, size_t *retlen)
Line 208... Line 209...
208
    }
209
    }
209
    async_wait_for(req, &rc);
210
    async_wait_for(req, &rc);
210
    async_serialize_end();
211
    async_serialize_end();
211
    futex_up(&vfs_phone_futex);
212
    futex_up(&vfs_phone_futex);
212
    free(pa);
213
    free(pa);
213
 
214
   
214
    if (rc != EOK)
215
    if (rc != EOK)
215
        return (int) rc;
216
        return (int) rc;
-
 
217
   
216
    return (int) IPC_GET_ARG1(answer);
218
    return (int) IPC_GET_ARG1(answer);
217
}
219
}
218
 
220
 
219
int open(const char *path, int oflag, ...)
221
int open(const char *path, int oflag, ...)
220
{
222
{
221
    return _open(path, L_FILE, oflag);
223
    return _open(path, L_FILE, oflag);
222
}
224
}
223
 
225
 
-
 
226
int open_node(fdi_node_t *node, int oflag)
-
 
227
{
-
 
228
    futex_down(&vfs_phone_futex);
-
 
229
    async_serialize_start();
-
 
230
    vfs_connect();
-
 
231
   
-
 
232
    ipc_call_t answer;
-
 
233
    aid_t req = async_send_4(vfs_phone, VFS_OPEN_NODE, node->fs_handle,
-
 
234
        node->dev_handle, node->index, oflag, &answer);
-
 
235
   
-
 
236
    ipcarg_t rc;
-
 
237
    async_wait_for(req, &rc);
-
 
238
    async_serialize_end();
-
 
239
    futex_up(&vfs_phone_futex);
-
 
240
   
-
 
241
    if (rc != EOK)
-
 
242
        return (int) rc;
-
 
243
   
-
 
244
    return (int) IPC_GET_ARG1(answer);
-
 
245
}
-
 
246
 
224
int close(int fildes)
247
int close(int fildes)
225
{
248
{
226
    ipcarg_t rc;
249
    ipcarg_t rc;
227
   
250
   
228
    futex_down(&vfs_phone_futex);
251
    futex_down(&vfs_phone_futex);
Line 289... Line 312...
289
        return (ssize_t) IPC_GET_ARG1(answer);
312
        return (ssize_t) IPC_GET_ARG1(answer);
290
    else
313
    else
291
        return -1;
314
        return -1;
292
}
315
}
293
 
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_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_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)
-
 
360
{
-
 
361
    futex_down(&vfs_phone_futex);
-
 
362
    async_serialize_start();
-
 
363
    vfs_connect();
-
 
364
   
-
 
365
    ipcarg_t rc = async_req_1_0(vfs_phone, VFS_SYNC, fildes);
-
 
366
   
-
 
367
    async_serialize_end();
-
 
368
    futex_up(&vfs_phone_futex);
-
 
369
   
-
 
370
    return (int) rc;
-
 
371
}
-
 
372
 
294
off_t lseek(int fildes, off_t offset, int whence)
373
off_t lseek(int fildes, off_t offset, int whence)
295
{
374
{
296
    ipcarg_t rc;
375
    ipcarg_t rc;
297
 
376
 
298
    futex_down(&vfs_phone_futex);
377
    futex_down(&vfs_phone_futex);
Line 384... Line 463...
384
    }
463
    }
385
    async_wait_for(req, &rc);
464
    async_wait_for(req, &rc);
386
    async_serialize_end();
465
    async_serialize_end();
387
    futex_up(&vfs_phone_futex);
466
    futex_up(&vfs_phone_futex);
388
    free(pa);
467
    free(pa);
389
    return rc;
468
    return rc;
390
}
469
}
391
 
470
 
392
static int _unlink(const char *path, int lflag)
471
static int _unlink(const char *path, int lflag)
393
{
472
{
394
    ipcarg_t rc;
473
    ipcarg_t rc;
Line 414... Line 493...
414
    }
493
    }
415
    async_wait_for(req, &rc);
494
    async_wait_for(req, &rc);
416
    async_serialize_end();
495
    async_serialize_end();
417
    futex_up(&vfs_phone_futex);
496
    futex_up(&vfs_phone_futex);
418
    free(pa);
497
    free(pa);
419
    return rc;
498
    return rc;
420
}
499
}
421
 
500
 
422
int unlink(const char *path)
501
int unlink(const char *path)
423
{
502
{
424
    return _unlink(path, L_NONE);
503
    return _unlink(path, L_NONE);