Changeset 8ffedd8 in mainline for uspace/lib/c/generic/vfs/vfs.c


Ignore:
Timestamp:
2017-03-16T16:50:29Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5a2b765
Parents:
35b7d86e
Message:

Partially revive support for mount table listing and walking

This implementation is purely client-based. Using a simple file system
traversal, the library figures out what are the actual mountpoints. It
only discovers mountpoints that it can reach from its VFS root.

The benefit is that this works and produces reasonable results even in
the environment of per-client VFS roots, whereas a global mount table
would present paths that might not make any sense to the client
(notwithstanding the fact that VFS no longer knows the mountpoint
paths).

Listing of file system names is still broken as of this commit.

File:
1 edited

Legend:

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

    r35b7d86e r8ffedd8  
    3535#include <vfs/canonify.h>
    3636#include <vfs/vfs.h>
     37#include <vfs/vfs_mtab.h>
    3738#include <vfs/vfs_sess.h>
    3839#include <macros.h>
     
    11041105}
    11051106
     1107static void process_mp(const char *path, struct stat *stat, list_t *mtab_list)
     1108{
     1109        mtab_ent_t *ent;
     1110
     1111        ent = (mtab_ent_t *) malloc(sizeof(mtab_ent_t));
     1112        if (!ent)
     1113                return;
     1114
     1115        link_initialize(&ent->link);
     1116        str_cpy(ent->mp, sizeof(ent->mp), path);
     1117        str_cpy(ent->fs_name, sizeof(ent->fs_name), "fixme");
     1118        ent->service_id = stat->service_id;
     1119       
     1120        list_append(&ent->link, mtab_list);
     1121}
     1122
     1123static int vfs_get_mtab_visit(const char *path, list_t *mtab_list,
     1124    fs_handle_t fs_handle, service_id_t service_id)
     1125{
     1126        DIR *dir;
     1127        struct dirent *dirent;
     1128
     1129        dir = opendir(path);
     1130        if (!dir)
     1131                return -1;
     1132
     1133        while ((dirent = readdir(dir)) != NULL) {
     1134                char *child;
     1135                struct stat st;
     1136                int rc;
     1137
     1138                rc = asprintf(&child, "%s/%s", path, dirent->d_name);
     1139                if (rc < 0) {
     1140                        closedir(dir);
     1141                        errno = rc;
     1142                        return -1;
     1143                }
     1144
     1145                rc = stat(child, &st);
     1146                if (rc != 0) {
     1147                        free(child);
     1148                        closedir(dir);
     1149                        errno = rc;
     1150                        return -1;
     1151                }
     1152
     1153                if (st.fs_handle != fs_handle || st.service_id != service_id) {
     1154                        /*
     1155                         * We have discovered a mountpoint.
     1156                         */
     1157                        process_mp(child, &st, mtab_list);
     1158                }
     1159
     1160                if (st.is_directory) {
     1161                        (void) vfs_get_mtab_visit(child, mtab_list,
     1162                            st.fs_handle, st.service_id);
     1163                }
     1164
     1165                free(child);
     1166        }
     1167
     1168        closedir(dir);
     1169        return EOK;
     1170}
     1171
    11061172int vfs_get_mtab_list(list_t *mtab_list)
    11071173{
    1108         sysarg_t rc = ENOTSUP;
    1109        
    1110         return rc;
     1174        struct stat st;
     1175
     1176        int rc = stat("/", &st);
     1177        if (rc != 0)
     1178                return rc;
     1179
     1180        process_mp("/", &st, mtab_list);
     1181
     1182        return vfs_get_mtab_visit("", mtab_list, st.fs_handle, st.service_id);
    11111183}
    11121184
Note: See TracChangeset for help on using the changeset viewer.