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

Changeset 53e3950 in mainline for uspace/lib/fdisk/src/fdisk.c


Ignore:
Timestamp:
2016-02-18T17:01:49Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
9e53406
Parents:
e11c527
Message:

libfdisk should not depend on libblock nor should it access the block devices directly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/fdisk/src/fdisk.c

    re11c527 r53e3950  
    3535
    3636#include <adt/list.h>
    37 #include <block.h>
    3837#include <errno.h>
    3938#include <fdisk.h>
    4039#include <loc.h>
     40#include <macros.h>
    4141#include <mem.h>
    4242#include <stdlib.h>
     
    6565                return;
    6666
    67         if (info->blk_inited)
    68                 block_fini(info->svcid);
    69 
    7067        free(info->svcname);
    7168        free(info);
     
    125122                return ENOMEM;
    126123
     124        devlist->fdisk = fdisk;
    127125        list_initialize(&devlist->devinfos);
    128126
     
    222220int fdisk_dev_info_capacity(fdisk_dev_info_t *info, fdisk_cap_t *cap)
    223221{
    224         size_t bsize;
    225         aoff64_t nblocks;
    226         int rc;
    227 
    228         if (!info->blk_inited) {
    229                 rc = block_init(info->svcid, 2048);
    230                 if (rc != EOK)
    231                         return rc;
    232 
    233                 info->blk_inited = true;
    234         }
    235 
    236         rc = block_get_bsize(info->svcid, &bsize);
     222        vbd_disk_info_t vinfo;
     223        int rc;
     224
     225        rc = vbd_disk_info(info->devlist->fdisk->vbd, info->svcid, &vinfo);
    237226        if (rc != EOK)
    238227                return EIO;
    239228
    240         rc = block_get_nblocks(info->svcid, &nblocks);
    241         if (rc != EOK)
    242                 return EIO;
    243 
    244         fdisk_cap_from_blocks(nblocks, bsize, cap);
     229        fdisk_cap_from_blocks(vinfo.nblocks, vinfo.block_size, cap);
    245230        return EOK;
    246231}
     
    435420int fdisk_dev_open(fdisk_t *fdisk, service_id_t sid, fdisk_dev_t **rdev)
    436421{
    437         vbd_disk_info_t vinfo;
    438422        fdisk_dev_t *dev = NULL;
    439423        service_id_t *psids = NULL;
     
    451435        list_initialize(&dev->pri_ba);
    452436        list_initialize(&dev->log_ba);
    453 
    454         rc = vbd_disk_info(fdisk->vbd, sid, &vinfo);
    455         if (rc != EOK) {
    456                 rc = EIO;
    457                 goto error;
    458         }
    459437
    460438        rc = fdisk_update_dev_info(dev);
     
    554532int fdisk_dev_capacity(fdisk_dev_t *dev, fdisk_cap_t *cap)
    555533{
    556         size_t bsize;
    557         aoff64_t nblocks;
    558         int rc;
    559 
    560         rc = block_init(dev->sid, 2048);
    561         if (rc != EOK)
    562                 return rc;
    563 
    564         rc = block_get_bsize(dev->sid, &bsize);
    565         if (rc != EOK)
    566                 return EIO;
    567 
    568         rc = block_get_nblocks(dev->sid, &nblocks);
    569         if (rc != EOK)
    570                 return EIO;
    571 
    572         block_fini(dev->sid);
    573 
    574         fdisk_cap_from_blocks(nblocks, bsize, cap);
     534        fdisk_cap_from_blocks(dev->dinfo.nblocks, dev->dinfo.block_size, cap);
    575535        return EOK;
    576536}
Note: See TracChangeset for help on using the changeset viewer.