本文整理汇总了C++中set_capacity函数的典型用法代码示例。如果您正苦于以下问题:C++ set_capacity函数的具体用法?C++ set_capacity怎么用?C++ set_capacity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_capacity函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sd_revalidate_disk
/*
* Checks if media is still valid.
*/
static int sd_revalidate_disk(struct gendisk *disk)
{
struct sd_host *host = disk->private_data;
int retval = 0;
/* report missing medium for zombies */
if (!host) {
retval = -ENOMEDIUM;
goto out;
}
/* the block layer likes to call us multiple times... */
if (!sd_media_changed(host->disk))
goto out;
/* get the card into a known status */
retval = sd_welcome_card(host);
if (retval < 0 || sd_card_is_bad(host)) {
retval = -ENOMEDIUM;
goto out;
}
/* inform the block layer about various sizes */
blk_queue_logical_block_size(host->queue, 1 << KERNEL_SECTOR_SHIFT);
set_capacity(host->disk, host->card.csd.capacity /*<< (host->card.csd.read_blkbits - KERNEL_SECTOR_SHIFT)*/);
clear_bit(__SD_MEDIA_CHANGED, &host->flags);
out:
return retval;
}
示例2: fd_create_cache
FAST_DRAW_CACHE* fd_create_cache(size_t initial_size, bool use_indices)
{
FAST_DRAW_CACHE* cache = calloc(1, sizeof(FAST_DRAW_CACHE));
cache->use_indices = use_indices;
set_capacity(cache, initial_size);
return cache;
}
示例3: set_capacity
void AP_BattMonitor_Bebop::init(void)
{
set_capacity(BATTERY_CAPACITY);
_battery_voltage_max = bat_lut[BATTERY_PERCENT_LUT_SIZE - 1].voltage;
_prev_vbat_raw = bat_lut[BATTERY_PERCENT_LUT_SIZE - 1].voltage;
_prev_vbat = bat_lut[BATTERY_PERCENT_LUT_SIZE - 1].voltage;
}
示例4: ramblock_init
static int ramblock_init(void)
{
major = register_blkdev(0, "ramblock");
/* 1.分配一个gendisk结构体 */
/* 这里的16表示分区的个数 15个分区 */
ramblock_gendisk = alloc_disk(16);
/* 2. 设置 */
ramblock_gendisk->major = major;
ramblock_gendisk->first_minor = 0;
sprintf(ramblock_gendisk->disk_name, "ramblock");
ramblock_gendisk->fops = &ramblock_fops;
/* 2.1 分配/设置队列:提供读写能力 */
ramblock_request_queue = blk_init_queue(do_ramblock_request, &ramblock_lock);
ramblock_gendisk->queue = ramblock_request_queue;
/* 2.2 设置其它属性:比如容量 */
set_capacity(ramblock_gendisk, RAMBLOCK_SIZE / 512);
/* 3. 硬件相关操作 */
if (NULL == (ramblock_buf = kzalloc(RAMBLOCK_SIZE, GFP_KERNEL)))
return -ENOMEM;
/* 4. 注册 */
add_disk(ramblock_gendisk);
return 0;
}
示例5: dasd_scan_partitions
/*
* Trigger a partition detection.
*/
int
dasd_scan_partitions(struct dasd_device * device)
{
struct block_device *bdev;
/* Make the disk known. */
set_capacity(device->gdp, device->blocks << device->s2b_shift);
bdev = bdget_disk(device->gdp, 0);
if (!bdev || blkdev_get(bdev, FMODE_READ, 1) < 0)
return -ENODEV;
/*
* See fs/partition/check.c:register_disk,rescan_partitions
* Can't call rescan_partitions directly. Use ioctl.
*/
ioctl_by_bdev(bdev, BLKRRPART, 0);
/*
* Since the matching blkdev_put call to the blkdev_get in
* this function is not called before dasd_destroy_partitions
* the offline open_count limit needs to be increased from
* 0 to 1. This is done by setting device->bdev (see
* dasd_generic_set_offline). As long as the partition
* detection is running no offline should be allowed. That
* is why the assignment to device->bdev is done AFTER
* the BLKRRPART ioctl.
*/
device->bdev = bdev;
return 0;
}
示例6: dasd_destroy_partitions
/*
* Remove all inodes in the system for a device, delete the
* partitions and make device unusable by setting its size to zero.
*/
void dasd_destroy_partitions(struct dasd_block *block)
{
/* The two structs have 168/176 byte on 31/64 bit. */
struct blkpg_partition bpart;
struct blkpg_ioctl_arg barg;
struct block_device *bdev;
/*
* Get the bdev pointer from the device structure and clear
* device->bdev to lower the offline open_count limit again.
*/
bdev = block->bdev;
block->bdev = NULL;
/*
* See fs/partition/check.c:delete_partition
* Can't call delete_partitions directly. Use ioctl.
* The ioctl also does locking and invalidation.
*/
memset(&bpart, 0, sizeof(struct blkpg_partition));
memset(&barg, 0, sizeof(struct blkpg_ioctl_arg));
barg.data = (void __force __user *) &bpart;
barg.op = BLKPG_DEL_PARTITION;
for (bpart.pno = block->gdp->minors - 1; bpart.pno > 0; bpart.pno--)
ioctl_by_bdev(bdev, BLKPG, (unsigned long) &barg);
invalidate_partition(block->gdp, 0);
/* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
blkdev_put(bdev, FMODE_READ);
set_capacity(block->gdp, 0);
}
示例7: ramhd_init
static int __init ramhd_init(void)
{
int i;
ramhd_space_init();
alloc_ramdev();
ramhd_major = register_blkdev(0, RAMHD_NAME);
for (i=0; i<RAMHD_MAX_DEVICE; i++)
{
rdev[i]->data = sdisk[i];
rdev[i]->queue = blk_alloc_queue(GFP_KERNEL);
blk_queue_make_request(rdev[i]->queue, ramhd_make_request);
rdev[i]->gd = alloc_disk(RAMHD_MAX_PARTITIONS);
rdev[i]->gd->major = ramhd_major;
rdev[i]->gd->first_minor = i*RAMHD_MAX_PARTITIONS;
rdev[i]->gd->fops = &ramhd_fops;
rdev[i]->gd->queue = rdev[i]->queue;
rdev[i]->gd->private_data = rdev[i];
sprintf(rdev[i]->gd->disk_name, "ramhd%c", 'a'+i);
rdev[i]->gd->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO;
set_capacity(rdev[i]->gd, RAMHD_SECTOR_TOTAL);
add_disk(rdev[i]->gd);
}
return 0;
}
示例8: cf_create_disk
static int cf_create_disk(struct cf_device *cf)
{
struct gendisk *disk;
DPRINTK(DEBUG_CF_GENDISK, "%s: cf %p\n", __FUNCTION__, cf);
disk = alloc_disk(1 << 4);
if (!disk) {
DPRINTK(DEBUG_CF_TRACE, "%s:%d\n", __FUNCTION__, __LINE__);
blk_cleanup_queue(cf->queue);
cf->queue = NULL;
return -ENOMEM;
}
cf->gd = disk;
disk->major = cf_major;
disk->first_minor = 0;
disk->fops = &cf_fops;
disk->queue = cf->queue;
disk->private_data = cf;
snprintf(disk->disk_name, 32, "cf%c", cf->id + 'a');
disk->private_data = cf;
set_capacity(disk, ata_id_u32(cf->cf_id, ATA_ID_LBA_CAPACITY));
printk(KERN_INFO "%s: %u MiB\n", disk->disk_name, ata_id_u32(cf->cf_id, ATA_ID_LBA_CAPACITY) >> (20-9));
add_disk(disk);
return 0;
}
示例9: orb_check
// read - read latest voltage and current
void AP_BattMonitor_SMBus_PX4::read()
{
bool updated = false;
struct battery_status_s batt_status;
// check if new info has arrived from the orb
orb_check(_batt_sub, &updated);
// retrieve latest info
if (updated) {
if (OK == orb_copy(ORB_ID(battery_status), _batt_sub, &batt_status)) {
_state.voltage = batt_status.voltage_v;
_state.current_amps = batt_status.current_a;
_state.last_time_micros = hal.scheduler->micros();
_state.current_total_mah = batt_status.discharged_mah;
_state.healthy = true;
// read capacity
if ((_batt_fd >= 0) && !_capacity_updated) {
uint16_t tmp;
if (ioctl(_batt_fd, BATT_SMBUS_GET_CAPACITY, (unsigned long)&tmp) == OK) {
_capacity_updated = true;
set_capacity(tmp);
}
}
}
} else if (_state.healthy) {
// timeout after 5 seconds
if ((hal.scheduler->micros() - _state.last_time_micros) > AP_BATTMONITOR_SMBUS_TIMEOUT_MICROS) {
_state.healthy = false;
}
}
}
示例10: setup_device
static int setup_device(osprd_info_t *d, int which)
{
memset(d, 0, sizeof(osprd_info_t));
/* Get memory to store the actual block data. */
if (!(d->data = vmalloc(nsectors * SECTOR_SIZE)))
return -1;
memset(d->data, 0, nsectors * SECTOR_SIZE);
/* Set up the I/O queue. */
spin_lock_init(&d->qlock);
if (!(d->queue = blk_init_queue(osprd_process_request_queue, &d->qlock)))
return -1;
blk_queue_hardsect_size(d->queue, SECTOR_SIZE);
d->queue->queuedata = d;
/* The gendisk structure. */
if (!(d->gd = alloc_disk(1)))
return -1;
d->gd->major = OSPRD_MAJOR;
d->gd->first_minor = which;
d->gd->fops = &osprd_ops;
d->gd->queue = d->queue;
d->gd->private_data = d;
snprintf(d->gd->disk_name, 32, "osprd%c", which + 'a');
set_capacity(d->gd, nsectors);
add_disk(d->gd);
/* Call the setup function. */
osprd_setup(d);
return 0;
}
示例11: mbd_init_disk
static int mbd_init_disk(int devno)
{
struct gendisk *disk = mbd_dev[devno].disk;
unsigned int sz;
if (!__onsim())
return -1;
/* check disk configured */
if (!MamboBogusDiskInfo(BD_INFO_STATUS, devno)) {
printk(KERN_ERR
"Attempting to open bogus disk before initializaiton\n");
return 0;
}
mbd_dev[devno].initialized++;
sz = MamboBogusDiskInfo(BD_INFO_DEVSZ, devno);
if (sz == -1)
return 0;
printk("Initializing disk %d with devsz %u\n", devno, sz);
set_capacity(disk, sz << 1);
return 1;
}
示例12: ramblock_init
static int ramblock_init(void)
{
/* 1. 分配一个gendisk结构体 */
ramblock_disk = alloc_disk(16); /* 次设备号个数: 分区个数+1 */
/* 2. 设置 */
/* 2.1 分配/设置队列: 提供读写能力 */
ramblock_queue = blk_init_queue(do_ramblock_request, &ramblock_lock);
ramblock_disk->queue = ramblock_queue;
/* 2.2 设置其他属性: 比如容量 */
major = register_blkdev(0, "ramblock"); /* cat /proc/devices */
ramblock_disk->major = major;
ramblock_disk->first_minor = 0;
sprintf(ramblock_disk->disk_name, "ramblock");
ramblock_disk->fops = &ramblock_fops;
set_capacity(ramblock_disk, RAMBLOCK_SIZE / 512);
/* 3. 硬件相关操作 */
ramblock_buf = kzalloc(RAMBLOCK_SIZE, GFP_KERNEL);
/* 4. 注册 */
add_disk(ramblock_disk);
return 0;
}
示例13: find_first_zero_bit
static struct card_blk_data *card_blk_alloc(struct memory_card *card)
{
struct card_blk_data *card_data;
int devidx, ret;
devidx = find_first_zero_bit(dev_use, CARD_NUM_MINORS);
if(card->card_type == CARD_INAND)
devidx = CARD_INAND_START_MINOR>>CARD_SHIFT;
if (devidx >= CARD_NUM_MINORS)
return ERR_PTR(-ENOSPC);
__set_bit(devidx, dev_use);
card_data = kmalloc(sizeof(struct card_blk_data), GFP_KERNEL);
if (!card_data) {
ret = -ENOMEM;
return ERR_PTR(ret);
}
memset(card_data, 0, sizeof(struct card_blk_data));
card_data->block_bits = 9;
card_data->disk = alloc_disk(1 << CARD_SHIFT);
if (card_data->disk == NULL) {
ret = -ENOMEM;
kfree(card_data);
return ERR_PTR(ret);
}
spin_lock_init(&card_data->lock);
card_data->usage = 1;
ret = card_init_queue(&card_data->queue, card, &card_data->lock);
if (ret) {
put_disk(card_data->disk);
return ERR_PTR(ret);
}
card_data->queue.prep_fn = card_blk_prep_rq;
card_data->queue.issue_fn = card_blk_issue_rq;
card_data->queue.data = card_data;
card_data->disk->major = major;
card_data->disk->minors = 1 << CARD_SHIFT;
card_data->disk->first_minor = devidx << CARD_SHIFT;
card_data->disk->fops = &card_ops;
card_data->disk->private_data = card_data;
card_data->disk->queue = card_data->queue.queue;
card_data->disk->driverfs_dev = &card->dev;
sprintf(card_data->disk->disk_name, "cardblk%s", card->name);
blk_queue_logical_block_size(card_data->queue.queue, 1 << card_data->block_bits);
set_capacity(card_data->disk, card->capacity);
return card_data;
}
示例14: ramblock_init
static int __init ramblock_init(void)
{
/* 1. Allocate gendisk struct */
ramblock_disk = alloc_disk(16);
/* 2. Configure */
/* 2.1 Allocate/Configure a queue which supporting read/write capabilities */
if (!(ramblock_queue = blk_init_queue(do_ramblock_request, &ramblock_lock)))
return -ENOMEM;
ramblock_disk->queue = ramblock_queue;
/* 2.2 Configure other properties: such as volume, etc */
major = register_blkdev(0, "ramblock");
ramblock_disk->major = major;
ramblock_disk->first_minor = 0;
sprintf(ramblock_disk->disk_name, "ramblock");
ramblock_disk->fops = &ramblock_fops;
set_capacity(ramblock_disk, RAMBLOCK_SIZE / 512); /* 512 bytes per sector */
/* 3. Register */
add_disk(ramblock_disk);
return 0;
}
示例15: ndas_init
static int __init ndas_init(void)
{
int retval = 0;
struct ndas_dev *dev;
func();
retval = register_blkdev(0, "myndas");
if (retval <= 0) {
printk(KERN_ERR "ndas: failed to register device\n");
return retval;
} else {
major_number = retval;
printk(KERN_INFO "ndas: register device major number %d\n", major_number);
}
/* init block device */
dev = kmalloc(sizeof(struct ndas_dev), GFP_KERNEL);
if (dev == NULL) {
printk(KERN_ERR "ndas: failed to allocate memory for device\n");
goto err1;
}
memset(dev, sizeof(struct ndas_dev), 0);
spin_lock_init(&dev->lock);
Device = dev;
/* init queue */
dev->queue = blk_init_queue(ndas_request, &dev->lock);
if (dev->queue == NULL) {
printk(KERN_ERR "ndas: failed to allocate memory for queue\n");
goto err2;
}
blk_queue_logical_block_size(dev->queue, HARDSECT_SIZE);
dev->queue->queuedata = dev;
/* gendisk structure */
dev->gd = alloc_disk(NDAS_MINORS);
if (dev->gd == NULL) {
printk(KERN_ERR "ndas: failed to allocate memory for gendisk\n");
goto err3;
}
dev->gd->major = major_number;
dev->gd->first_minor = 0;
dev->gd->fops = &blk_ops;
dev->gd->queue = dev->queue;
dev->gd->private_data = dev;
set_capacity(dev->gd, NSECTOR * (HARDSECT_SIZE / KERNEL_SECTOR_SIZE));
snprintf(dev->gd->disk_name, 6, "myndas");
add_disk(dev->gd);
return 0;
err3:
blk_cleanup_queue(dev->queue);
err2:
kfree(dev);
err1:
Device = NULL;
unregister_blkdev(major_number, "ndas");
return -ENOMEM;
}