blob: 6042f769471abbbe3ae6d172b22cf01a38feaf30 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/pagemap.h>
3#include <linux/blkdev.h>
Will Drewry6d1d8052010-08-31 15:47:05 -05004#include <linux/genhd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6/*
7 * add_gd_partition adds a partitions details to the devices partition
8 * description.
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010struct parsed_partitions {
Tejun Heo1493bf22010-05-15 20:09:30 +020011 struct block_device *bdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 char name[BDEVNAME_SIZE];
13 struct {
14 sector_t from;
15 sector_t size;
16 int flags;
Will Drewry6d1d8052010-08-31 15:47:05 -050017 bool has_info;
18 struct partition_meta_info info;
Ming Leiac2e5322013-02-27 17:05:19 -080019 } *parts;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 int next;
21 int limit;
Tejun Heob403a982010-05-15 20:09:31 +020022 bool access_beyond_eod;
Alexey Dobriyan9c867fb2010-08-10 18:03:14 -070023 char *pp_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024};
25
Ming Leiac2e5322013-02-27 17:05:19 -080026void free_partitions(struct parsed_partitions *state);
27
Al Viro94ea4152011-09-16 00:45:36 -040028struct parsed_partitions *
29check_partition(struct gendisk *, struct block_device *);
30
Tejun Heo1493bf22010-05-15 20:09:30 +020031static inline void *read_part_sector(struct parsed_partitions *state,
32 sector_t n, Sector *p)
33{
Tejun Heob403a982010-05-15 20:09:31 +020034 if (n >= get_capacity(state->bdev->bd_disk)) {
35 state->access_beyond_eod = true;
36 return NULL;
37 }
Tejun Heo1493bf22010-05-15 20:09:30 +020038 return read_dev_sector(state->bdev, n, p);
39}
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static inline void
42put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
43{
44 if (n < p->limit) {
Alexey Dobriyan9c867fb2010-08-10 18:03:14 -070045 char tmp[1 + BDEVNAME_SIZE + 10 + 1];
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 p->parts[n].from = from;
48 p->parts[n].size = size;
Alexey Dobriyan9c867fb2010-08-10 18:03:14 -070049 snprintf(tmp, sizeof(tmp), " %s%d", p->name, n);
50 strlcat(p->pp_buf, tmp, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
52}
53
54extern int warn_no_part;
55