Changeset 9c2c7d2 in mainline for uspace/srv/volsrv


Ignore:
Timestamp:
2017-07-06T15:52:15Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5cd1eb9a
Parents:
d858a660
Message:

Fdisk should be able to set volume label for newly created partitions.

Location:
uspace/srv/volsrv
Files:
5 edited

Legend:

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

    rd858a660 r9c2c7d2  
    4040#include <stdarg.h>
    4141#include <stdlib.h>
     42#include <str.h>
    4243#include <str_error.h>
    4344#include <task.h>
     
    101102
    102103
    103 int volsrv_part_mkfs(service_id_t sid, vol_fstype_t fstype)
     104int volsrv_part_mkfs(service_id_t sid, vol_fstype_t fstype, const char *label)
    104105{
    105106        const char *cmd;
     
    131132                return rc;
    132133
    133         rc = cmd_runl(cmd, cmd, svc_name, NULL);
     134        if (str_size(label) > 0)
     135                rc = cmd_runl(cmd, cmd, "--label", label, svc_name, NULL);
     136        else
     137                rc = cmd_runl(cmd, cmd, svc_name, NULL);
     138
    134139        free(svc_name);
    135140        return rc;
    136141}
    137142
     143void volsrv_part_get_lsupp(vol_fstype_t fstype, vol_label_supp_t *vlsupp)
     144{
     145        vlsupp->supported = false;
     146
     147        switch (fstype) {
     148        case fs_fat:
     149                vlsupp->supported = true;
     150                break;
     151        case fs_exfat:
     152        case fs_minix:
     153        case fs_ext4:
     154        case fs_cdfs:
     155                break;
     156        }
     157}
     158
    138159/** @}
    139160 */
  • uspace/srv/volsrv/mkfs.h

    rd858a660 r9c2c7d2  
    4141#include <types/vol.h>
    4242
    43 extern int volsrv_part_mkfs(service_id_t, vol_fstype_t);
     43extern int volsrv_part_mkfs(service_id_t, vol_fstype_t, const char *);
     44extern void volsrv_part_get_lsupp(vol_fstype_t, vol_label_supp_t *);
    4445
    4546#endif
  • uspace/srv/volsrv/part.c

    rd858a660 r9c2c7d2  
    143143}
    144144
    145 static int vol_part_add_locked(service_id_t sid)
    146 {
    147         vol_part_t *part;
     145static int vol_part_probe(vol_part_t *part)
     146{
    148147        bool empty;
    149148        vfs_fs_probe_info_t info;
    150149        struct fsname_type *fst;
     150        char *label;
     151        int rc;
     152
     153        log_msg(LOG_DEFAULT, LVL_NOTE, "Probe partition %s", part->svc_name);
     154
     155        assert(fibril_mutex_is_locked(&vol_parts_lock));
     156
     157        fst = &fstab[0];
     158        while (fst->name != NULL) {
     159                rc = vfs_fsprobe(fst->name, part->svc_id, &info);
     160                if (rc == EOK)
     161                        break;
     162                ++fst;
     163        }
     164
     165        if (fst->name != NULL) {
     166                log_msg(LOG_DEFAULT, LVL_NOTE, "Found %s, label '%s'",
     167                    fst->name, info.label);
     168                label = str_dup(info.label);
     169                if (label == NULL) {
     170                        rc = ENOMEM;
     171                        goto error;
     172                }
     173
     174                part->pcnt = vpc_fs;
     175                part->fstype = fst->fstype;
     176                part->label = label;
     177        } else {
     178                log_msg(LOG_DEFAULT, LVL_NOTE, "Partition does not contain "
     179                    "a recognized file system.");
     180
     181                rc = volsrv_part_is_empty(part->svc_id, &empty);
     182                if (rc != EOK) {
     183                        log_msg(LOG_DEFAULT, LVL_ERROR, "Failed determining if "
     184                            "partition is empty.");
     185                        rc = EIO;
     186                        goto error;
     187                }
     188
     189                label = str_dup("");
     190                if (label == NULL) {
     191                        rc = ENOMEM;
     192                        goto error;
     193                }
     194
     195                part->pcnt = empty ? vpc_empty : vpc_unknown;
     196                part->label = label;
     197        }
     198
     199        return EOK;
     200
     201error:
     202        return rc;
     203}
     204
     205static int vol_part_add_locked(service_id_t sid)
     206{
     207        vol_part_t *part;
    151208        int rc;
    152209
     
    171228        }
    172229
    173         log_msg(LOG_DEFAULT, LVL_NOTE, "Probe partition %s", part->svc_name);
    174 
    175         fst = &fstab[0];
    176         while (fst->name != NULL) {
    177                 rc = vfs_fsprobe(fst->name, sid, &info);
    178                 if (rc == EOK)
    179                         break;
    180                 ++fst;
    181         }
    182 
    183         if (fst->name != NULL) {
    184                 log_msg(LOG_DEFAULT, LVL_NOTE, "Found %s, label '%s'",
    185                     fst->name, info.label);
    186                 part->pcnt = vpc_fs;
    187                 part->fstype = fst->fstype;
    188                 part->label = str_dup(info.label);
    189                 if (part->label == NULL)
    190                         goto error;
    191         } else {
    192                 log_msg(LOG_DEFAULT, LVL_NOTE, "Partition does not contain "
    193                     "a recognized file system.");
    194 
    195                 rc = volsrv_part_is_empty(sid, &empty);
    196                 if (rc != EOK) {
    197                         log_msg(LOG_DEFAULT, LVL_ERROR, "Failed determining if "
    198                             "partition is empty.");
    199                         goto error;
    200                 }
    201 
    202                 part->pcnt = empty ? vpc_empty : vpc_unknown;
    203                 part->label = str_dup("");
    204                 if (part->label == NULL)
    205                         goto error;
    206         }
     230        rc = vol_part_probe(part);
     231        if (rc != EOK)
     232                goto error;
    207233
    208234        list_append(&part->lparts, &vol_parts);
     
    311337}
    312338
    313 int vol_part_mkfs_part(vol_part_t *part, vol_fstype_t fstype)
     339int vol_part_mkfs_part(vol_part_t *part, vol_fstype_t fstype,
     340    const char *label)
    314341{
    315342        int rc;
     
    317344        log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_part()");
    318345
    319         rc = volsrv_part_mkfs(part->svc_id, fstype);
     346        fibril_mutex_lock(&vol_parts_lock);
     347
     348        rc = volsrv_part_mkfs(part->svc_id, fstype, label);
    320349        if (rc != EOK) {
    321350                log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_part() - failed %d",
    322351                    rc);
     352                fibril_mutex_unlock(&vol_parts_lock);
    323353                return rc;
    324354        }
    325355
    326         part->pcnt = vpc_fs;
    327         part->fstype = fstype;
     356        /*
     357         * Re-probe the partition to update information. This is needed since
     358         * the FS can make conversions of the volume label (e.g. make it
     359         * uppercase).
     360         */
     361        rc = vol_part_probe(part);
     362        if (rc != EOK) {
     363                fibril_mutex_unlock(&vol_parts_lock);
     364                return rc;
     365        }
     366
     367        fibril_mutex_unlock(&vol_parts_lock);
    328368        return EOK;
    329369}
  • uspace/srv/volsrv/part.h

    rd858a660 r9c2c7d2  
    4949extern int vol_part_find_by_id(service_id_t, vol_part_t **);
    5050extern int vol_part_empty_part(vol_part_t *);
    51 extern int vol_part_mkfs_part(vol_part_t *, vol_fstype_t);
     51extern int vol_part_mkfs_part(vol_part_t *, vol_fstype_t, const char *);
    5252extern int vol_part_get_info(vol_part_t *, vol_part_info_t *);
    5353
  • uspace/srv/volsrv/volsrv.c

    rd858a660 r9c2c7d2  
    4646#include <types/vol.h>
    4747
     48#include "mkfs.h"
    4849#include "part.h"
    4950
     
    131132        async_answer_0(iid, EOK);
    132133}
    133 
    134134
    135135static void vol_part_info_srv(ipc_callid_t iid, ipc_call_t *icall)
     
    204204}
    205205
     206static void vol_part_get_lsupp_srv(ipc_callid_t iid, ipc_call_t *icall)
     207{
     208        vol_fstype_t fstype;
     209        vol_label_supp_t vlsupp;
     210        int rc;
     211
     212        fstype = IPC_GET_ARG1(*icall);
     213        log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_get_lsupp_srv(%u)",
     214            fstype);
     215
     216        volsrv_part_get_lsupp(fstype, &vlsupp);
     217
     218        ipc_callid_t callid;
     219        size_t size;
     220        if (!async_data_read_receive(&callid, &size)) {
     221                async_answer_0(callid, EREFUSED);
     222                async_answer_0(iid, EREFUSED);
     223                return;
     224        }
     225
     226        if (size != sizeof(vol_label_supp_t)) {
     227                async_answer_0(callid, EINVAL);
     228                async_answer_0(iid, EINVAL);
     229                return;
     230        }
     231
     232        rc = async_data_read_finalize(callid, &vlsupp,
     233            min(size, sizeof(vlsupp)));
     234        if (rc != EOK) {
     235                async_answer_0(callid, rc);
     236                async_answer_0(iid, rc);
     237                return;
     238        }
     239
     240        async_answer_0(iid, EOK);
     241}
     242
     243
    206244static void vol_part_mkfs_srv(ipc_callid_t iid, ipc_call_t *icall)
    207245{
     
    209247        vol_part_t *part;
    210248        vol_fstype_t fstype;
     249        char *label;
    211250        int rc;
    212251
     
    214253        fstype = IPC_GET_ARG2(*icall);
    215254
     255        rc = async_data_write_accept((void **)&label, true, 0, VOL_LABEL_MAXLEN,
     256            0, NULL);
     257        if (rc != EOK) {
     258                async_answer_0(iid, rc);
     259                return;
     260        }
     261
     262        printf("vol_part_mkfs_srv: label=%p\n", label);
     263        if (label!=NULL) printf("vol_part_mkfs_srv: label='%s'\n", label);
     264
    216265        rc = vol_part_find_by_id(sid, &part);
    217266        if (rc != EOK) {
     267                free(label);
    218268                async_answer_0(iid, ENOENT);
    219269                return;
    220270        }
    221271
    222         rc = vol_part_mkfs_part(part, fstype);
    223         if (rc != EOK) {
    224                 async_answer_0(iid, rc);
    225                 return;
    226         }
    227 
    228         part->pcnt = vpc_fs;
    229         part->fstype = fstype;
    230 
     272        rc = vol_part_mkfs_part(part, fstype, label);
     273        if (rc != EOK) {
     274                free(label);
     275                async_answer_0(iid, rc);
     276                return;
     277        }
     278
     279        free(label);
    231280        async_answer_0(iid, EOK);
    232281}
     
    263312                        vol_part_empty_srv(callid, &call);
    264313                        break;
     314                case VOL_PART_LSUPP:
     315                        vol_part_get_lsupp_srv(callid, &call);
     316                        break;
    265317                case VOL_PART_MKFS:
    266318                        vol_part_mkfs_srv(callid, &call);
Note: See TracChangeset for help on using the changeset viewer.