Exemplo n.º 1
0
/*
 * 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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
/*
 * 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;
}
Exemplo n.º 6
0
/*
 * 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);
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
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;
}
// 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;
        }
    }
}
Exemplo n.º 10
0
/**
 * Resize disk.
 *
 * @gd disk.
 * @new_size new size [logical block].
 *
 * RETURN:
 *   true in success, or false.
 */
bool resize_disk(struct gendisk *gd, u64 new_size)
{
	struct block_device *bdev;
	u64 old_size;

	ASSERT(gd);

	old_size = get_capacity(gd);
	if (old_size == new_size) {
		return true;
	}
	set_capacity(gd, new_size);

	bdev = bdget_disk(gd, 0);
	if (!bdev) {
		LOGe("bdget_disk failed.\n");
		return false;
	}
	mutex_lock(&bdev->bd_mutex);
	if (old_size > new_size) {
		LOGn("Shrink disk should discard block cache.\n");
		check_disk_size_change(gd, bdev);
		/* This should be implemented in check_disk_size_change(). */
		bdev->bd_invalidated = 0;
	} else {
		i_size_write(bdev->bd_inode,
			(loff_t)new_size * LOGICAL_BLOCK_SIZE);
	}
	mutex_unlock(&bdev->bd_mutex);
	bdput(bdev);
	return true;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
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;
}
Exemplo n.º 17
0
static void __set_size(struct mapped_device *md, sector_t size)
{
	set_capacity(md->disk, size);

	down(&md->frozen_bdev->bd_inode->i_sem);
	i_size_write(md->frozen_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
	up(&md->frozen_bdev->bd_inode->i_sem);
}
Exemplo n.º 18
0
static void __set_size(struct mapped_device *md, sector_t size)
{
	set_capacity(md->disk, size);

	mutex_lock(&md->suspended_bdev->bd_inode->i_mutex);
	i_size_write(md->suspended_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
	mutex_unlock(&md->suspended_bdev->bd_inode->i_mutex);
}
Exemplo n.º 19
0
static int nbd_size_clear(struct nbd_device *nbd, struct block_device *bdev)
{
	bdev->bd_inode->i_size = 0;
	set_capacity(nbd->disk, 0);
	kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);

	return 0;
}
Exemplo n.º 20
0
static int __init mbd_init(void)
{
	int err = -ENOMEM;
	int i;

	for (i = 0; i < MAX_MBD; i++) {
		struct gendisk *disk = alloc_disk(1);
		if (!disk)
			goto out;
		mbd_dev[i].disk = disk;
		/*
		 * The new linux 2.5 block layer implementation requires
		 * every gendisk to have its very own request_queue struct.
		 * These structs are big so we dynamically allocate them.
		 */
		disk->queue = blk_init_queue(do_mbd_request, &mbd_lock);
		if (!disk->queue) {
			put_disk(disk);
			goto out;
		}
	}

	if (register_blkdev(MAJOR_NR, "mbd")) {
		err = -EIO;
		goto out;
	}
#ifdef MODULE
	printk("mambo bogus disk: registered device at major %d\n", MAJOR_NR);
#else
	printk("mambo bogus disk: compiled in with kernel\n");
#endif

	devfs_mk_dir("mambobd");
	for (i = 0; i < MAX_MBD; i++) {	/* load defaults */
		struct gendisk *disk = mbd_dev[i].disk;
		mbd_dev[i].initialized = 0;
		mbd_dev[i].refcnt = 0;
		mbd_dev[i].flags = 0;
		disk->major = MAJOR_NR;
		disk->first_minor = i;
		disk->fops = &mbd_fops;
		disk->private_data = &mbd_dev[i];
		sprintf(disk->disk_name, "mambobd%d", i);
		sprintf(disk->devfs_name, "mambobd%d", i);
		set_capacity(disk, 0x7ffffc00ULL << 1);	/* 2 TB */
		add_disk(disk);
	}

	return 0;
      out:
	while (i--) {
		if (mbd_dev[i].disk->queue)
			blk_cleanup_queue(mbd_dev[i].disk->queue);
		put_disk(mbd_dev[i].disk);
	}
	return -EIO;
}
Exemplo n.º 21
0
/* alloc_disk and add_disk can sleep */
void
aoeblk_gdalloc(void *vp)
{
	struct aoedev *d = vp;
	struct gendisk *gd;
	ulong flags;

	gd = alloc_disk(AOE_PARTITIONS);
	if (gd == NULL) {
		printk(KERN_ERR
			"aoe: cannot allocate disk structure for %ld.%d\n",
			d->aoemajor, d->aoeminor);
		goto err;
	}

	d->bufpool = mempool_create_slab_pool(MIN_BUFS, buf_pool_cache);
	if (d->bufpool == NULL) {
		printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%d\n",
			d->aoemajor, d->aoeminor);
		goto err_disk;
	}

	d->blkq = blk_alloc_queue(GFP_KERNEL);
	if (!d->blkq)
		goto err_mempool;
	blk_queue_make_request(d->blkq, aoeblk_make_request);
	d->blkq->backing_dev_info.name = "aoe";
	spin_lock_irqsave(&d->lock, flags);
	gd->major = AOE_MAJOR;
	gd->first_minor = d->sysminor * AOE_PARTITIONS;
	gd->fops = &aoe_bdops;
	gd->private_data = d;
	set_capacity(gd, d->ssize);
	snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%d",
		d->aoemajor, d->aoeminor);

	gd->queue = d->blkq;
	d->gd = gd;
	d->flags &= ~DEVFL_GDALLOC;
	d->flags |= DEVFL_UP;

	spin_unlock_irqrestore(&d->lock, flags);

	add_disk(gd);
	aoedisk_add_sysfs(d);
	return;

err_mempool:
	mempool_destroy(d->bufpool);
err_disk:
	put_disk(gd);
err:
	spin_lock_irqsave(&d->lock, flags);
	d->flags &= ~DEVFL_GDALLOC;
	spin_unlock_irqrestore(&d->lock, flags);
}
Exemplo n.º 22
0
/**
 * add_last_partition : add card last partition as a full device, refer to
 * board-****.c  inand_partition_info[] last partition
 * @card: inand_card_lp
 * @size: set last partition capacity
 */
int add_last_partition(struct memory_card* card, uint64_t offset ,uint64_t size)
{
      struct card_blk_data *card_data;
      int ret;

      card_data = kmalloc(sizeof(struct card_blk_data), GFP_KERNEL);
      if (!card_data) {
            ret = -ENOMEM;
            return ret;
      }

      memset(card_data, 0, sizeof(struct card_blk_data));

      if(card->state & CARD_STATE_READONLY)
            card_data->read_only = 1;

      card_data->block_bits = 9;

      card_data->disk = alloc_disk(1 << CARD_SHIFT);
      if (card_data->disk == NULL) {
            ret = -ENOMEM;
            kfree(card_data);
            return 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 ret;
      }

      card->part_offset=offset;
      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 = INAND_LAST_PART_MAJOR;
      card_data->disk->minors = 1 << CARD_SHIFT;
      card_data->disk->first_minor = 0;
      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, size);
      card_set_drvdata(card, card_data);
      add_disk(card_data->disk);
      return 0;
}
Exemplo n.º 23
0
static int ide_gd_revalidate_disk(struct gendisk *disk)
{
	struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
	ide_drive_t *drive = idkp->drive;

	if (ide_gd_media_changed(disk))
		drive->disk_ops->get_capacity(drive);

	set_capacity(disk, ide_gd_capacity(drive));
	return 0;
}
Exemplo n.º 24
0
static int
figure_loop_size(struct loop_device *lo)
{
	loff_t size = get_loop_size(lo, lo->lo_backing_file);
	sector_t x = (sector_t)size;

	if (unlikely((loff_t)x != size))
		return -EFBIG;

	set_capacity(lo->lo_disk, x);
	return 0;					
}
Exemplo n.º 25
0
static void setup_blk_device(struct ramdisk_dev* dev)
{
    mutex_init(&dev->mutex);
    init_waitqueue_head(&dev->waitqueue);

    /*
     * Get some memory.
     */
    memset (dev, 0, sizeof (struct ramdisk_dev));
    dev->size = NSECTORS*HARDSECT_SIZE;
    dev->data = vmalloc(dev->size);
    if (dev->data == NULL) {
        printk (KERN_NOTICE "vmalloc failure.\n");
        return;
    }
    spin_lock_init(&dev->lock);
    
    /*
     * The timer which "invalidates" the device.
     */
    init_timer(&dev->timer);
    dev->timer.data = (unsigned long) dev;
    dev->timer.function = ramdisk_invalidate;
    
    dev->queue = blk_init_queue(ramdisk_request, &dev->lock);
    if (dev->queue == NULL)
        goto out_vfree;

    blk_queue_logical_block_size(dev->queue, HARDSECT_SIZE);
    dev->queue->queuedata = dev;
    /*
     * And the gendisk structure.
     */
    dev->gd = alloc_disk(BLK_MINORS);
    if (! dev->gd) {
        printk (KERN_NOTICE "alloc_disk failure\n");
        goto out_vfree;
    }
    dev->gd->major = blk_major;
    dev->gd->first_minor = BLK_MINORS;
    dev->gd->fops = &ramdisk_ops;
    dev->gd->queue = dev->queue;
    dev->gd->private_data = dev;
    snprintf (dev->gd->disk_name, 32, "ramdisk%c", 'a');
    set_capacity(dev->gd, NSECTORS*(HARDSECT_SIZE/KERNEL_SECTOR_SIZE));
//    set_capacity(dev->gd, 0);
    add_disk(dev->gd);
    return;

  out_vfree:
    if (dev->data)
        vfree(dev->data);
}
Exemplo n.º 26
0
/*
 * Allocate and register gendisk structure for device.
 */
int
dasd_gendisk_alloc(struct dasd_device *device)
{
	struct gendisk *gdp;
	int len;

	/* Make sure the minor for this device exists. */
	if (device->devindex >= DASD_PER_MAJOR)
		return -EBUSY;

	gdp = alloc_disk(1 << DASD_PARTN_BITS);
	if (!gdp)
		return -ENOMEM;

	/* Initialize gendisk structure. */
	gdp->major = DASD_MAJOR;
	gdp->first_minor = device->devindex << DASD_PARTN_BITS;
	gdp->fops = &dasd_device_operations;
	gdp->driverfs_dev = &device->cdev->dev;

	/*
	 * Set device name.
	 *   dasda - dasdz : 26 devices
	 *   dasdaa - dasdzz : 676 devices, added up = 702
	 *   dasdaaa - dasdzzz : 17576 devices, added up = 18278
	 *   dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
	 */
	len = sprintf(gdp->disk_name, "dasd");
	if (device->devindex > 25) {
	        if (device->devindex > 701) {
		        if (device->devindex > 18277)
			        len += sprintf(gdp->disk_name + len, "%c",
					       'a'+(((device->devindex-18278)
						     /17576)%26));
			len += sprintf(gdp->disk_name + len, "%c",
				       'a'+(((device->devindex-702)/676)%26));
		}
		len += sprintf(gdp->disk_name + len, "%c",
			       'a'+(((device->devindex-26)/26)%26));
	}
	len += sprintf(gdp->disk_name + len, "%c", 'a'+(device->devindex%26));

 	sprintf(gdp->devfs_name, "dasd/%s", device->cdev->dev.bus_id);

	if (test_bit(DASD_FLAG_RO, &device->flags))
		set_disk_ro(gdp, 1);
	gdp->private_data = device;
	gdp->queue = device->request_queue;
	device->gdp = gdp;
	set_capacity(device->gdp, 0);
	add_disk(device->gdp);
	return 0;
}
Exemplo n.º 27
0
/*
 * Allocate and register gendisk structure for device.
 */
int dasd_gendisk_alloc(struct dasd_block *block)
{
	struct gendisk *gdp;
	struct dasd_device *base;
	int len;

	/* Make sure the minor for this device exists. */
	base = block->base;
	if (base->devindex >= DASD_PER_MAJOR)
		return -EBUSY;

	gdp = alloc_disk(1 << DASD_PARTN_BITS);
	if (!gdp)
		return -ENOMEM;

	/* Initialize gendisk structure. */
	gdp->major = DASD_MAJOR;
	gdp->first_minor = base->devindex << DASD_PARTN_BITS;
	gdp->fops = &dasd_device_operations;
	gdp->driverfs_dev = &base->cdev->dev;

	/*
	 * Set device name.
	 *   dasda - dasdz : 26 devices
	 *   dasdaa - dasdzz : 676 devices, added up = 702
	 *   dasdaaa - dasdzzz : 17576 devices, added up = 18278
	 *   dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
	 */
	len = sprintf(gdp->disk_name, "dasd");
	if (base->devindex > 25) {
		if (base->devindex > 701) {
			if (base->devindex > 18277)
			        len += sprintf(gdp->disk_name + len, "%c",
					       'a'+(((base->devindex-18278)
						     /17576)%26));
			len += sprintf(gdp->disk_name + len, "%c",
				       'a'+(((base->devindex-702)/676)%26));
		}
		len += sprintf(gdp->disk_name + len, "%c",
			       'a'+(((base->devindex-26)/26)%26));
	}
	len += sprintf(gdp->disk_name + len, "%c", 'a'+(base->devindex%26));

	if (base->features & DASD_FEATURE_READONLY ||
	    test_bit(DASD_FLAG_DEVICE_RO, &base->flags))
		set_disk_ro(gdp, 1);
	gdp->private_data = block;
	gdp->queue = block->request_queue;
	block->gdp = gdp;
	set_capacity(block->gdp, 0);
	add_disk(block->gdp);
	return 0;
}
Exemplo n.º 28
0
static int __init looper_init(void) {
  
  if (filename == NULL) {
    printk(KERN_WARNING "looper: no filename defined");
    return -1;
  }

  /*
   * Set up our internal device.
   */
  Device.size = nsectors * logical_block_size;
  spin_lock_init(&Device.lock);
  Device.data = vmalloc(Device.size);
  if (Device.data == NULL)
    return -ENOMEM;
  /*
   * Get a request queue.
   */
  Queue = blk_init_queue(looper_request, &Device.lock);
  if (Queue == NULL)
    goto out;
  blk_queue_logical_block_size(Queue, logical_block_size);
  /*
   * Get registered.
   */
  major_num = register_blkdev(major_num, "looper");
  if (major_num <= 0) {
    printk(KERN_WARNING "looper: unable to get major number\n");
    goto out;
  }
  /*
   * And the gendisk structure.
   */
  Device.gd = alloc_disk(16);
  if (!Device.gd)
    goto out_unregister;
  Device.gd->major = major_num;
  Device.gd->first_minor = 0;
  Device.gd->fops = &looper_ops;
  Device.gd->private_data = &Device;
  strcpy(Device.gd->disk_name, "looper0");
  set_capacity(Device.gd, nsectors);
  Device.gd->queue = Queue;
  add_disk(Device.gd);
  
  return 0;
  
 out_unregister:
  unregister_blkdev(major_num, "looper");
 out:
  vfree(Device.data);
  return -ENOMEM;
}
Exemplo n.º 29
0
Arquivo: dm.c Projeto: wxlong/Test
static void __set_size(struct gendisk *disk, sector_t size)
{
	struct block_device *bdev;

	set_capacity(disk, size);
	bdev = bdget_disk(disk, 0);
	if (bdev) {
		down(&bdev->bd_inode->i_sem);
		i_size_write(bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
		up(&bdev->bd_inode->i_sem);
		bdput(bdev);
	}
}
Exemplo n.º 30
0
static int ide_floppy_init_media(ide_drive_t *drive, struct gendisk *disk)
{
	int ret = 0;

	if (ide_do_test_unit_ready(drive, disk))
		ide_do_start_stop(drive, disk, 1);

	ret = ide_floppy_get_capacity(drive);

	set_capacity(disk, ide_gd_capacity(drive));

	return ret;
}