Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
genhd.c File Reference
#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/mutex.h>
#include <linux/idr.h>
#include <linux/log2.h>
#include "blk.h"

Go to the source code of this file.

Data Structures

struct  blk_major_name
struct  disk_events


#define MAX_EXT_DEVT   (1 << MINORBITS)


struct hd_struct * disk_get_part (struct gendisk *disk, int partno)
 EXPORT_SYMBOL_GPL (disk_get_part)
void disk_part_iter_init (struct disk_part_iter *piter, struct gendisk *disk, unsigned int flags)
 EXPORT_SYMBOL_GPL (disk_part_iter_init)
struct hd_struct * disk_part_iter_next (struct disk_part_iter *piter)
 EXPORT_SYMBOL_GPL (disk_part_iter_next)
void disk_part_iter_exit (struct disk_part_iter *piter)
 EXPORT_SYMBOL_GPL (disk_part_iter_exit)
struct hd_struct * disk_map_sector_rcu (struct gendisk *disk, sector_t sector)
 EXPORT_SYMBOL_GPL (disk_map_sector_rcu)


struct kobjectblock_depr

must be unique within the system.

The return value depends on the input parameter.

  • if a major device number was requested in range [1..255] then the function returns zero on success, or a negative error code
  • if any unused major number was requested with =0 parameter then the return value is the allocated major number in range [1..255] or a negative error code otherwise
#define MODULE_PARAM_PREFIX   "block."
struct class block_class
int register_blkdev (unsigned int major, const char *name)
 EXPORT_SYMBOL (register_blkdev)
void unregister_blkdev (unsigned int major, const char *name)
 EXPORT_SYMBOL (unregister_blkdev)
int blk_alloc_devt (struct hd_struct *part, dev_t *devt)
void blk_free_devt (dev_t devt)
void blk_register_region (dev_t devt, unsigned long range, struct module *module, struct kobject *(*probe)(dev_t, int *, void *), int(*lock)(dev_t, void *), void *data)
 EXPORT_SYMBOL (blk_register_region)
void blk_unregister_region (dev_t devt, unsigned long range)
 EXPORT_SYMBOL (blk_unregister_region)
void add_disk (struct gendisk *disk)
 EXPORT_SYMBOL (add_disk)
void del_gendisk (struct gendisk *disk)
 EXPORT_SYMBOL (del_gendisk)
struct gendisk * get_gendisk (dev_t devt, int *partno)
 EXPORT_SYMBOL (get_gendisk)
struct block_devicebdget_disk (struct gendisk *disk, int partno)
 EXPORT_SYMBOL (bdget_disk)
void __init printk_all_partitions (void)
 subsys_initcall (genhd_device_init)
int disk_expand_part_tbl (struct gendisk *disk, int partno)
dev_t blk_lookup_devt (const char *name, int partno)
 EXPORT_SYMBOL (blk_lookup_devt)
struct gendisk * alloc_disk (int minors)
 EXPORT_SYMBOL (alloc_disk)
struct gendisk * alloc_disk_node (int minors, int node_id)
 EXPORT_SYMBOL (alloc_disk_node)
struct kobjectget_disk (struct gendisk *disk)
 EXPORT_SYMBOL (get_disk)
void put_disk (struct gendisk *disk)
 EXPORT_SYMBOL (put_disk)
void set_device_ro (struct block_device *bdev, int flag)
 EXPORT_SYMBOL (set_device_ro)
void set_disk_ro (struct gendisk *disk, int flag)
 EXPORT_SYMBOL (set_disk_ro)
int bdev_read_only (struct block_device *bdev)
 EXPORT_SYMBOL (bdev_read_only)
int invalidate_partition (struct gendisk *disk, int partno)
 EXPORT_SYMBOL (invalidate_partition)
void disk_block_events (struct gendisk *disk)
void disk_unblock_events (struct gendisk *disk)
void disk_flush_events (struct gendisk *disk, unsigned int mask)
unsigned int disk_clear_events (struct gendisk *disk, unsigned int mask)
 module_param_cb (events_dfl_poll_msecs,&disk_events_dfl_poll_msecs_param_ops,&disk_events_dfl_poll_msecs, 0644)

Macro Definition Documentation

#define MAX_EXT_DEVT   (1 << MINORBITS)

Definition at line 28 of file genhd.c.

#define MODULE_PARAM_PREFIX   "block."

Definition at line 1743 of file genhd.c.

Function Documentation

void add_disk ( struct gendisk *  disk)

add_disk - add partitioning information to kernel list : per-device partitioning information

This function registers the partitioning information in with the kernel.

FIXME: error handling

Definition at line 577 of file genhd.c.

struct gendisk* alloc_disk ( int  minors)

Definition at line 1246 of file genhd.c.

struct gendisk* alloc_disk_node ( int  minors,
int  node_id 

Definition at line 1252 of file genhd.c.

int bdev_read_only ( struct block_device bdev)

Definition at line 1357 of file genhd.c.

struct block_device* bdget_disk ( struct gendisk *  disk,
int  partno 

bdget_disk - do bdget() by gendisk and partition number : gendisk of interest : partition number

Find partition from , do bdget() on it.

CONTEXT: Don't care.

RETURNS: Resulting block_device on success, NULL on failure.

Definition at line 715 of file genhd.c.

int blk_alloc_devt ( struct hd_struct *  part,
dev_t devt 

blk_alloc_devt - allocate a dev_t for a partition : partition to allocate dev_t for : out parameter for resulting dev_t

Allocate a dev_t for block device.

RETURNS: 0 on success, allocated dev_t is returned in *. -errno on failure.

CONTEXT: Might sleep.

Definition at line 408 of file genhd.c.

void blk_free_devt ( dev_t  devt)

blk_free_devt - free a dev_t : dev_t to free

Free which was allocated using blk_alloc_devt().

CONTEXT: Might sleep.

Definition at line 447 of file genhd.c.

dev_t blk_lookup_devt ( const char name,
int  partno 

Definition at line 1211 of file genhd.c.

void blk_register_region ( dev_t  devt,
unsigned long  range,
struct module module,
struct kobject *(*)(dev_t, int *, void *)  probe,
int(*)(dev_t, void *)  lock,
void data 

Definition at line 478 of file genhd.c.

void blk_unregister_region ( dev_t  devt,
unsigned long  range 

Definition at line 487 of file genhd.c.

void del_gendisk ( struct gendisk *  disk)

Definition at line 630 of file genhd.c.

void disk_block_events ( struct gendisk *  disk)

disk_block_events - block and flush disk event checking : disk to block events for

On return from this function, it is guaranteed that event checking isn't in progress and won't happen until unblocked by disk_unblock_events(). Events blocking is counted and the actual unblocking happens after the matching number of unblocks are done.

Note that this intentionally does not block event checking from disk_clear_events().

CONTEXT: Might sleep.

Definition at line 1447 of file genhd.c.

unsigned int disk_clear_events ( struct gendisk *  disk,
unsigned int  mask 

disk_clear_events - synchronously check, clear and return pending events : disk to fetch and clear events from : mask of events to be fetched and clearted

Disk events are synchronously checked and pending events in are cleared and returned. This ignores the block count.

CONTEXT: Might sleep.

Definition at line 1553 of file genhd.c.

int disk_expand_part_tbl ( struct gendisk *  disk,
int  partno 

disk_expand_part_tbl - expand disk->part_tbl : disk to expand part_tbl for : expand such that this partno can fit in

Expand disk->part_tbl such that can fit in. disk->part_tbl uses RCU to allow unlocked dereferencing for stats and other stuff.

LOCKING: Matching bd_mutex locked, might sleep.

RETURNS: 0 on success, -errno on failure.

Definition at line 1069 of file genhd.c.

void disk_flush_events ( struct gendisk *  disk,
unsigned int  mask 

disk_flush_events - schedule immediate event checking and flushing : disk to check and flush events for : events to flush

Schedule immediate event checking on if not blocked. Events in are scheduled to be cleared from the driver. Note that this doesn't clear the events from ->ev.

CONTEXT: If is non-zero must be called with bdev->bd_mutex held.

Definition at line 1528 of file genhd.c.

struct hd_struct* disk_get_part ( struct gendisk *  disk,
int  partno 

disk_get_part - get partition : disk to look partition from : partition number

Look for partition from . If found, increment reference count and return it.

CONTEXT: Don't care.

RETURNS: Pointer to the found partition on success, NULL if not found.

Definition at line 57 of file genhd.c.

struct hd_struct* disk_map_sector_rcu ( struct gendisk *  disk,
sector_t  sector 

disk_map_sector_rcu - map sector to partition : gendisk of interest : sector to map

Find out which partition maps to on . This is primarily used for stats accounting.

CONTEXT: RCU read locked. The returned partition pointer is valid only while preemption is disabled.

RETURNS: Found partition on success, part0 is returned if no partition matches

Definition at line 212 of file genhd.c.

void disk_part_iter_exit ( struct disk_part_iter *  piter)

disk_part_iter_exit - finish up partition iteration : iter of interest

Called when iteration is over. Cleans up .

CONTEXT: Don't care.

Definition at line 184 of file genhd.c.

void disk_part_iter_init ( struct disk_part_iter *  piter,
struct gendisk *  disk,
unsigned int  flags 

disk_part_iter_init - initialize partition iterator : iterator to initialize : disk to iterate over : DISK_PITER_* flags

Initialize so that it iterates over partitions of .

CONTEXT: Don't care.

Definition at line 91 of file genhd.c.

struct hd_struct* disk_part_iter_next ( struct disk_part_iter *  piter)

disk_part_iter_next - proceed iterator to the next partition and return it : iterator of interest

Proceed to the next partition and return it.

CONTEXT: Don't care.

Definition at line 124 of file genhd.c.

void disk_unblock_events ( struct gendisk *  disk)

disk_unblock_events - unblock disk event checking : disk to unblock events for

Undo disk_block_events(). When the block count reaches zero, it starts events polling if configured.

CONTEXT: Don't care. Safe to call from irq context.

Definition at line 1510 of file genhd.c.

EXPORT_SYMBOL ( register_blkdev  )
EXPORT_SYMBOL ( unregister_blkdev  )
EXPORT_SYMBOL ( blk_register_region  )
EXPORT_SYMBOL ( blk_unregister_region  )
EXPORT_SYMBOL ( add_disk  )
EXPORT_SYMBOL ( del_gendisk  )
EXPORT_SYMBOL ( get_gendisk  )
EXPORT_SYMBOL ( bdget_disk  )
EXPORT_SYMBOL ( blk_lookup_devt  )
EXPORT_SYMBOL ( alloc_disk  )
EXPORT_SYMBOL ( alloc_disk_node  )
EXPORT_SYMBOL ( get_disk  )
EXPORT_SYMBOL ( put_disk  )
EXPORT_SYMBOL ( set_device_ro  )
EXPORT_SYMBOL ( set_disk_ro  )
EXPORT_SYMBOL ( bdev_read_only  )
EXPORT_SYMBOL ( invalidate_partition  )
EXPORT_SYMBOL_GPL ( disk_get_part  )
EXPORT_SYMBOL_GPL ( disk_part_iter_init  )
EXPORT_SYMBOL_GPL ( disk_part_iter_next  )
EXPORT_SYMBOL_GPL ( disk_part_iter_exit  )
EXPORT_SYMBOL_GPL ( disk_map_sector_rcu  )
struct kobject* get_disk ( struct gendisk *  disk)

Definition at line 1293 of file genhd.c.

struct gendisk* get_gendisk ( dev_t  devt,
int partno 

get_gendisk - get partitioning information for a given device : device to get partitioning information for : returned partition index

This function gets the structure containing partitioning information for the given device .

Definition at line 676 of file genhd.c.

int invalidate_partition ( struct gendisk *  disk,
int  partno 

Definition at line 1366 of file genhd.c.

module_param_cb ( events_dfl_poll_msecs  ,
void __init printk_all_partitions ( void  )

Definition at line 734 of file genhd.c.

void put_disk ( struct gendisk *  disk)

Definition at line 1314 of file genhd.c.

int register_blkdev ( unsigned int  major,
const char name 

Definition at line 282 of file genhd.c.

void set_device_ro ( struct block_device bdev,
int  flag 

Definition at line 1332 of file genhd.c.

void set_disk_ro ( struct gendisk *  disk,
int  flag 

Definition at line 1339 of file genhd.c.

subsys_initcall ( genhd_device_init  )
void unregister_blkdev ( unsigned int  major,
const char name 

Definition at line 338 of file genhd.c.

Variable Documentation

struct class block_class
Initial value:
= {
.name = "block",

Definition at line 1112 of file genhd.c.

struct kobject* block_depr

Definition at line 25 of file genhd.c.