Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changes between Version 14 and Version 15 of FSDesign


Ignore:
Timestamp:
2009-10-24T11:27:34Z (10 years ago)
Author:
Jakub Jermář
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • FSDesign

    v14 v15  
    100100==== Handles as Arguments ====
    101101
    102 The VFS server understands file handles and can accept them as arguments for VFS requests made by the client. Each client is using its private set of file handles to refer to its open files. VFS maintains each client's open files in a table of open files, which is local to the servicing connection fibril. The table is composed of 'vfs_file_t'' pointers and the file handles index it. The associated connection fibril does not need to synchronize accesses to the table of open files because it is its exclusive owner.
     102The VFS server understands file handles and can accept them as arguments for VFS requests made by the client. Each client is using its private set of file handles to refer to its open files. VFS maintains each client's open files in a table of open files, which is local to the servicing connection fibril. The table is composed of ''vfs_file_t'' pointers and the file handles index it. The associated connection fibril does not need to synchronize accesses to the table of open files because it is its exclusive owner.
    103103
    104 The ''vfs_file_t'' structures track things like how many file handles reference it, the current position in the open file and the corresponding VFS node. The transition from a file handle to a VFS node is therefore straightforward.
     104The ''vfs_file_t'' structures track things like how many file handles reference it, the current position in the open file and the corresponding VFS node. The transition from a file handle to a VFS node is therefore straightforward and is best shown on the following example:
     105
     106{{{
     107        int fd;     /* file handle */
     108...
     109        /* Lookup the file structure corresponding to the file descriptor. */
     110        vfs_file_t *file = vfs_file_get(fd);
     111...
     112        /*
     113         * Lock the open file structure so that no other thread can manipulate
     114         * the same open file at a time.
     115         */
     116        fibril_mutex_lock(&file->lock);
     117...
     118        /*
     119         * Lock the file's node so that no other client can read/write to it at
     120         * the same time.
     121         */
     122        if (read)
     123                fibril_rwlock_read_lock(&file->node->contents_rwlock);
     124        else
     125                fibril_rwlock_write_lock(&file->node->contents_rwlock);
     126
     127}}}
     128
     129In the above code snippet, the ''vfs_rdwr()'' function first translates the file handle using the ''vfs_file_get()'' interface to a ''vfs_file_t'' structure and then locks it. The VFS node is directly addressed in the two RW-lock lock operations at the end of the example.