Changeset a6fc88a in mainline


Ignore:
Timestamp:
2017-04-03T21:15:17Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8fe46a0
Parents:
ea4a3f0
Message:

Let vfs_link() and vfs_link_path() return the linked file handle

Add an output argument to both vfs_link() and vfs_link_path() so that the
client may receive the file handle of the linked file or directory. This
makes it easy to work with the new file or directory as it is ready to be
opened or in case of a directory to use it as a parent for further
operations without the need for additional vfs_lookup().

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rea4a3f0 ra6fc88a  
    294294                                merge_paths(dest_path, PATH_MAX, src_dirname);
    295295
    296                                 if (vfs_link_path(dest_path, KIND_DIRECTORY) != EOK) {
     296                                if (vfs_link_path(dest_path, KIND_DIRECTORY,
     297                                    NULL) != EOK) {
    297298                                        printf("Unable to create "
    298299                                            "dest directory %s\n", dest_path);
     
    308309                         * e.g. cp -r /src /data/new_dir_src
    309310                         */
    310                         if (vfs_link_path(dest_path, KIND_DIRECTORY) != EOK) {
     311                        if (vfs_link_path(dest_path, KIND_DIRECTORY,
     312                            NULL) != EOK) {
    311313                                printf("Unable to create "
    312314                                    "dest directory %s\n", dest_path);
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    rea4a3f0 ra6fc88a  
    9696
    9797        if (!create_parents) {
    98                 ret = vfs_link_path(path, KIND_DIRECTORY);
     98                ret = vfs_link_path(path, KIND_DIRECTORY, NULL);
    9999                if (ret != EOK) {
    100100                        cli_error(CL_EFAIL, "%s: could not create %s (%s)",
     
    135135                        path[prev_off] = 0;
    136136
    137                         ret = vfs_link_path(path, KIND_DIRECTORY);
     137                        ret = vfs_link_path(path, KIND_DIRECTORY, NULL);
    138138                        if (ret != EOK && ret != EEXIST) {
    139139                                cli_error(CL_EFAIL, "%s: could not create %s (%s)",
     
    146146                }
    147147                /* Create the final directory. */
    148                 ret = vfs_link_path(path, KIND_DIRECTORY);
     148                ret = vfs_link_path(path, KIND_DIRECTORY, NULL);
    149149                if (ret != EOK) {
    150150                        cli_error(CL_EFAIL, "%s: could not create %s (%s)",
  • uspace/app/sysinst/futil.c

    rea4a3f0 ra6fc88a  
    128128                } else if (s.is_directory) {
    129129                        printf("Create directory '%s'\n", destp);
    130                         rc = vfs_link_path(destp, KIND_DIRECTORY);
     130                        rc = vfs_link_path(destp, KIND_DIRECTORY, NULL);
    131131                        if (rc != EOK)
    132132                                return EIO;
  • uspace/app/sysinst/sysinst.c

    rea4a3f0 ra6fc88a  
    174174                return EIO;
    175175
    176         rc = vfs_link_path(MOUNT_POINT, KIND_DIRECTORY);
     176        rc = vfs_link_path(MOUNT_POINT, KIND_DIRECTORY, NULL);
    177177        if (rc != EOK)
    178178                return rc;
     
    213213
    214214        printf("sysinst_copy_boot_files(): create CD mount point\n");
    215         rc = vfs_link_path(CD_MOUNT_POINT, KIND_DIRECTORY);
     215        rc = vfs_link_path(CD_MOUNT_POINT, KIND_DIRECTORY, NULL);
    216216        if (rc != EOK)
    217217                return rc;
  • uspace/app/tester/vfs/vfs1.c

    rea4a3f0 ra6fc88a  
    7171        int rc;
    7272
    73         rc = vfs_link_path(TEST_DIRECTORY, KIND_DIRECTORY);
     73        rc = vfs_link_path(TEST_DIRECTORY, KIND_DIRECTORY, NULL);
    7474        if (rc != EOK) {
    7575                TPRINTF("rc=%d\n", rc);
  • uspace/app/untar/main.c

    rea4a3f0 ra6fc88a  
    105105        int rc;
    106106
    107         rc = vfs_link_path(header->filename, KIND_DIRECTORY);
     107        rc = vfs_link_path(header->filename, KIND_DIRECTORY, NULL);
    108108        if (rc != EOK) {
    109109                if (rc != EEXIST) {
  • uspace/lib/c/generic/vfs/vfs.c

    rea4a3f0 ra6fc88a  
    359359 * @param kind          Kind of the object to be created: KIND_FILE or
    360360 *                      KIND_DIRECTORY
     361 * @param[out] linkedfd If not NULL, will receive a file handle to the linked
     362 *                      child
    361363 * @return              EOK on success or a negative error code
    362364 */
    363 int vfs_link(int parent, const char *child, vfs_file_kind_t kind)
     365int vfs_link(int parent, const char *child, vfs_file_kind_t kind, int *linkedfd)
    364366{
    365367        int flags = (kind == KIND_DIRECTORY) ? WALK_DIRECTORY : WALK_REGULAR;
     
    369371                return file;
    370372
    371         vfs_put(file);
     373        if (linkedfd)
     374                *linkedfd = file;
     375        else
     376                vfs_put(file);
    372377
    373378        return EOK;
     
    384389 * @param kind          Kind of the object to be created: KIND_FILE or
    385390 *                      KIND_DIRECTORY
     391 * @param[out] linkedfd If not NULL, will receive a file handle to the linked
     392 *                      child
    386393 * @return              EOK on success or a negative error code
    387394 */
    388 int vfs_link_path(const char *path, vfs_file_kind_t kind)
     395int vfs_link_path(const char *path, vfs_file_kind_t kind, int *linkedfd)
    389396{
    390397        char *child;
     
    393400                return parent;
    394401
    395         int rc = vfs_link(parent, child, kind);
     402        int rc = vfs_link(parent, child, kind, linkedfd);
    396403
    397404        free(child);
  • uspace/lib/c/include/vfs/vfs.h

    rea4a3f0 ra6fc88a  
    8181extern async_exch_t *vfs_exchange_begin(void);
    8282extern void vfs_exchange_end(async_exch_t *);
    83 extern int vfs_link(int, const char *, vfs_file_kind_t);
    84 extern int vfs_link_path(const char *, vfs_file_kind_t);
     83extern int vfs_link(int, const char *, vfs_file_kind_t, int *);
     84extern int vfs_link_path(const char *, vfs_file_kind_t, int *);
    8585extern int vfs_lookup(const char *, int);
    8686extern int vfs_lookup_open(const char *, int, int);
  • uspace/lib/posix/source/sys/stat.c

    rea4a3f0 ra6fc88a  
    152152int posix_mkdir(const char *path, mode_t mode)
    153153{
    154         int rc = rcerrno(vfs_link_path, path, KIND_DIRECTORY);
     154        int rc = rcerrno(vfs_link_path, path, KIND_DIRECTORY, NULL);
    155155        if (rc != EOK)
    156156                return -1;
Note: See TracChangeset for help on using the changeset viewer.