Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 3faa03d in mainline


Ignore:
Timestamp:
2015-07-02T16:30:16Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
1626cd4
Parents:
78d50bd
Message:

Liblabel reading GPT and MBR partitions (primary only).

Location:
uspace
Files:
5 added
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/label/Makefile

    r78d50bd r3faa03d  
    3333
    3434SOURCES = \
     35        src/mbr.c \
     36        src/gpt.c \
    3537        src/label.c
    3638
  • uspace/lib/label/include/std/gpt.h

    r78d50bd r3faa03d  
    11/*
    2  * Copyright (c) 2009 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3333 */
    3434
    35 #ifndef __GPT_H__
    36 #define __GPT_H__
     35#ifndef LIBLABEL_STD_GPT_H_
     36#define LIBLABEL_STD_GPT_H_
    3737
    3838#include <sys/types.h>
  • uspace/lib/label/include/types/liblabel.h

    r78d50bd r3faa03d  
    4242#include <vol.h>
    4343
     44typedef struct label label_t;
     45typedef struct label_part label_part_t;
     46typedef struct label_part_info label_part_info_t;
     47typedef struct label_part_spec label_part_spec_t;
     48
     49/** Ops for individual label type */
     50typedef struct {
     51        int (*open)(service_id_t, label_t **);
     52        int (*create)(service_id_t, label_t **);
     53        void (*close)(label_t *);
     54        int (*destroy)(label_t *);
     55        label_part_t *(*part_first)(label_t *);
     56        label_part_t *(*part_next)(label_part_t *);
     57        void (*part_get_info)(label_part_t *, label_part_info_t *);
     58        int (*part_create)(label_t *, label_part_spec_t *, label_part_t **);
     59        int (*part_destroy)(label_part_t *);
     60} label_ops_t;
     61
    4462typedef struct {
    4563        /** Disk contents */
     
    4967} label_info_t;
    5068
    51 typedef struct {
     69struct label_part_info {
    5270        /** Address of first block */
    5371        aoff64_t block0;
    5472        /** Number of blocks */
    5573        aoff64_t nblocks;
    56 } label_part_info_t;
     74};
    5775
    5876/** Partition */
    59 typedef struct {
     77struct label_part {
    6078        /** Containing label */
    6179        struct label *label;
    6280        /** Link to label_t.parts */
    6381        link_t llabel;
    64 } label_part_t;
     82        aoff64_t block0;
     83        aoff64_t nblocks;
     84};
    6585
    6686/** Specification of new partition */
    67 typedef struct {
    68 } label_part_spec_t;
     87struct label_part_spec {
     88};
    6989
    7090/** Label instance */
    71 typedef struct label {
     91struct label {
     92        /** Label type ops */
     93        label_ops_t *ops;
     94        /** Label type */
     95        label_type_t ltype;
    7296        /** Partitions */
    7397        list_t parts; /* of label_part_t */
    74 } label_t;
     98};
    7599
    76100#endif
  • uspace/lib/label/src/label.c

    r78d50bd r3faa03d  
    4040#include <stdlib.h>
    4141
     42#include "gpt.h"
     43
     44static label_ops_t *probe_list[] = {
     45        &gpt_label_ops,
     46        NULL
     47};
     48
    4249int label_open(service_id_t sid, label_t **rlabel)
    4350{
    44         label_t *label;
     51        label_ops_t **ops;
     52        int rc;
    4553
    46         label = calloc(1, sizeof(label_t));
    47         if (label == NULL)
    48                 return ENOMEM;
     54        ops = &probe_list[0];
     55        while (ops[0] != NULL) {
     56                rc = ops[0]->open(sid, rlabel);
     57                if (rc == EOK)
     58                        return EOK;
     59                ++ops;
     60        }
    4961
    50         list_initialize(&label->parts);
    51         *rlabel = label;
    52         return EOK;
     62        return ENOTSUP;
    5363}
    5464
    5565int label_create(service_id_t sid, label_type_t ltype, label_t **rlabel)
    5666{
    57         label_t *label;
     67        label_ops_t *ops = NULL;
    5868
    59         label = calloc(1, sizeof(label_t));
    60         if (label == NULL)
    61                 return ENOMEM;
     69        switch (ltype) {
     70        case lt_gpt:
     71                ops = &gpt_label_ops;
     72                break;
     73        case lt_mbr:
     74                ops = NULL;
     75                break;
     76        }
    6277
    63         list_initialize(&label->parts);
    64         *rlabel = label;
    65         return EOK;
     78        if (ops == NULL)
     79                return ENOTSUP;
     80
     81        return ops->create(sid, rlabel);
    6682}
    6783
     
    7187                return;
    7288
    73         free(label);
     89        label->ops->close(label);
    7490}
    7591
    7692int label_destroy(label_t *label)
    7793{
    78         free(label);
    79         return EOK;
     94        return label->ops->destroy(label);
    8095}
    8196
     
    8398{
    8499        memset(linfo, 0, sizeof(label_info_t));
    85         linfo->dcnt = dc_empty;
     100        linfo->dcnt = dc_label;
     101        linfo->ltype = label->ltype;
    86102        return EOK;
    87103}
     
    89105label_part_t *label_part_first(label_t *label)
    90106{
    91         link_t *link;
    92 
    93         link = list_first(&label->parts);
    94         if (link == NULL)
    95                 return NULL;
    96 
    97         return list_get_instance(link, label_part_t, llabel);
     107        return label->ops->part_first(label);
    98108}
    99109
    100110label_part_t *label_part_next(label_part_t *part)
    101111{
    102         link_t *link;
    103 
    104         link = list_next(&part->llabel, &part->label->parts);
    105         if (link == NULL)
    106                 return NULL;
    107 
    108         return list_get_instance(link, label_part_t, llabel);
     112        return part->label->ops->part_next(part);
    109113}
    110114
    111115void label_part_get_info(label_part_t *part, label_part_info_t *pinfo)
    112116{
    113         pinfo->block0 = 0;
    114         pinfo->nblocks = 0;
     117        return part->label->ops->part_get_info(part, pinfo);
    115118}
    116119
     
    118121    label_part_t **rpart)
    119122{
    120         label_part_t *part;
    121 
    122         part = calloc(1, sizeof(label_part_t));
    123         if (part == NULL)
    124                 return ENOMEM;
    125 
    126         part->label = label;
    127         list_append(&part->llabel, &label->parts);
    128         *rpart = part;
    129         return EOK;
     123        return label->ops->part_create(label, pspec, rpart);
    130124}
    131125
    132126int label_part_destroy(label_part_t *part)
    133127{
    134         list_remove(&part->llabel);
    135         free(part);
    136         return EOK;
     128        return part->label->ops->part_destroy(part);
    137129}
    138130
  • uspace/srv/bd/part/guid_part/Makefile

    r78d50bd r3faa03d  
    2929USPACE_PREFIX = ../../../..
    3030LIBS = $(LIBBLOCK_PREFIX)/libblock.a
    31 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
     31EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBLABEL_PREFIX)/include
    3232
    3333# Correct name is 'guid_part' but must use this because of FAT 8.3 names.
  • uspace/srv/bd/part/guid_part/guid_part.c

    r78d50bd r3faa03d  
    6464#include <task.h>
    6565
    66 #include "gpt.h"
     66#include <std/gpt.h>
    6767
    6868#define NAME "guid_part"
  • uspace/srv/bd/vbd/disk.c

    r78d50bd r3faa03d  
    9696static int vbds_part_by_id(vbds_part_id_t partid, vbds_part_t **rpart)
    9797{
     98        log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_part_by_id(%zu)", partid);
     99
    98100        list_foreach(vbds_parts, lparts, vbds_part_t, part) {
     101                log_msg(LOG_DEFAULT, LVL_NOTE, "%zu == %zu ?", part->id, partid);
    99102                if (part->id == partid) {
     103                        log_msg(LOG_DEFAULT, LVL_NOTE, "Found match.");
    100104                        *rpart = part;
    101105                        return EOK;
     
    103107        }
    104108
     109        log_msg(LOG_DEFAULT, LVL_NOTE, "No match.");
    105110        return ENOENT;
    106111}
     
    146151        part->lpart = lpart;
    147152        part->disk = disk;
     153        part->id = (vbds_part_id_t)psid;
    148154        part->block0 = lpinfo.block0;
    149155        part->nblocks = lpinfo.nblocks;
     
    161167int vbds_disk_add(service_id_t sid)
    162168{
    163         label_t *label;
     169        label_t *label = NULL;
    164170        label_part_t *part;
    165171        vbds_disk_t *disk = NULL;
     
    206212        rc = label_open(sid, &label);
    207213        if (rc != EOK) {
     214                log_msg(LOG_DEFAULT, LVL_NOTE, "Label in disk %s not recognized.",
     215                    disk->svc_name);
    208216                rc = EIO;
    209217                goto error;
     
    216224        list_initialize(&disk->parts);
    217225        list_append(&disk->ldisks, &vbds_disks);
     226
     227        log_msg(LOG_DEFAULT, LVL_NOTE, "Recognized disk label. Adding partitions.");
    218228
    219229        part = label_part_first(label);
     
    462472static int vbds_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
    463473{
     474        vbds_part_t *part = bd_srv_part(bd);
     475
    464476        log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_get_block_size()");
     477        *rsize = part->disk->block_size;
    465478        return EOK;
    466479}
     
    468481static int vbds_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
    469482{
     483        vbds_part_t *part = bd_srv_part(bd);
     484
    470485        log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_get_num_blocks()");
     486        *rnb = part->nblocks;
    471487        return EOK;
    472488}
     
    478494        service_id_t partid;
    479495
     496        log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_conn()");
     497
    480498        partid = IPC_GET_ARG1(*icall);
    481499
     500        log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_conn() - partid=%zu", partid);
     501
    482502        rc = vbds_part_by_id(partid, &part);
    483503        if (rc != EOK) {
     504                log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_bd_conn() - partition "
     505                    "not found.");
    484506                async_answer_0(iid, EINVAL);
    485507                return;
    486508        }
    487509
     510        log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_conn() - call bd_conn");
    488511        bd_conn(iid, icall, &part->bds);
    489512}
Note: See TracChangeset for help on using the changeset viewer.