block.c (6f2ef80b0ce87d258b4736471a81747da2a7a881) | block.c (122860bae7c3a3cf45f9f2dedddb0e2492f09888) |
---|---|
1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 5077 unchanged lines hidden (view full) --- 5086/** 5087 * Return length in bytes on success, -errno on error. 5088 * The length is always a multiple of BDRV_SECTOR_SIZE. 5089 */ 5090int64_t bdrv_getlength(BlockDriverState *bs) 5091{ 5092 int64_t ret = bdrv_nb_sectors(bs); 5093 | 1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 5077 unchanged lines hidden (view full) --- 5086/** 5087 * Return length in bytes on success, -errno on error. 5088 * The length is always a multiple of BDRV_SECTOR_SIZE. 5089 */ 5090int64_t bdrv_getlength(BlockDriverState *bs) 5091{ 5092 int64_t ret = bdrv_nb_sectors(bs); 5093 |
5094 ret = ret > INT64_MAX / BDRV_SECTOR_SIZE ? -EFBIG : ret; 5095 return ret < 0 ? ret : ret * BDRV_SECTOR_SIZE; | 5094 if (ret < 0) { 5095 return ret; 5096 } 5097 if (ret > INT64_MAX / BDRV_SECTOR_SIZE) { 5098 return -EFBIG; 5099 } 5100 return ret * BDRV_SECTOR_SIZE; |
5096} 5097 5098/* return 0 as number of sectors if no device present or error */ 5099void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr) 5100{ 5101 int64_t nb_sectors = bdrv_nb_sectors(bs); 5102 5103 *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors; --- 2122 unchanged lines hidden --- | 5101} 5102 5103/* return 0 as number of sectors if no device present or error */ 5104void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr) 5105{ 5106 int64_t nb_sectors = bdrv_nb_sectors(bs); 5107 5108 *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors; --- 2122 unchanged lines hidden --- |