/* * gendisk handling */#include<linux/module.h>#include<linux/fs.h>#include<linux/genhd.h>#include<linux/kdev_t.h>#include<linux/kernel.h>#include<linux/blkdev.h>#include<linux/init.h>#include<linux/spinlock.h>#include<linux/proc_fs.h>#include<linux/seq_file.h>#include<linux/slab.h>#include<linux/kmod.h>#include<linux/kobj_map.h>#include<linux/buffer_head.h>#include<linux/mutex.h>#include<linux/idr.h>#include"blk.h"staticDEFINE_MUTEX(block_class_lock);#ifndef CONFIG_SYSFS_DEPRECATEDstructkobject*block_depr;#endif/* for extended dynamic devt allocation, currently only one major is used */#define MAX_EXT_DEVT (1 << MINORBITS)/* For extended devt allocation. ext_devt_mutex prevents look up * results from going away underneath its user. */staticDEFINE_MUTEX(ext_devt_mutex);staticDEFINE_IDR(ext_devt_idr);staticstructdevice_typedisk_type;/** * disk_get_part - get partition * @disk: disk to look partition from * @partno: partition number * * Look for partition @partno from @disk. If found, increment * reference count and return it. * * CONTEXT: * Don't care. * * RETURNS: * Pointer to the found partition on success, NULL if not found. */structhd_struct*disk_get_part(structgendisk*disk,intpartno){structhd_struct*part=NULL;structdisk_part_tbl*ptbl;if(unlikely(partno<0))returnNULL;rcu_read_lock();ptbl=rcu_dereference(disk->part_tbl);if(likely(partno<ptbl->len)){part=rcu_dereference(ptbl->part[partno]);if(part)get_device(part_to_dev(part));}rcu_read_unlock();returnpart;}EXPORT_SYMBOL_GPL(disk_get_part);/** * disk_part_iter_init - initialize partition iterator * @piter: iterator to initialize * @disk: disk to iterate over * @flags: DISK_PITER_* flags * * Initialize @piter so that it iterates over partitions of @disk. * * CONTEXT: * Don't care. */voiddisk_part_iter_init(structdisk_part_iter*piter,structgendisk*disk,unsignedintflags){structdisk_part_tbl*ptbl;rcu_read_lock();ptbl=rcu_dereference(disk->part_tbl);piter->disk=disk;piter->part=NULL;if(flags&DISK_PITER_REVERSE)piter->idx=ptbl->len-1;elseif(flags&(DISK_PITER_INCL_PART0|DISK_PITER_INCL_EMPTY_PART0))piter->idx=0;elsepiter->idx=1;piter->flags=flags;rcu_read_unlock();}EXPORT_SYMBOL_GPL(disk_part_iter_init);/** * disk_part_iter_next - proceed iterator to the next partition and return it * @piter: iterator of interest * * Proceed @piter to the next partition and return it. * * CONTEXT: * Don't care. */structhd_struct*disk_part_iter_next(structdisk_part_iter*piter){structdisk_part_tbl*ptbl;