Changeset 23a0368 in mainline for uspace/lib/c


Ignore:
Timestamp:
2017-03-30T19:52:23Z (8 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/lib/c
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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 *);
Note: See TracChangeset for help on using the changeset viewer.