| 67 | |
| 68 | The following example illustrates how the VFS server obtains the VFS node in the |
| 69 | implementation of the unlink operation: |
| 70 | |
| 71 | {{{ |
| 72 | int rc; |
| 73 | int lflag = ...; |
| 74 | char *path = ...; /* file path */ |
| 75 | ... |
| 76 | vfs_lookup_res_t lr; |
| 77 | rc = vfs_lookup_internal(path, lflag | L_UNLINK, &lr, NULL); |
| 78 | if (rc != EOK) { |
| 79 | /* handle error */ |
| 80 | ... |
| 81 | } |
| 82 | |
| 83 | vfs_node_t *node = vfs_node_get(&lr); |
| 84 | /* now we have a reference to the node and work with it */ |
| 85 | ... |
| 86 | vfs_node_put(node); |
| 87 | }}} |
| 88 | |
| 89 | The example is simplified and does not show all the details (e.g. it omits all synchronization), but it shows the main idea. Note the trailing ''vfs_node_put()'' function which drops a reference to a VFS node. If the last reference is dropped from a node, ''vfs_node_put()'' removes it from the hash table and cleans it up. |