Changeset b82985e in mainline for uspace/srv/volsrv/part.c


Ignore:
Timestamp:
2018-10-12T13:16:04Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d09eeb2
Parents:
6d00aff
Message:

Inserting volume by path.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/volsrv/part.c

    r6d00aff rb82985e  
    297297}
    298298
    299 /** Mount partition.
     299/** Determine actual mount path to be used for a partition.
    300300 *
    301301 * @param part Partition
    302  */
    303 static errno_t vol_part_mount(vol_part_t *part)
     302 * @param rpath Place to store pointer to newly allocated string or @c NULL
     303 *              if volume should not be mounted
     304 * @param rauto Place to store boolean flag whether mount point is automatic
     305 *
     306 * @return EOK on success, ENOMEM if out of memory
     307 */
     308static errno_t vol_part_determine_mount_path(vol_part_t *part, char **rpath,
     309    bool *rauto)
    304310{
    305311        const char *cfg_mp;
    306312        char *mp;
     313        bool mp_auto;
    307314        int err;
    308         bool mp_auto;
    309         errno_t rc;
    310315
    311316        /* Get configured mount point */
     
    324329                if (str_size(part->label) < 1) {
    325330                        /* Don't mount nameless volumes */
    326                         log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting nameless volume.");
     331                        *rpath = NULL;
     332                        *rauto = false;
    327333                        return EOK;
    328334                }
     
    335341                }
    336342
     343                mp_auto = true;
     344        } else if (str_cmp(cfg_mp, "None") == 0 || str_cmp(cfg_mp, "none") == 0) {
     345                mp = NULL;
     346                mp_auto = false;
     347        } else {
     348                mp = str_dup(cfg_mp);
     349                mp_auto = false;
     350        }
     351
     352        *rpath = mp;
     353        *rauto = mp_auto;
     354        return EOK;
     355}
     356
     357/** Mount partition.
     358 *
     359 * @param part Partition
     360 */
     361static errno_t vol_part_mount(vol_part_t *part)
     362{
     363        char *mp;
     364        bool mp_auto;
     365        errno_t rc;
     366
     367        rc = vol_part_determine_mount_path(part, &mp, &mp_auto);
     368        if (rc != EOK) {
     369                log_msg(LOG_DEFAULT, LVL_ERROR, "Error determining mount point.\n");
     370                return rc;
     371        }
     372
     373        if (mp == NULL) {
     374                log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting volume.");
     375                return EOK;
     376        }
     377
     378        if (mp_auto) {
     379                /* Create directory for automatic mount point */
    337380                log_msg(LOG_DEFAULT, LVL_NOTE, "Create mount point '%s'", mp);
    338381                rc = vfs_link_path(mp, KIND_DIRECTORY, NULL);
     
    343386                        return EIO;
    344387                }
    345 
    346                 mp_auto = true;
    347         } else if (str_cmp(cfg_mp, "None") == 0 || str_cmp(cfg_mp, "none") == 0) {
    348                 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting volume.");
    349                 return EOK;
    350         } else {
    351                 mp = str_dup(cfg_mp);
    352                 mp_auto = false;
    353388        }
    354389
     
    545580}
    546581
     582/** Find partition by filesystem path.
     583 *
     584 * @param parts Partitions
     585 * @param path Filesystem path
     586 * @param rpart Place to store pointer to partition
     587 * @return EOK on success, ENOENT if not found, ENOMEM if out of memory
     588 */
     589errno_t vol_part_find_by_path_ref(vol_parts_t *parts, const char *path,
     590    vol_part_t **rpart)
     591{
     592        errno_t rc;
     593        char *mpath;
     594        bool mauto;
     595
     596        fibril_mutex_lock(&parts->lock);
     597
     598        list_foreach(parts->parts, lparts, vol_part_t, part) {
     599                rc = vol_part_determine_mount_path(part, &mpath, &mauto);
     600                if (rc != EOK) {
     601                        fibril_mutex_unlock(&parts->lock);
     602                        return ENOMEM;
     603                }
     604
     605                if (mpath != NULL && str_cmp(mpath, path) == 0) {
     606                        /* Add reference */
     607                        refcount_up(&part->refcnt);
     608                        fibril_mutex_unlock(&parts->lock);
     609                        free(mpath);
     610                        *rpart = part;
     611                        return EOK;
     612                }
     613
     614                if (mpath != NULL)
     615                        free(mpath);
     616        }
     617
     618        fibril_mutex_unlock(&parts->lock);
     619        return ENOENT;
     620}
     621
    547622void vol_part_del_ref(vol_part_t *part)
    548623{
Note: See TracChangeset for help on using the changeset viewer.