Changeset 6e5562a in mainline for uspace/lib/c/generic/vfs/vfs.c


Ignore:
Timestamp:
2017-03-31T19:57:38Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
80743a1
Parents:
a56cef9
Message:

Introduce vfs_link_path() and replace mkdir() with it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vfs/vfs.c

    ra56cef9 r6e5562a  
    4343#include <fcntl.h>
    4444#include <stdio.h>
    45 #include <sys/stat.h>
    4645#include <sys/types.h>
    4746#include <ipc/services.h>
     
    765764}
    766765
    767 /** Create directory.
     766int vfs_link(int parent, const char *child, vfs_file_kind_t kind)
     767{
     768        int flags = (kind == KIND_DIRECTORY) ? WALK_DIRECTORY : WALK_REGULAR;
     769        int file = _vfs_walk(parent, child, WALK_MUST_CREATE | flags);
     770
     771        if (file < 0)
     772                return file;
     773
     774        close(file);
     775
     776        return EOK;
     777}
     778
     779/** Link a file or directory.
    768780 *
    769781 * @param path Path
    770  * @param mode File mode
    771  * @return 0 on success. On error returns -1 and sets errno.
    772  */
    773 int mkdir(const char *path, mode_t mode)
    774 {
    775         int fd = vfs_lookup(path, WALK_MUST_CREATE | WALK_DIRECTORY);
    776         if (fd < 0) {
    777                 errno = fd;
    778                 return -1;
    779         }
    780        
    781         return close(fd);
    782 }
     782 * @param kind Kind of the file to be created.
     783 * @return EOK on success or a negative error code otherwise
     784 */
     785int vfs_link_path(const char *path, vfs_file_kind_t kind)
     786{
     787        size_t pa_size;
     788        char *pa = vfs_absolutize(path, &pa_size);
     789        if (!pa)
     790                return ENOMEM;
     791
     792        int parent;
     793        char *slash = str_rchr(pa, L'/');
     794        if (slash != pa) {
     795                *slash = '\0';
     796                parent = vfs_lookup(pa, WALK_DIRECTORY);
     797                *slash = '/';
     798        } else {
     799                parent = vfs_root();
     800        }
     801
     802        if (parent < 0) {
     803                free(pa);
     804                return parent;
     805        }
     806
     807        int rc = vfs_link(parent, slash, kind);
     808
     809        free(pa);
     810        close(parent);
     811        return rc;
     812}       
    783813
    784814int vfs_unlink(int parent, const char *child, int expect)
     
    802832}
    803833
    804 /** Unlink file or directory.
     834/** Unlink a file or directory.
    805835 *
    806836 * @param path Path
    807  * @return EOk on success or a negative error code otherwise
     837 * @return EOK on success or a negative error code otherwise
    808838 */
    809839int vfs_unlink_path(const char *path)
Note: See TracChangeset for help on using the changeset viewer.