Changeset 3faa03d in mainline
- Timestamp:
- 2015-07-02T16:30:16Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1626cd4
- Parents:
- 78d50bd
- Location:
- uspace
- Files:
-
- 5 added
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/label/Makefile
r78d50bd r3faa03d 33 33 34 34 SOURCES = \ 35 src/mbr.c \ 36 src/gpt.c \ 35 37 src/label.c 36 38 -
uspace/lib/label/include/std/gpt.h
r78d50bd r3faa03d 1 1 /* 2 * Copyright (c) 20 09Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 33 33 */ 34 34 35 #ifndef __GPT_H__36 #define __GPT_H__35 #ifndef LIBLABEL_STD_GPT_H_ 36 #define LIBLABEL_STD_GPT_H_ 37 37 38 38 #include <sys/types.h> -
uspace/lib/label/include/types/liblabel.h
r78d50bd r3faa03d 42 42 #include <vol.h> 43 43 44 typedef struct label label_t; 45 typedef struct label_part label_part_t; 46 typedef struct label_part_info label_part_info_t; 47 typedef struct label_part_spec label_part_spec_t; 48 49 /** Ops for individual label type */ 50 typedef 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 44 62 typedef struct { 45 63 /** Disk contents */ … … 49 67 } label_info_t; 50 68 51 typedef struct{69 struct label_part_info { 52 70 /** Address of first block */ 53 71 aoff64_t block0; 54 72 /** Number of blocks */ 55 73 aoff64_t nblocks; 56 } label_part_info_t;74 }; 57 75 58 76 /** Partition */ 59 typedef struct {77 struct label_part { 60 78 /** Containing label */ 61 79 struct label *label; 62 80 /** Link to label_t.parts */ 63 81 link_t llabel; 64 } label_part_t; 82 aoff64_t block0; 83 aoff64_t nblocks; 84 }; 65 85 66 86 /** Specification of new partition */ 67 typedef struct{68 } label_part_spec_t;87 struct label_part_spec { 88 }; 69 89 70 90 /** Label instance */ 71 typedef struct label { 91 struct label { 92 /** Label type ops */ 93 label_ops_t *ops; 94 /** Label type */ 95 label_type_t ltype; 72 96 /** Partitions */ 73 97 list_t parts; /* of label_part_t */ 74 } label_t;98 }; 75 99 76 100 #endif -
uspace/lib/label/src/label.c
r78d50bd r3faa03d 40 40 #include <stdlib.h> 41 41 42 #include "gpt.h" 43 44 static label_ops_t *probe_list[] = { 45 &gpt_label_ops, 46 NULL 47 }; 48 42 49 int label_open(service_id_t sid, label_t **rlabel) 43 50 { 44 label_t *label; 51 label_ops_t **ops; 52 int rc; 45 53 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 } 49 61 50 list_initialize(&label->parts); 51 *rlabel = label; 52 return EOK; 62 return ENOTSUP; 53 63 } 54 64 55 65 int label_create(service_id_t sid, label_type_t ltype, label_t **rlabel) 56 66 { 57 label_ t *label;67 label_ops_t *ops = NULL; 58 68 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 } 62 77 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); 66 82 } 67 83 … … 71 87 return; 72 88 73 free(label);89 label->ops->close(label); 74 90 } 75 91 76 92 int label_destroy(label_t *label) 77 93 { 78 free(label); 79 return EOK; 94 return label->ops->destroy(label); 80 95 } 81 96 … … 83 98 { 84 99 memset(linfo, 0, sizeof(label_info_t)); 85 linfo->dcnt = dc_empty; 100 linfo->dcnt = dc_label; 101 linfo->ltype = label->ltype; 86 102 return EOK; 87 103 } … … 89 105 label_part_t *label_part_first(label_t *label) 90 106 { 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); 98 108 } 99 109 100 110 label_part_t *label_part_next(label_part_t *part) 101 111 { 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); 109 113 } 110 114 111 115 void label_part_get_info(label_part_t *part, label_part_info_t *pinfo) 112 116 { 113 pinfo->block0 = 0; 114 pinfo->nblocks = 0; 117 return part->label->ops->part_get_info(part, pinfo); 115 118 } 116 119 … … 118 121 label_part_t **rpart) 119 122 { 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); 130 124 } 131 125 132 126 int label_part_destroy(label_part_t *part) 133 127 { 134 list_remove(&part->llabel); 135 free(part); 136 return EOK; 128 return part->label->ops->part_destroy(part); 137 129 } 138 130 -
uspace/srv/bd/part/guid_part/Makefile
r78d50bd r3faa03d 29 29 USPACE_PREFIX = ../../../.. 30 30 LIBS = $(LIBBLOCK_PREFIX)/libblock.a 31 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) 31 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBLABEL_PREFIX)/include 32 32 33 33 # 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 64 64 #include <task.h> 65 65 66 #include "gpt.h"66 #include <std/gpt.h> 67 67 68 68 #define NAME "guid_part" -
uspace/srv/bd/vbd/disk.c
r78d50bd r3faa03d 96 96 static int vbds_part_by_id(vbds_part_id_t partid, vbds_part_t **rpart) 97 97 { 98 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_part_by_id(%zu)", partid); 99 98 100 list_foreach(vbds_parts, lparts, vbds_part_t, part) { 101 log_msg(LOG_DEFAULT, LVL_NOTE, "%zu == %zu ?", part->id, partid); 99 102 if (part->id == partid) { 103 log_msg(LOG_DEFAULT, LVL_NOTE, "Found match."); 100 104 *rpart = part; 101 105 return EOK; … … 103 107 } 104 108 109 log_msg(LOG_DEFAULT, LVL_NOTE, "No match."); 105 110 return ENOENT; 106 111 } … … 146 151 part->lpart = lpart; 147 152 part->disk = disk; 153 part->id = (vbds_part_id_t)psid; 148 154 part->block0 = lpinfo.block0; 149 155 part->nblocks = lpinfo.nblocks; … … 161 167 int vbds_disk_add(service_id_t sid) 162 168 { 163 label_t *label ;169 label_t *label = NULL; 164 170 label_part_t *part; 165 171 vbds_disk_t *disk = NULL; … … 206 212 rc = label_open(sid, &label); 207 213 if (rc != EOK) { 214 log_msg(LOG_DEFAULT, LVL_NOTE, "Label in disk %s not recognized.", 215 disk->svc_name); 208 216 rc = EIO; 209 217 goto error; … … 216 224 list_initialize(&disk->parts); 217 225 list_append(&disk->ldisks, &vbds_disks); 226 227 log_msg(LOG_DEFAULT, LVL_NOTE, "Recognized disk label. Adding partitions."); 218 228 219 229 part = label_part_first(label); … … 462 472 static int vbds_bd_get_block_size(bd_srv_t *bd, size_t *rsize) 463 473 { 474 vbds_part_t *part = bd_srv_part(bd); 475 464 476 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_get_block_size()"); 477 *rsize = part->disk->block_size; 465 478 return EOK; 466 479 } … … 468 481 static int vbds_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 469 482 { 483 vbds_part_t *part = bd_srv_part(bd); 484 470 485 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_get_num_blocks()"); 486 *rnb = part->nblocks; 471 487 return EOK; 472 488 } … … 478 494 service_id_t partid; 479 495 496 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_conn()"); 497 480 498 partid = IPC_GET_ARG1(*icall); 481 499 500 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_conn() - partid=%zu", partid); 501 482 502 rc = vbds_part_by_id(partid, &part); 483 503 if (rc != EOK) { 504 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_bd_conn() - partition " 505 "not found."); 484 506 async_answer_0(iid, EINVAL); 485 507 return; 486 508 } 487 509 510 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_bd_conn() - call bd_conn"); 488 511 bd_conn(iid, icall, &part->bds); 489 512 }
Note:
See TracChangeset
for help on using the changeset viewer.