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

Changeset 53e3950 in mainline


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.

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/fdisk/Makefile

    re11c527 r53e3950  
    3030LIBS = \
    3131        $(LIBCLUI_PREFIX)/libclui.a \
    32         $(LIBFDISK_PREFIX)/libfdisk.a \
    33         $(LIBBLOCK_PREFIX)/libblock.a
     32        $(LIBFDISK_PREFIX)/libfdisk.a
    3433
    3534EXTRA_CFLAGS = \
  • uspace/lib/c/include/vbd.h

    re11c527 r53e3950  
    5959        /** Block size */
    6060        size_t block_size;
     61        /** Total number of blocks */
     62        aoff64_t nblocks;
    6163} vbd_disk_info_t;
    6264
  • uspace/lib/fdisk/Makefile

    re11c527 r53e3950  
    2828
    2929USPACE_PREFIX = ../..
    30 EXTRA_CFLAGS = -Iinclude -I$(LIBBLOCK_PREFIX)
     30EXTRA_CFLAGS = -Iinclude
    3131
    3232LIBRARY = libfdisk
  • uspace/lib/fdisk/include/types/fdisk.h

    re11c527 r53e3950  
    110110/** List of devices available for managing by fdisk */
    111111typedef struct {
     112        /** Fdisk instance */
     113        struct fdisk *fdisk;
     114        /** List of device info structures */
    112115        list_t devinfos; /* of fdisk_dev_info_t */
    113116} fdisk_dev_list_t;
     
    123126        /** Service name or NULL if not determined yet */
    124127        char *svcname;
    125         /** Device is initialized in libblock */
    126         bool blk_inited;
    127128} fdisk_dev_info_t;
    128129
  • 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}
  • uspace/srv/bd/vbd/disk.c

    re11c527 r53e3950  
    452452        bool block_inited = false;
    453453        size_t block_size;
     454        aoff64_t nblocks;
    454455        int rc;
    455456
     
    489490        }
    490491
     492        rc = block_get_nblocks(sid, &nblocks);
     493        if (rc != EOK) {
     494                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed getting number of "
     495                    "blocks of %s.", disk->svc_name);
     496                rc = EIO;
     497                goto error;
     498        }
     499
    491500        block_inited = true;
    492501
     
    502511        disk->label = label;
    503512        disk->block_size = block_size;
     513        disk->nblocks = nblocks;
    504514        disk->present = true;
    505515
     
    598608        info->anblocks = linfo.anblocks;
    599609        info->block_size = disk->block_size;
     610        info->nblocks = disk->nblocks;
    600611        log_msg(LOG_DEFAULT, LVL_DEBUG, "vbds_disk_info - block_size=%zu",
    601612            info->block_size);
  • uspace/srv/bd/vbd/types/vbd.h

    re11c527 r53e3950  
    100100        /** Block size */
    101101        size_t block_size;
     102        /** Total number of blocks */
     103        aoff64_t nblocks;
    102104        /** Used to mark disks still present during re-discovery */
    103105        bool present;
Note: See TracChangeset for help on using the changeset viewer.