Changeset 6e5562a in mainline


Ignore:
Timestamp:
2017-03-31T19:57:38Z (7 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

Location:
uspace
Files:
1 deleted
22 edited

Legend:

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

    ra56cef9 r6e5562a  
    3636#include <str.h>
    3737#include <fcntl.h>
    38 #include <sys/stat.h>
    3938#include <vfs/vfs.h>
    4039#include <dirent.h>
     
    296295                                merge_paths(dest_path, PATH_MAX, src_dirname);
    297296
    298                                 if (mkdir(dest_path, 0) != 0) {
     297                                if (vfs_link_path(dest_path, KIND_DIRECTORY) != EOK) {
    299298                                        printf("Unable to create "
    300299                                            "dest directory %s\n", dest_path);
     
    310309                         * e.g. cp -r /src /data/new_dir_src
    311310                         */
    312                         if (mkdir(dest_path, 0) != 0) {
     311                        if (vfs_link_path(dest_path, KIND_DIRECTORY) != EOK) {
    313312                                printf("Unable to create "
    314313                                    "dest directory %s\n", dest_path);
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    ra56cef9 r6e5562a  
    3232#include <fcntl.h>
    3333#include <sys/types.h>
    34 #include <sys/stat.h>
    3534#include <getopt.h>
    3635#include <stdarg.h>
     
    9897
    9998        if (!create_parents) {
    100                 if (mkdir(path, 0) != 0) {
     99                ret = vfs_link_path(path, KIND_DIRECTORY);
     100                if (ret != EOK) {
    101101                        cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    102                             cmdname, path, str_error(errno));
     102                            cmdname, path, str_error(ret));
    103103                        ret = 1;
    104104                }
     
    136136                        path[prev_off] = 0;
    137137
    138                         if (mkdir(path, 0) != 0 && errno != EEXIST) {
     138                        ret = vfs_link_path(path, KIND_DIRECTORY);
     139                        if (ret != EOK && ret != EEXIST) {
    139140                                cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    140                                     cmdname, path, str_error(errno));
     141                                    cmdname, path, str_error(ret));
    141142                                ret = 1;
    142143                                goto leave;
     
    146147                }
    147148                /* Create the final directory. */
    148                 if (mkdir(path, 0) != 0) {
     149                ret = vfs_link_path(path, KIND_DIRECTORY);
     150                if (ret != EOK) {
    149151                        cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    150                             cmdname, path, str_error(errno));
     152                            cmdname, path, str_error(ret));
    151153                        ret = 1;
    152154                }
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    ra56cef9 r6e5562a  
    3333#include <fcntl.h>
    3434#include <sys/types.h>
    35 #include <sys/stat.h>
    3635#include <macros.h>
    3736#include <getopt.h>
  • uspace/app/fontviewer/fontviewer.c

    ra56cef9 r6e5562a  
    3636#include <unistd.h>
    3737#include <fcntl.h>
    38 #include <sys/stat.h>
    3938#include <errno.h>
    4039#include <malloc.h>
  • uspace/app/sysinst/futil.c

    ra56cef9 r6e5562a  
    3939#include <stdio.h>
    4040#include <stdlib.h>
    41 #include <sys/stat.h>
    4241#include <vfs/vfs.h>
    4342#include <sys/types.h>
     
    130129                } else if (s.is_directory) {
    131130                        printf("Create directory '%s'\n", destp);
    132                         rc = mkdir(destp, 0);
     131                        rc = vfs_link_path(destp, KIND_DIRECTORY);
    133132                        if (rc != EOK)
    134133                                return EIO;
  • uspace/app/sysinst/sysinst.c

    ra56cef9 r6e5562a  
    4343#include <stdio.h>
    4444#include <stdlib.h>
    45 #include <sys/stat.h>
    4645#include <task.h>
    4746#include <vfs/vfs.h>
     
    175174                return EIO;
    176175
    177         rc = mkdir(MOUNT_POINT, 0);
     176        rc = vfs_link_path(MOUNT_POINT, KIND_DIRECTORY);
    178177        if (rc != EOK)
    179178                return rc;
     
    214213
    215214        printf("sysinst_copy_boot_files(): create CD mount point\n");
    216         rc = mkdir(CD_MOUNT_POINT, 0);
     215        rc = vfs_link_path(CD_MOUNT_POINT, KIND_DIRECTORY);
    217216        if (rc != EOK)
    218217                return rc;
  • uspace/app/taskdump/elf_core.c

    ra56cef9 r6e5562a  
    5454#include <errno.h>
    5555#include <sys/types.h>
    56 #include <sys/stat.h>
    5756#include <unistd.h>
    5857#include <fcntl.h>
  • uspace/app/taskdump/symtab.c

    ra56cef9 r6e5562a  
    4141#include <errno.h>
    4242#include <sys/types.h>
    43 #include <sys/stat.h>
    4443#include <fcntl.h>
    4544
  • uspace/app/tester/hw/misc/virtchar1.c

    ra56cef9 r6e5562a  
    4545#include <vfs/vfs.h>
    4646#include <vfs/vfs_sess.h>
    47 #include <sys/stat.h>
    4847#include <fcntl.h>
    4948#include "../../tester.h"
  • uspace/app/tester/vfs/vfs1.c

    ra56cef9 r6e5562a  
    3737#include <loc.h>
    3838#include <sys/types.h>
    39 #include <sys/stat.h>
    4039#include "../tester.h"
    4140
     
    7170{
    7271        aoff64_t pos = 0;
     72        int rc;
    7373
    74         if (mkdir(TEST_DIRECTORY, 0) != 0) {
    75                 TPRINTF("rc=%d\n", errno);
    76                 return "mkdir() failed";
     74        rc = vfs_link_path(TEST_DIRECTORY, KIND_DIRECTORY);
     75        if (rc != EOK) {
     76                TPRINTF("rc=%d\n", rc);
     77                return "vfs_link_path() failed";
    7778        }
    7879        TPRINTF("Created directory %s\n", TEST_DIRECTORY);
  • uspace/app/untar/main.c

    ra56cef9 r6e5562a  
    3535#include <stdio.h>
    3636#include <stdlib.h>
    37 #include <sys/stat.h>
    3837#include <errno.h>
    3938#include <str_error.h>
     39#include <vfs/vfs.h>
    4040#include "tar.h"
    4141
     
    103103static int handle_directory(const tar_header_t *header, FILE *tarfile)
    104104{
    105         if (mkdir(header->filename, 0755) != 0) {
    106                 if (errno != EEXIST) {
     105        int rc;
     106
     107        rc = vfs_link_path(header->filename, KIND_DIRECTORY);
     108        if (rc != EOK) {
     109                if (rc != EEXIST) {
    107110                        fprintf(stderr, "Failed to create directory %s: %s.\n",
    108                             header->filename, str_error(errno));
    109                         return errno;
     111                            header->filename, str_error(rc));
     112                        return rc;
    110113                }
    111114        }
  • uspace/app/websrv/websrv.c

    ra56cef9 r6e5562a  
    3939#include <stdio.h>
    4040#include <sys/types.h>
    41 #include <sys/stat.h>
    4241#include <stdlib.h>
    4342#include <fcntl.h>
  • uspace/drv/char/ns8250/ns8250.c

    ra56cef9 r6e5562a  
    4949#include <dirent.h>
    5050#include <fcntl.h>
    51 #include <sys/stat.h>
    5251#include <ddi.h>
    5352
  • uspace/lib/bithenge/src/failure.c

    ra56cef9 r6e5562a  
    4141#include <stdio.h>
    4242#include <stdlib.h>
    43 #include <sys/stat.h>
    4443#include <sys/types.h>
    4544#include <sys/wait.h>
  • uspace/lib/bithenge/src/failure.h

    ra56cef9 r6e5562a  
    4242#include <stdio.h>
    4343#include <stdlib.h>
    44 #include <sys/stat.h>
    4544#include <sys/types.h>
    4645#include <unistd.h>
  • 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)
  • uspace/lib/c/include/vfs/vfs.h

    ra56cef9 r6e5562a  
    4949};
    5050
     51typedef enum {
     52        KIND_FILE,
     53        KIND_DIRECTORY,
     54} vfs_file_kind_t;
     55
     56
    5157struct stat {
    5258        fs_handle_t fs_handle;
     
    8894
    8995extern int vfs_clone(int, int, bool);
     96extern int vfs_link(int, const char *, vfs_file_kind_t);
     97extern int vfs_link_path(const char *, vfs_file_kind_t);
     98extern int vfs_resize(int, aoff64_t);
    9099extern int vfs_root(void);
    91100extern void vfs_root_set(int);
    92 extern int vfs_resize(int, aoff64_t);
    93101extern int vfs_stat(int, struct stat *);
    94102extern int vfs_stat_path(const char *, struct stat *);
  • uspace/lib/fs/libfs.c

    ra56cef9 r6e5562a  
    4444#include <mem.h>
    4545#include <str.h>
    46 #include <sys/stat.h>
    4746#include <stdlib.h>
    4847#include <fibril_synch.h>
  • uspace/lib/posix/include/posix/sys/stat.h

    ra56cef9 r6e5562a  
    133133extern int __POSIX_DEF__(chmod)(const char *path, mode_t mode);
    134134extern mode_t __POSIX_DEF__(umask)(mode_t mask);
    135 extern int mkdir(const char *, mode_t);
     135extern int __POSIX_DEF__(mkdir)(const char *path, mode_t mode);
    136136
    137137
  • uspace/lib/posix/source/stdio.c

    ra56cef9 r6e5562a  
    5353#include "libc/malloc.h"
    5454#include "libc/adt/list.h"
    55 #include "libc/sys/stat.h"
    5655
    5756/** Clears the stream's error and end-of-file indicators.
  • uspace/lib/posix/source/sys/stat.c

    ra56cef9 r6e5562a  
    143143}
    144144
     145/**
     146 * Create a directory.
     147 *
     148 * @param path Path to the new directory.
     149 * @param mode Permission bits to be set.
     150 * @return Zero on success, -1 otherwise.
     151 */
     152int posix_mkdir(const char *path, mode_t mode)
     153{
     154        int rc = rcerrno(vfs_link_path, path, KIND_DIRECTORY);
     155        if (rc != EOK)
     156                return -1;
     157        else
     158                return 0;
     159}
     160
    145161/** @}
    146162 */
  • uspace/srv/fs/locfs/locfs_ops.c

    ra56cef9 r6e5562a  
    4545#include <adt/hash_table.h>
    4646#include <ipc/loc.h>
    47 #include <sys/stat.h>
    4847#include <assert.h>
    4948#include "locfs.h"
Note: See TracChangeset for help on using the changeset viewer.