struct MountsPublicInterface* mm_mount_bypath( const char* path ){ struct MountInfo* mount_info = mm_mountinfo_bypath(path); if ( mount_info ) return mount_info->mount; else return NULL; }
struct MountsPublicInterface* mm_mount_bypath( struct MountsManager *mounts_manager, const char* path){ int located_mount_index; struct MountInfo* mount_info = mm_mountinfo_bypath(mounts_manager, path, &located_mount_index); (void)located_mount_index; if ( mount_info ) return mount_info->mount; else return NULL; }
int mm_mount_remove( struct MountsManager *mounts_manager, const char* path ){ int located_index; struct MountInfo* mount = mm_mountinfo_bypath( mounts_manager, path, &located_index ); if (mount!=NULL){ free(mount->mount); free(mount->mount_path); free(mount); if ( DynArraySet(&mounts_manager->mount_items, located_index, NULL) != 0 ) return 0; } return -1; /*todo implement it*/ }
const char* mm_convert_path_to_mount(const char* full_path){ struct MountInfo* mount_info = mm_mountinfo_bypath( full_path ); if ( mount_info ){ if ( mount_info->mount->mount_id == EChannelsMountId ){ /*for channels mount do not use path transformation*/ return full_path; } else{ if ( strlen(mount_info->mount_path) == 1 && mount_info->mount_path[0] == '/' ) return full_path; /*use paths mounted on root '/' as is*/ else{ /*get path relative to mount path. * for example: full_path="/tmp/fire", mount_path="/tmp", returned="/fire" */ return &full_path[ strlen( mount_info->mount_path ) ]; } } } else return NULL; }
int mm_mount_add( struct MountsManager *mounts_manager, const char* path, struct MountsPublicInterface* filesystem_mount, char expect_absolute_path){ /*check if the same mountpoint haven't used by another mount*/ int located_index; struct MountInfo* existing_mount = mm_mountinfo_bypath( mounts_manager, path, &located_index ); if ( existing_mount && !strcmp(existing_mount->mount_path, path) ){ SET_ERRNO(EBUSY); return -1; } (void)located_index; /*create mount*/ struct MountInfo *new_mount_info = malloc(sizeof(struct MountInfo)); new_mount_info->mount_path = strdup(path); new_mount_info->expect_absolute_path = expect_absolute_path; new_mount_info->mount = filesystem_mount; /*add mount*/ return ! DynArraySet( &mounts_manager->mount_items, mounts_manager->mount_items.num_entries, new_mount_info ); }
const char* mm_convert_path_to_mount(struct MountsManager *mounts_manager, const char* full_path){ int located_mount_index; struct MountInfo* mount_info = mm_mountinfo_bypath( mounts_manager, full_path, &located_mount_index ); if ( mount_info ){ if ( mount_info->expect_absolute_path == EAbsolutePathExpected ){ /*for mounts which do not use path transformation*/ return full_path; } else{ if ( strlen(mount_info->mount_path) == 1 && mount_info->mount_path[0] == '/' ) return full_path; /*use paths mounted on root '/' as is*/ else{ /*get path relative to mount path. * for example: full_path="/tmp/fire", mount_path="/tmp", returned="/fire" */ return &full_path[ strlen( mount_info->mount_path ) ]; } } } else return NULL; }