Linux 4.14-rc6
[linux-block.git] / block / partitions / check.h
CommitLineData
1da177e4
LT
1#include <linux/pagemap.h>
2#include <linux/blkdev.h>
6d1d8050 3#include <linux/genhd.h>
1da177e4
LT
4
5/*
6 * add_gd_partition adds a partitions details to the devices partition
7 * description.
8 */
1da177e4 9struct parsed_partitions {
1493bf21 10 struct block_device *bdev;
1da177e4
LT
11 char name[BDEVNAME_SIZE];
12 struct {
13 sector_t from;
14 sector_t size;
15 int flags;
6d1d8050
WD
16 bool has_info;
17 struct partition_meta_info info;
ac2e5327 18 } *parts;
1da177e4
LT
19 int next;
20 int limit;
b403a98e 21 bool access_beyond_eod;
9c867fbe 22 char *pp_buf;
1da177e4
LT
23};
24
ac2e5327
ML
25void free_partitions(struct parsed_partitions *state);
26
94ea4158
AV
27struct parsed_partitions *
28check_partition(struct gendisk *, struct block_device *);
29
1493bf21
TH
30static inline void *read_part_sector(struct parsed_partitions *state,
31 sector_t n, Sector *p)
32{
b403a98e
TH
33 if (n >= get_capacity(state->bdev->bd_disk)) {
34 state->access_beyond_eod = true;
35 return NULL;
36 }
1493bf21
TH
37 return read_dev_sector(state->bdev, n, p);
38}
39
1da177e4
LT
40static inline void
41put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
42{
43 if (n < p->limit) {
9c867fbe
AD
44 char tmp[1 + BDEVNAME_SIZE + 10 + 1];
45
1da177e4
LT
46 p->parts[n].from = from;
47 p->parts[n].size = size;
9c867fbe
AD
48 snprintf(tmp, sizeof(tmp), " %s%d", p->name, n);
49 strlcat(p->pp_buf, tmp, PAGE_SIZE);
1da177e4
LT
50 }
51}
52
53extern int warn_no_part;
54