|
CardSight 0.1.0
C API reference for the CardSight firmware and application
|
Block devices: disks made by a driver, the partitions found in their table, and the checked transfers on them. More...
Go to the source code of this file.
Data Structures | |
| struct | block_device_operations |
| Operations a disk driver provides to the block layer. More... | |
| struct | block_device |
| One openable view of a disk: the whole disk or one partition. More... | |
| struct | gendisk |
| A disk as a driver describes it to the block layer. More... | |
| struct | blk_partition_layout_entry |
| One partition to create, in disk order. More... | |
Enumerations | |
| enum | blk_partition_table_type { BLK_PARTITION_TABLE_MBR , BLK_PARTITION_TABLE_GPT } |
| Partition table format written by blk_write_partition_layout(). More... | |
| enum | blk_partition_content { BLK_PARTITION_FAT32 , BLK_PARTITION_EXFAT , BLK_PARTITION_EXT4 } |
| File system marker stored in a created partition. More... | |
Functions | |
| struct gendisk * | alloc_disk (void) |
| Allocate a zeroed disk with its whole-disk block device. | |
| void | put_disk (struct gendisk *disk) |
| Drop the caller's reference to a disk. | |
| int | add_disk (struct gendisk *disk) |
| Register the disk and read its partition table. | |
| int | del_gendisk (struct gendisk *disk) |
| Take the disk and its partitions away. | |
| void | del_gendisk_force (struct gendisk *disk) |
| Remove the disk without checking its mounts. | |
| struct block_device * | bdev_open_by_name (const char *name) |
| Open a registered block device by name. | |
| void | bdev_close (struct block_device *bdev) |
| Drop one opener of a block device. | |
| int | bdev_read (struct block_device *bdev, uint64_t sector, void *buffer, uint32_t count) |
| Read sectors through a block device view. | |
| int | bdev_write (struct block_device *bdev, uint64_t sector, const void *buffer, uint32_t count) |
| Write sectors through a block device view. | |
| int | bdev_flush (struct block_device *bdev) |
| Ask the disk behind a block device to write out its cached writes. | |
| bool | bdev_read_only (const struct block_device *bdev) |
| Report whether a block device refuses writes. | |
| uint64_t | bdev_nr_sectors (const struct block_device *bdev) |
| Length of a block device in sectors. | |
| uint32_t | bdev_sector_size (const struct block_device *bdev) |
| Logical sector size of the disk behind a block device. | |
| bool | bdev_is_whole (const struct block_device *bdev) |
| Report whether a block device covers a whole disk. | |
| const char * | bdev_name (const struct block_device *bdev) |
| Name of a block device as registered. | |
| int | bdev_claim_mount (struct block_device *bdev) |
| Claim a block device for one file system instance. | |
| void | bdev_release_mount (struct block_device *bdev) |
| Release the mount claim of a block device. | |
| int | blk_erase_partition_table (struct gendisk *disk) |
| Erase the MBR and both GPT copies. | |
| int | blk_write_partition_layout (struct gendisk *disk, enum blk_partition_table_type table, const struct blk_partition_layout_entry *entries, uint32_t count) |
| Write a fresh partition table and rescan it. | |
Block devices: disks made by a driver, the partitions found in their table, and the checked transfers on them.
A disk driver fills a struct gendisk from alloc_disk() and registers it with add_disk(); the whole disk is "part0" and the partitions are "<disk>p<N>". Access goes through a struct block_device opened by name.
The calls are synchronous and run in the caller's task; read and write buffers must be 64-byte aligned (the card driver does DMA on them).
Partition table format written by blk_write_partition_layout().
| Enumerator | |
|---|---|
| BLK_PARTITION_TABLE_MBR | Master boot record, four primary entries. |
| BLK_PARTITION_TABLE_GPT | GUID partition table, primary and backup copies. |
| int add_disk | ( | struct gendisk * | disk | ) |
Register the disk and read its partition table.
The name and operations are validated, then the whole-disk view is registered and the MBR or GPT is scanned. A table that cannot be read is logged and the disk stays without partitions.
| [in] | disk | Disk to register. |
| struct gendisk * alloc_disk | ( | void | ) |
Allocate a zeroed disk with its whole-disk block device.
part0 ready, or NULL when out of memory. | int bdev_claim_mount | ( | struct block_device * | bdev | ) |
Claim a block device for one file system instance.
A file system keeps a device claimed from its mount to its unmount.
| [in] | bdev | Device to claim. |
| void bdev_close | ( | struct block_device * | bdev | ) |
Drop one opener of a block device.
The last close of a live disk flushes it, so writes it held back reach the media.
| [in] | bdev | Device to close; NULL is ignored. |
| int bdev_flush | ( | struct block_device * | bdev | ) |
Ask the disk behind a block device to write out its cached writes.
| [in] | bdev | Device to flush. |
| bool bdev_is_whole | ( | const struct block_device * | bdev | ) |
Report whether a block device covers a whole disk.
| [in] | bdev | Device to query. |
| const char * bdev_name | ( | const struct block_device * | bdev | ) |
Name of a block device as registered.
| [in] | bdev | Device to query. |
| uint64_t bdev_nr_sectors | ( | const struct block_device * | bdev | ) |
Length of a block device in sectors.
| [in] | bdev | Device to query. |
| struct block_device * bdev_open_by_name | ( | const char * | name | ) |
Open a registered block device by name.
| [in] | name | Device name such as "mmcblk0", "mmcblk0p1", or "/dev/...". |
| int bdev_read | ( | struct block_device * | bdev, |
| uint64_t | sector, | ||
| void * | buffer, | ||
| uint32_t | count ) |
Read sectors through a block device view.
| [in] | bdev | Device to read from. |
| [in] | sector | First sector inside the device. |
| [out] | buffer | Destination buffer; 64-byte aligned. |
| [in] | count | Number of sectors. |
| bool bdev_read_only | ( | const struct block_device * | bdev | ) |
Report whether a block device refuses writes.
| [in] | bdev | Device to query. |
| uint32_t bdev_sector_size | ( | const struct block_device * | bdev | ) |
Logical sector size of the disk behind a block device.
| [in] | bdev | Device to query. |
| int bdev_write | ( | struct block_device * | bdev, |
| uint64_t | sector, | ||
| const void * | buffer, | ||
| uint32_t | count ) |
Write sectors through a block device view.
| [in] | bdev | Device to write to. |
| [in] | sector | First sector inside the device. |
| [in] | buffer | Source buffer; 64-byte aligned. |
| [in] | count | Number of sectors. |
| int blk_erase_partition_table | ( | struct gendisk * | disk | ) |
Erase the MBR and both GPT copies.
Zeroes the first 512 KiB (some cards carry a boot image in front of the table and the SoC would try to run it) and the backup GPT copy at the end of the disk, then rescans, leaving the card without a partition table. File data itself is left where it is.
| [in] | disk | Registered disk to erase. |
| int blk_write_partition_layout | ( | struct gendisk * | disk, |
| enum blk_partition_table_type | table, | ||
| const struct blk_partition_layout_entry * | entries, | ||
| uint32_t | count ) |
Write a fresh partition table and rescan it.
Entries are placed with 1 MiB alignment, at most four of them for the MBR; the first entry starts at sector 2048. The table is flushed and rescanned before the call returns.
| [in] | disk | Registered disk to write. |
| [in] | table | Table format to write. |
| [in] | entries | Partitions to create, in disk order. |
| [in] | count | Number of entries in entries. |
| int del_gendisk | ( | struct gendisk * | disk | ) |
Take the disk and its partitions away.
| [in] | disk | Disk to remove. |
| void del_gendisk_force | ( | struct gendisk * | disk | ) |
Remove the disk without checking its mounts.
The same as del_gendisk() but without the -EBUSY, for a card that is gone.
| [in] | disk | Disk to remove. |
| void put_disk | ( | struct gendisk * | disk | ) |
Drop the caller's reference to a disk.
Call after del_gendisk(), or after a failed add_disk().
| [in] | disk | Disk to release; NULL is ignored. |