Changeset 438f355 in mainline


Ignore:
Timestamp:
2017-04-02T21:24:22Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ca7506f
Parents:
c23275a
Message:

Move mtab emulation to its own file

Location:
uspace/lib/c
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    rc23275a r438f355  
    149149        generic/udebug.c \
    150150        generic/vfs/canonify.c \
     151        generic/vfs/inbox.c \
     152        generic/vfs/mtab.c \
    151153        generic/vfs/vfs.c \
    152154        generic/rcu.c \
    153155        generic/setjmp.c \
    154         generic/vfs/inbox.c \
    155156        generic/stack.c \
    156157        generic/stacktrace.c \
  • uspace/lib/c/generic/vfs/vfs.c

    rc23275a r438f355  
    3333 */
    3434
     35#include <vfs/vfs.h>
    3536#include <vfs/canonify.h>
    36 #include <vfs/vfs.h>
    3737#include <vfs/vfs_mtab.h>
    3838#include <vfs/vfs_sess.h>
    3939#include <macros.h>
    4040#include <stdlib.h>
    41 #include <dirent.h>
    4241#include <sys/types.h>
    4342#include <ipc/services.h>
     
    882881}
    883882
    884 static void process_mp(const char *path, struct stat *stat, list_t *mtab_list)
    885 {
    886         mtab_ent_t *ent;
    887 
    888         ent = (mtab_ent_t *) malloc(sizeof(mtab_ent_t));
    889         if (!ent)
    890                 return;
    891 
    892         link_initialize(&ent->link);
    893         str_cpy(ent->mp, sizeof(ent->mp), path);
    894         ent->service_id = stat->service_id;
    895 
    896         struct statfs stfs;
    897         if (vfs_statfs_path(path, &stfs) == EOK)
    898                 str_cpy(ent->fs_name, sizeof(ent->fs_name), stfs.fs_name);
    899         else
    900                 str_cpy(ent->fs_name, sizeof(ent->fs_name), "?");
    901        
    902         list_append(&ent->link, mtab_list);
    903 }
    904 
    905 static int vfs_get_mtab_visit(const char *path, list_t *mtab_list,
    906     fs_handle_t fs_handle, service_id_t service_id)
    907 {
    908         DIR *dir;
    909         struct dirent *dirent;
    910 
    911         dir = opendir(path);
    912         if (!dir)
    913                 return ENOENT;
    914 
    915         while ((dirent = readdir(dir)) != NULL) {
    916                 char *child;
    917                 struct stat st;
    918                 int rc;
    919 
    920                 rc = asprintf(&child, "%s/%s", path, dirent->d_name);
    921                 if (rc < 0) {
    922                         closedir(dir);
    923                         return rc;
    924                 }
    925 
    926                 char *pa = vfs_absolutize(child, NULL);
    927                 if (!pa) {
    928                         free(child);
    929                         closedir(dir);
    930                         return ENOMEM;
    931                 }
    932 
    933                 free(child);
    934                 child = pa;
    935 
    936                 rc = vfs_stat_path(child, &st);
    937                 if (rc != 0) {
    938                         free(child);
    939                         closedir(dir);
    940                         return rc;
    941                 }
    942 
    943                 if (st.fs_handle != fs_handle || st.service_id != service_id) {
    944                         /*
    945                          * We have discovered a mountpoint.
    946                          */
    947                         process_mp(child, &st, mtab_list);
    948                 }
    949 
    950                 if (st.is_directory) {
    951                         (void) vfs_get_mtab_visit(child, mtab_list,
    952                             st.fs_handle, st.service_id);
    953                 }
    954 
    955                 free(child);
    956         }
    957 
    958         closedir(dir);
    959         return EOK;
    960 }
    961 
    962 int vfs_get_mtab_list(list_t *mtab_list)
    963 {
    964         struct stat st;
    965 
    966         int rc = vfs_stat_path("/", &st);
    967         if (rc != 0)
    968                 return rc;
    969 
    970         process_mp("/", &st, mtab_list);
    971 
    972         return vfs_get_mtab_visit("/", mtab_list, st.fs_handle, st.service_id);
    973 }
    974 
    975883/** Get filesystem statistics.
    976884 *
  • uspace/lib/c/include/vfs/vfs.h

    rc23275a r438f355  
    7979extern int vfs_fhandle(FILE *, int *);
    8080
    81 extern int vfs_get_mtab_list(list_t *mtab_list);
    82 
    8381extern async_exch_t *vfs_exchange_begin(void);
    8482extern void vfs_exchange_end(async_exch_t *);
  • uspace/lib/c/include/vfs/vfs_mtab.h

    rc23275a r438f355  
    4747} mtab_ent_t;
    4848
     49extern int vfs_get_mtab_list(list_t *);
     50
    4951#endif
    5052
Note: See TracChangeset for help on using the changeset viewer.