Changeset 23a0368 in mainline


Ignore:
Timestamp:
2017-03-30T19:52:23Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ae7bfbbd
Parents:
b5b5d84
Message:

Rename stat() to vfs_stat_path() and fstat() to vfs_stat()

Location:
uspace
Files:
20 edited

Legend:

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

    rb5b5d84 r23a0368  
    3131#include <stdlib.h>
    3232#include <unistd.h>
    33 #include <sys/stat.h>
    3433#include <getopt.h>
    3534#include <str.h>
     
    214213                struct stat st;
    215214
    216                 if (fstat(fd, &st) != EOK) {
     215                if (vfs_stat(fd, &st) != EOK) {
    217216                        close(fd);
    218217                        free(buff);
    219                         printf("Unable to fstat %d\n", fd);
     218                        printf("Unable to vfs_stat %d\n", fd);
    220219                        return 1;
    221220                }
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rb5b5d84 r23a0368  
    3737#include <fcntl.h>
    3838#include <sys/stat.h>
     39#include <vfs/vfs.h>
    3940#include <dirent.h>
    4041#include "config.h"
     
    8384        struct stat s;
    8485
    85         int r = stat(path, &s);
    86 
    87         if (r != 0)
     86        int r = vfs_stat_path(path, &s);
     87
     88        if (r != EOK)
    8889                return TYPE_NONE;
    8990        else if (s.is_directory)
     
    341342
    342343                        /* Check if we are copying a directory into itself */
    343                         stat(src_dent, &src_s);
    344                         stat(dest_path, &dest_s);
     344                        vfs_stat_path(src_dent, &src_s);
     345                        vfs_stat_path(dest_path, &dest_s);
    345346
    346347                        if (dest_s.index == src_s.index &&
     
    394395        }
    395396
    396         if (fstat(fd1, &st) != EOK) {
     397        if (vfs_stat(fd1, &st) != EOK) {
    397398                printf("Unable to fstat %d\n", fd1);
    398399                close(fd1);
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    rb5b5d84 r23a0368  
    3939#include <getopt.h>
    4040#include <sys/types.h>
    41 #include <sys/stat.h>
     41#include <vfs/vfs.h>
    4242#include <str.h>
    4343#include <sort.h>
     
    185185                buff[len] = '\0';
    186186
    187                 rc = stat(buff, &tosort[nbdirs++].s);
    188                 if (rc != 0) {
     187                rc = vfs_stat_path(buff, &tosort[nbdirs++].s);
     188                if (rc != EOK) {
    189189                        printf("ls: skipping bogus node %s\n", buff);
    190                         printf("error=%d\n", errno);
     190                        printf("error=%d\n", rc);
    191191                        goto out;
    192192                }
     
    315315static unsigned int ls_scope(const char *path, struct dir_elem_t *de)
    316316{
    317         if (stat(path, &de->s) != 0) {
     317        if (vfs_stat_path(path, &de->s) != EOK) {
    318318                cli_error(CL_ENOENT, "%s", path);
    319319                return LS_BOGUS;
  • uspace/app/bdsh/cmds/modules/ls/ls.h

    rb5b5d84 r23a0368  
    11#ifndef LS_H
    22#define LS_H
     3
     4#include <vfs/vfs.h>
    35
    46/* Various values that can be returned by ls_scope() */
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    rb5b5d84 r23a0368  
    4040#include <str.h>
    4141#include <getopt.h>
    42 #include <sys/stat.h>
    4342#include <errno.h>
     43#include <vfs/vfs.h>
    4444
    4545#include "config.h"
     
    123123               
    124124                /* Check whether file exists if -c (--no-create) option is given */
    125                 if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == 0)))
     125                if ((!no_create) ||
     126                    ((no_create) && (vfs_stat_path(buff, &file_stat) == EOK))) {
    126127                        fd = open(buff, O_RDWR | O_CREAT);
     128                }
    127129               
    128130                if (fd < 0) {
  • uspace/app/bdsh/compl.c

    rb5b5d84 r23a0368  
    3333#include <macros.h>
    3434#include <stdlib.h>
    35 #include <sys/stat.h>
     35#include <vfs/vfs.h>
    3636
    3737#include "cmds/cmds.h"
     
    360360                                asprintf(&ent_path, "%s/%s", *cs->path, dent->d_name);
    361361                                struct stat ent_stat;
    362                                 if (stat(ent_path, &ent_stat) != 0) {
     362                                if (vfs_stat_path(ent_path, &ent_stat) != EOK) {
    363363                                        /* Error */
    364364                                        free(ent_path);
  • uspace/app/init/init.c

    rb5b5d84 r23a0368  
    4242#include <errno.h>
    4343#include <fcntl.h>
    44 #include <sys/stat.h>
    4544#include <task.h>
    4645#include <malloc.h>
     
    156155{
    157156        struct stat s;
    158         if (stat(path, &s) != 0) {
     157        if (vfs_stat_path(path, &s) != EOK) {
    159158                printf("%s: Unable to stat %s\n", NAME, path);
    160159                return ENOENT;
  • uspace/app/sysinst/futil.c

    rb5b5d84 r23a0368  
    4040#include <stdlib.h>
    4141#include <sys/stat.h>
     42#include <vfs/vfs.h>
    4243#include <sys/types.h>
    4344#include <dirent.h>
     
    119120                        return ENOMEM;
    120121
    121                 rc = stat(srcp, &s);
     122                rc = vfs_stat_path(srcp, &s);
    122123                if (rc != EOK)
    123124                        return EIO;
     
    166167                return ENOENT;
    167168
    168         if (fstat(sf, &st) != EOK) {
     169        if (vfs_stat(sf, &st) != EOK) {
    169170                close(sf);
    170171                return EIO;
  • uspace/app/viewer/viewer.c

    rb5b5d84 r23a0368  
    3636#include <unistd.h>
    3737#include <fcntl.h>
    38 #include <sys/stat.h>
     38#include <vfs/vfs.h>
    3939#include <errno.h>
    4040#include <malloc.h>
     
    115115       
    116116        struct stat stat;
    117         int rc = fstat(fd, &stat);
    118         if (rc != 0) {
     117        int rc = vfs_stat(fd, &stat);
     118        if (rc != EOK) {
    119119                close(fd);
    120120                return false;
  • uspace/drv/bus/isa/isa.c

    rb5b5d84 r23a0368  
    5454#include <ipc/irc.h>
    5555#include <ipc/services.h>
    56 #include <sys/stat.h>
     56#include <vfs/vfs.h>
    5757#include <irc.h>
    5858#include <ns.h>
     
    264264        opened = true;
    265265
    266         if (fstat(fd, &st) != EOK) {
    267                 ddf_msg(LVL_ERROR, "Unable to fstat %d", fd);
     266        if (vfs_stat(fd, &st) != EOK) {
     267                ddf_msg(LVL_ERROR, "Unable to vfs_stat %d", fd);
    268268                goto cleanup;
    269269        }
  • uspace/lib/bithenge/src/file.c

    rb5b5d84 r23a0368  
    4141#include <stdio.h>
    4242#include <stdlib.h>
    43 #include <sys/stat.h>
     43#include <vfs/vfs.h>
    4444#include <sys/types.h>
    4545#include <unistd.h>
     
    104104
    105105        struct stat stat;
    106         int rc = fstat(fd, &stat);
    107         if (rc != 0) {
     106        int rc = vfs_stat(fd, &stat);
     107        if (rc != EOK) {
    108108                if (needs_close)
    109109                        close(fd);
  • uspace/lib/c/generic/io/io.c

    rb5b5d84 r23a0368  
    4141#include <stdbool.h>
    4242#include <malloc.h>
    43 #include <sys/stat.h>
    4443#include <async.h>
    4544#include <io/kio.h>
     
    765764int fseek(FILE *stream, off64_t offset, int whence)
    766765{
     766        int rc;
     767
    767768        if (stream->error)
    768769                return -1;
     
    785786                break;
    786787        case SEEK_END:
    787                 if (fstat(stream->fd, &st) != EOK) {
    788                         /* errno was set by fstat() */
     788                rc = vfs_stat(stream->fd, &st);
     789                if (rc != EOK) {
     790                        errno = rc;
    789791                        stream->error = true;
    790792                        return -1;     
  • uspace/lib/c/generic/vfs/vfs.c

    rb5b5d84 r23a0368  
    641641/** Get file status.
    642642 *
    643  * @param fildes File descriptor
     643 * @param file File descriptor
    644644 * @param stat Place to store file information
    645645 *
    646  * @return 0 on success, -1 on error and sets errno.
    647  */
    648 int fstat(int fildes, struct stat *stat)
     646 * @return EOK on success or a negative error code otherwise.
     647 */
     648int vfs_stat(int file, struct stat *stat)
    649649{
    650650        sysarg_t rc;
     
    653653        async_exch_t *exch = vfs_exchange_begin();
    654654       
    655         req = async_send_1(exch, VFS_IN_STAT, fildes, NULL);
     655        req = async_send_1(exch, VFS_IN_STAT, file, NULL);
    656656        rc = async_data_read_start(exch, (void *) stat, sizeof(struct stat));
    657657        if (rc != EOK) {
     
    663663                if (rc_orig != EOK)
    664664                        rc = rc_orig;
    665                 if (rc != EOK) {
    666                         errno = rc;
    667                         return -1;
    668                 }
    669665               
    670                 return 0;
     666                return rc;
    671667        }
    672668       
     
    674670        async_wait_for(req, &rc);
    675671       
    676         if (rc != EOK) {
    677                 errno = rc;
    678                 return -1;
    679         }
    680        
    681         return 0;
     672        return rc;
    682673}
    683674
     
    687678 * @param stat Place to store file information
    688679 *
    689  * @return 0 on success, -1 on error and sets errno.
    690  */
    691 int stat(const char *path, struct stat *stat)
    692 {
    693         int fd = vfs_lookup(path, 0);
    694         if (fd < 0) {
    695                 errno = fd;
    696                 return -1;
    697         }
    698        
    699         int rc = fstat(fd, stat);
    700         if (rc != EOK) {
    701                 close(fd);
    702                 errno = rc;
    703                 rc = -1;
    704         } else
    705                 rc = close(fd);
     680 * @return EOK on success or a negative error code otherwise.
     681 */
     682int vfs_stat_path(const char *path, struct stat *stat)
     683{
     684        int file = vfs_lookup(path, 0);
     685        if (file < 0)
     686                return file;
     687       
     688        int rc = vfs_stat(file, stat);
     689
     690        close(file);
    706691
    707692        return rc;
     
    10571042 * @return On success returns session pointer. On error returns @c NULL.
    10581043 */
    1059 async_sess_t *vfs_fd_session(int fildes, iface_t iface)
     1044async_sess_t *vfs_fd_session(int file, iface_t iface)
    10601045{
    10611046        struct stat stat;
    1062         int rc = fstat(fildes, &stat);
     1047        int rc = vfs_stat(file, &stat);
    10631048        if (rc != 0)
    10641049                return NULL;
     
    11221107                child = pa;
    11231108
    1124                 rc = stat(child, &st);
     1109                rc = vfs_stat_path(child, &st);
    11251110                if (rc != 0) {
    11261111                        free(child);
     
    11521137        struct stat st;
    11531138
    1154         int rc = stat("/", &st);
     1139        int rc = vfs_stat_path("/", &st);
    11551140        if (rc != 0)
    11561141                return rc;
     
    11651150 * @param file File located on the queried file system
    11661151 * @param st Buffer for storing information
    1167  * @return 0 on success. On error -1 is returned and errno is set.
     1152 * @return EOK on success or a negative error code otherwise.
    11681153 */
    11691154int vfs_statfs(int file, struct statfs *st)
  • uspace/lib/c/include/sys/stat.h

    rb5b5d84 r23a0368  
    3636#define LIBC_SYS_STAT_H_
    3737
    38 #include <sys/types.h>
    39 #include <stdbool.h>
    4038#include <ipc/vfs.h>
    41 #include <ipc/loc.h>
    4239
    43 struct stat {
    44         fs_handle_t fs_handle;
    45         service_id_t service_id;
    46         fs_index_t index;
    47         unsigned int lnkcnt;
    48         bool is_file;
    49         bool is_directory;
    50         aoff64_t size;
    51         service_id_t service;
    52 };
    53 
    54 extern int fstat(int, struct stat *);
    55 extern int stat(const char *, struct stat *);
    5640extern int mkdir(const char *, mode_t);
    5741
  • uspace/lib/c/include/vfs/vfs.h

    rb5b5d84 r23a0368  
    4949};
    5050
     51struct stat {
     52        fs_handle_t fs_handle;
     53        service_id_t service_id;
     54        fs_index_t index;
     55        unsigned int lnkcnt;
     56        bool is_file;
     57        bool is_directory;
     58        aoff64_t size;
     59        service_id_t service;
     60};
     61
    5162struct statfs {
    5263        char fs_name[FS_NAME_MAXLEN + 1];
     
    7990extern int vfs_root(void);
    8091extern void vfs_root_set(int);
     92extern int vfs_stat(int, struct stat *);
     93extern int vfs_stat_path(const char *, struct stat *);
    8194extern int vfs_statfs(int, struct statfs *);
    8295extern int vfs_statfs_path(const char *, struct statfs *);
  • uspace/lib/posix/source/internal/common.h

    rb5b5d84 r23a0368  
    5959})
    6060
     61/* Convert error code to positive errno and -1 return value */
     62#define rcerrno(func, ...) ({ \
     63        int rc = func(__VA_ARGS__); \
     64        if (rc < 0) \
     65                errno = -rc; \
     66        rc; \
     67})
     68
    6169extern aoff64_t posix_pos[MAX_OPEN_FILES];
    6270
  • uspace/lib/posix/source/sys/stat.c

    rb5b5d84 r23a0368  
    3939#include "../internal/common.h"
    4040#include "posix/sys/stat.h"
    41 #include "libc/sys/stat.h"
     41#include "libc/vfs/vfs.h"
    4242
    4343#include "posix/errno.h"
     
    8080{
    8181        struct stat hst;
    82         int rc = negerrno(fstat, fd, &hst);
     82        int rc = rcerrno(vfs_stat, fd, &hst);
    8383        if (rc < 0)
    84                 return rc;
     84                return -1;
    8585        stat_to_posix(st, &hst);
    8686        return 0;
     
    110110{
    111111        struct stat hst;
    112         int rc = negerrno(stat, path, &hst);
     112        int rc = rcerrno(vfs_stat_path, path, &hst);
    113113        if (rc < 0)
    114                 return rc;
     114                return -1;
    115115        stat_to_posix(st, &hst);
    116116        return 0;
  • uspace/lib/posix/source/unistd.c

    rb5b5d84 r23a0368  
    4848#include "libc/malloc.h"
    4949#include "libc/vfs/vfs.h"
    50 #include "libc/sys/stat.h"
    5150
    5251aoff64_t posix_pos[MAX_OPEN_FILES];
     
    221220{
    222221        struct stat st;
     222        int rc;
    223223
    224224        switch (whence) {
     
    230230                break;
    231231        case SEEK_END:
    232                 if (fstat(fildes, &st) != EOK) {
    233                         errno = -errno;
     232                rc = rcerrno(vfs_stat, fildes, &st);
     233                if (rc != EOK)
    234234                        return -1;
    235                 }
    236235                posix_pos[fildes] = st.size + offset;
    237236                break;
  • uspace/srv/devman/driver.c

    rb5b5d84 r23a0368  
    3434#include <errno.h>
    3535#include <fcntl.h>
    36 #include <sys/stat.h>
    3736#include <io/log.h>
     37#include <vfs/vfs.h>
    3838#include <loc.h>
    3939#include <str_error.h>
     
    142142        /* Check whether the driver's binary exists. */
    143143        struct stat s;
    144         if (stat(drv->binary_path, &s) != 0) {
     144        if (vfs_stat_path(drv->binary_path, &s) != EOK) {
    145145                log_msg(LOG_DEFAULT, LVL_ERROR, "Driver not found at path `%s'.",
    146146                    drv->binary_path);
  • uspace/srv/devman/match.c

    rb5b5d84 r23a0368  
    3737#include <str_error.h>
    3838#include <sys/types.h>
    39 #include <sys/stat.h>
     39#include <vfs/vfs.h>
    4040
    4141#include "devman.h"
     
    211211        opened = true;
    212212       
    213         if (fstat(fd, &st) != EOK) {
     213        if (vfs_stat(fd, &st) != EOK) {
    214214                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to fstat %d: %s.", fd,
    215215                    str_error(errno));
Note: See TracChangeset for help on using the changeset viewer.