Commit ebac37cfbfb32ea44704fe032fadd5cf334824b7
1 parent
db1d9e78e6
Exists in
v2017.01-smarct4x
and in
29 other branches
dm: blk: Rename get_device() to blk_get_device_by_str()
The current name is too generic. The function returns a block device based on a provided string. Rename it to aid searching and make its purpose clearer. Also add a few comments. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Stephen Warren <swarren@nvidia.com>
Showing 6 changed files with 39 additions and 13 deletions Side-by-side Diff
cmd/part.c
... | ... | @@ -81,7 +81,7 @@ |
81 | 81 | return CMD_RET_USAGE; |
82 | 82 | } |
83 | 83 | |
84 | - ret = get_device(argv[0], argv[1], &desc); | |
84 | + ret = blk_get_device_by_str(argv[0], argv[1], &desc); | |
85 | 85 | if (ret < 0) |
86 | 86 | return 1; |
87 | 87 | |
... | ... | @@ -128,7 +128,7 @@ |
128 | 128 | |
129 | 129 | part = simple_strtoul(argv[2], NULL, 0); |
130 | 130 | |
131 | - ret = get_device(argv[0], argv[1], &desc); | |
131 | + ret = blk_get_device_by_str(argv[0], argv[1], &desc); | |
132 | 132 | if (ret < 0) |
133 | 133 | return 1; |
134 | 134 | |
... | ... | @@ -162,7 +162,7 @@ |
162 | 162 | |
163 | 163 | part = simple_strtoul(argv[2], NULL, 0); |
164 | 164 | |
165 | - ret = get_device(argv[0], argv[1], &desc); | |
165 | + ret = blk_get_device_by_str(argv[0], argv[1], &desc); | |
166 | 166 | if (ret < 0) |
167 | 167 | return 1; |
168 | 168 |
cmd/unzip.c
cmd/usb_mass_storage.c
disk/part.c
... | ... | @@ -449,8 +449,8 @@ |
449 | 449 | return -1; |
450 | 450 | } |
451 | 451 | |
452 | -int get_device(const char *ifname, const char *dev_hwpart_str, | |
453 | - struct blk_desc **dev_desc) | |
452 | +int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, | |
453 | + struct blk_desc **dev_desc) | |
454 | 454 | { |
455 | 455 | char *ep; |
456 | 456 | char *dup_str = NULL; |
... | ... | @@ -598,7 +598,7 @@ |
598 | 598 | } |
599 | 599 | |
600 | 600 | /* Look up the device */ |
601 | - dev = get_device(ifname, dev_str, dev_desc); | |
601 | + dev = blk_get_device_by_str(ifname, dev_str, dev_desc); | |
602 | 602 | if (dev < 0) |
603 | 603 | goto cleanup; |
604 | 604 |
include/part.h
... | ... | @@ -101,8 +101,34 @@ |
101 | 101 | void print_part(struct blk_desc *dev_desc); |
102 | 102 | void init_part(struct blk_desc *dev_desc); |
103 | 103 | void dev_print(struct blk_desc *dev_desc); |
104 | -int get_device(const char *ifname, const char *dev_str, | |
105 | - struct blk_desc **dev_desc); | |
104 | + | |
105 | +/** | |
106 | + * blk_get_device_by_str() - Get a block device given its interface/hw partition | |
107 | + * | |
108 | + * Each interface allocates its own devices and typically struct blk_desc is | |
109 | + * contained with the interface's data structure. There is no global | |
110 | + * numbering for block devices, so the interface name must be provided. | |
111 | + * | |
112 | + * The hardware parition is not related to the normal software partitioning | |
113 | + * of a device - each hardware partition is effectively a separately | |
114 | + * accessible block device. When a hardware parition is selected on MMC the | |
115 | + * other hardware partitions become inaccessible. The same block device is | |
116 | + * used to access all hardware partitions, but its capacity may change when a | |
117 | + * different hardware partition is selected. | |
118 | + * | |
119 | + * When a hardware partition number is given, the block device switches to | |
120 | + * that hardware partition. | |
121 | + * | |
122 | + * @ifname: Interface name (e.g. "ide", "scsi") | |
123 | + * @dev_str: Device and optional hw partition. This can either be a string | |
124 | + * containing the device number (e.g. "2") or the device number | |
125 | + * and hardware partition number (e.g. "2.4") for devices that | |
126 | + * support it (currently only MMC). | |
127 | + * @dev_desc: Returns a pointer to the block device on success | |
128 | + * @return block device number (local to the interface), or -1 on error | |
129 | + */ | |
130 | +int blk_get_device_by_str(const char *ifname, const char *dev_str, | |
131 | + struct blk_desc **dev_desc); | |
106 | 132 | int get_device_and_partition(const char *ifname, const char *dev_part_str, |
107 | 133 | struct blk_desc **dev_desc, |
108 | 134 | disk_partition_t *info, int allow_whole_dev); |
... | ... | @@ -124,8 +150,8 @@ |
124 | 150 | static inline void print_part(struct blk_desc *dev_desc) {} |
125 | 151 | static inline void init_part(struct blk_desc *dev_desc) {} |
126 | 152 | static inline void dev_print(struct blk_desc *dev_desc) {} |
127 | -static inline int get_device(const char *ifname, const char *dev_str, | |
128 | - struct blk_desc **dev_desc) | |
153 | +static inline int blk_get_device_by_str(const char *ifname, const char *dev_str, | |
154 | + struct blk_desc **dev_desc) | |
129 | 155 | { return -1; } |
130 | 156 | static inline int get_device_and_partition(const char *ifname, |
131 | 157 | const char *dev_part_str, |
test/dm/usb.c
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 | state_set_skip_delays(true); |
46 | 46 | ut_assertok(usb_init()); |
47 | 47 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev)); |
48 | - ut_assertok(get_device("usb", "0", &dev_desc)); | |
48 | + ut_assertok(blk_get_device_by_str("usb", "0", &dev_desc)); | |
49 | 49 | |
50 | 50 | /* Read a few blocks and look for the string we expect */ |
51 | 51 | ut_asserteq(512, dev_desc->blksz); |