Changes in uspace/lib/label/src/mbr.c [d8513177:9f64c1e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/label/src/mbr.c
rd8513177 r9f64c1e 34 34 */ 35 35 36 #include <block.h>37 36 #include <byteorder.h> 38 37 #include <errno.h> … … 40 39 #include <stdlib.h> 41 40 41 #include "std/fat.h" 42 42 #include "std/mbr.h" 43 43 #include "mbr.h" 44 44 45 static int mbr_open( service_id_t, label_t **);45 static int mbr_open(label_bd_t *, label_t **); 46 46 static int mbr_open_ext(label_t *); 47 static int mbr_create( service_id_t, label_t **);47 static int mbr_create(label_bd_t *, label_t **); 48 48 static void mbr_close(label_t *); 49 49 static int mbr_destroy(label_t *); … … 86 86 }; 87 87 88 static int mbr_open( service_id_t sid, label_t **rlabel)88 static int mbr_open(label_bd_t *bd, label_t **rlabel) 89 89 { 90 90 label_t *label = NULL; 91 91 mbr_br_block_t *mbr = NULL; 92 fat_bs_t *bs; 92 93 mbr_pte_t *eptr; 93 94 uint16_t sgn; … … 97 98 int rc; 98 99 99 rc = b lock_get_bsize(sid, &bsize);100 if (rc != EOK) { 101 rc = EIO; 102 goto error; 103 } 104 105 rc = b lock_get_nblocks(sid, &nblocks);100 rc = bd->ops->get_bsize(bd->arg, &bsize); 101 if (rc != EOK) { 102 rc = EIO; 103 goto error; 104 } 105 106 rc = bd->ops->get_nblocks(bd->arg, &nblocks); 106 107 if (rc != EOK) { 107 108 rc = EIO; … … 125 126 } 126 127 127 rc = block_read_direct(sid, mbr_ba, 1, mbr); 128 bs = (fat_bs_t *)mbr; 129 130 rc = bd->ops->read(bd->arg, mbr_ba, 1, mbr); 128 131 if (rc != EOK) { 129 132 rc = EIO; … … 146 149 } 147 150 151 /* 152 * We can't really tell whether this is an MBR. Make sure 153 * this is not actually the BR of a 12/16-bit FAT file system 154 */ 155 if (bs->type[0] == 'F' && bs->type[1] == 'A' && bs->type[2] == 'T') { 156 rc = EIO; 157 goto error; 158 } 159 160 /* 161 * Or a 32-bit FAT file system 162 */ 163 if (bs->fat32.type[0] == 'F' && bs->fat32.type[1] == 'A' && 164 bs->fat32.type[2] == 'T') { 165 rc = EIO; 166 goto error; 167 } 148 168 149 169 label->ext_part = NULL; … … 160 180 label->ops = &mbr_label_ops; 161 181 label->ltype = lt_mbr; 162 label-> svc_id = sid;182 label->bd = *bd; 163 183 label->block_size = bsize; 164 184 label->ablock0 = mbr_ablock0; … … 219 239 while (true) { 220 240 /* Read EBR */ 221 rc = block_read_direct(label->svc_id, ebr_b0, 1, ebr);241 rc = label->bd.ops->read(label->bd.arg, ebr_b0, 1, ebr); 222 242 if (rc != EOK) { 223 243 rc = EIO; … … 280 300 } 281 301 282 static int mbr_create( service_id_t sid, label_t **rlabel)302 static int mbr_create(label_bd_t *bd, label_t **rlabel) 283 303 { 284 304 label_t *label = NULL; … … 289 309 int rc; 290 310 291 rc = b lock_get_bsize(sid, &bsize);292 if (rc != EOK) { 293 rc = EIO; 294 goto error; 295 } 296 297 rc = b lock_get_nblocks(sid, &nblocks);311 rc = bd->ops->get_bsize(bd->arg, &bsize); 312 if (rc != EOK) { 313 rc = EIO; 314 goto error; 315 } 316 317 rc = bd->ops->get_nblocks(bd->arg, &nblocks); 298 318 if (rc != EOK) { 299 319 rc = EIO; … … 321 341 mbr->signature = host2uint16_t_le(mbr_br_signature); 322 342 323 rc = b lock_write_direct(sid, mbr_ba, 1, mbr);343 rc = bd->ops->write(bd->arg, mbr_ba, 1, mbr); 324 344 if (rc != EOK) { 325 345 rc = EIO; … … 333 353 label->ltype = lt_mbr; 334 354 label->block_size = bsize; 335 label-> svc_id = sid;355 label->bd = *bd; 336 356 label->ablock0 = mbr_ablock0; 337 357 label->anblocks = nblocks - mbr_ablock0; … … 387 407 } 388 408 389 rc = block_write_direct(label->svc_id, mbr_ba, 1, mbr);409 rc = label->bd.ops->write(label->bd.arg, mbr_ba, 1, mbr); 390 410 if (rc != EOK) { 391 411 rc = EIO; … … 998 1018 return ENOMEM; 999 1019 1000 rc = block_read_direct(label->svc_id, mbr_ba, 1, br);1020 rc = label->bd.ops->read(label->bd.arg, mbr_ba, 1, br); 1001 1021 if (rc != EOK) { 1002 1022 rc = EIO; … … 1006 1026 br->pte[index] = *pte; 1007 1027 1008 rc = block_write_direct(label->svc_id, mbr_ba, 1, br);1028 rc = label->bd.ops->write(label->bd.arg, mbr_ba, 1, br); 1009 1029 if (rc != EOK) { 1010 1030 rc = EIO; … … 1066 1086 br->signature = host2uint16_t_le(mbr_br_signature); 1067 1087 1068 rc = block_write_direct(label->svc_id, ba, 1, br);1088 rc = label->bd.ops->write(label->bd.arg, ba, 1, br); 1069 1089 if (rc != EOK) { 1070 1090 rc = EIO; … … 1091 1111 ba = part->block0 - part->hdr_blocks; 1092 1112 1093 rc = block_write_direct(label->svc_id, ba, 1, br);1113 rc = label->bd.ops->write(label->bd.arg, ba, 1, br); 1094 1114 if (rc != EOK) { 1095 1115 rc = EIO; … … 1118 1138 return ENOMEM; 1119 1139 1120 rc = block_read_direct(label->svc_id, ba, 1, br);1140 rc = label->bd.ops->read(label->bd.arg, ba, 1, br); 1121 1141 if (rc != EOK) { 1122 1142 rc = EIO; … … 1133 1153 mbr_log_part_to_ptes(part, NULL, &br->pte[mbr_ebr_pte_next]); 1134 1154 1135 rc = block_write_direct(label->svc_id, ba, 1, br);1155 rc = label->bd.ops->write(label->bd.arg, ba, 1, br); 1136 1156 if (rc != EOK) { 1137 1157 rc = EIO;
Note:
See TracChangeset
for help on using the changeset viewer.