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

Changes between Version 2 and Version 3 of FilesystemAPITutorial


Ignore:
Timestamp:
2017-04-09T07:40:21Z (2 years ago)
Author:
Jakub Jermář
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • FilesystemAPITutorial

    v2 v3  
    66== Preparing to use the API ==
    77
    8 HelenOS filesystem API is implemented in the standard library, so there is no need to link against any additional library in order to access files. HelenOS requires you to only include `vfs/vfs.h` in order to get declarations of all filesystem APIs:
     8HelenOS filesystem API is implemented in the standard library, so there is no need to link against any additional library in order to be able to use it. HelenOS only requires filesystem clients to include `vfs/vfs.h` in order to get declarations of all the APIs:
    99
    1010{{{
     
    1414== Paths and File handles ==
    1515
    16 The API is designed to use file handles as a primary way to refer to files. One may obtain a file handle by looking up a filesytem path, creating a new file or directory or attaching a new filesystem into the filesystem hierarchy.
     16The API is designed to use file handles as a primary and prefered way to refer to files. One may obtain a file handle by looking up a filesytem path, creating a new file or directory or attaching a new filesystem into the filesystem hierarchy.
    1717
    1818== Reading an existing file ==
     
    100100}}}
    101101
    102 `vfs_link_path()` used here is a convenience wrapper around `vfs_link()`, which we will shortly use too. It allows us not to care about `/foo`'s handle. If the return code is `EOK`, we can be sure that a new directory named `/foo/foobar` was created and also that there was no file or directory of the same name standing in its way. Moreover, the variable `foobar` now contains a file handle of the newly created directory. We will use it now to create the file:
     102`vfs_link_path()` used here is a convenience wrapper around `vfs_link()`, which we will shortly use too. It allows us not to care about `/foo`'s handle (but directory `/foo` must already exist). If the return code is `EOK`, we can be sure that a new directory named `/foo/foobar` was created and also that there was no file or directory of the same name standing in its way. Moreover, the variable `foobar` now contains a file handle of the newly created directory. We will use it now to create the file:
    103103
    104104{{{
     
    108108if (rc != EOK)
    109109        return rc;
     110}}}
    110111
     112As in the previous scenario, the file handle needs to be opened before we can write to it:
     113
     114{{{
    111115rc = vfs_open(hello, MODE_WRITE);
    112116if (rc != EOK) {
     
    114118        return rc;
    115119}
     120}}}
     121
     122Finally, we can write our message. This time we use a compound literal to pass our initial position.
    116123
    117124char greeting[] = "Hello world!";
     
    122129}
    123130}}}
     131
     132Finally, we put the file handle:
     133
     134{{{
     135rc = vfs_put(hello);
     136if (rc != EOK)
     137        return rc;
     138}}}
     139
     140Here we are interested in the return code of `vfs_put()` because we made modifications to the file. An error at this point might indicate our data didn't get entirely through.