Lines Matching +full:parent +full:- +full:child
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
30 kfree(mtd->name); in free_partition()
34 static struct mtd_info *allocate_partition(struct mtd_info *parent, in allocate_partition() argument
38 struct mtd_info *master = mtd_get_master(parent); in allocate_partition()
39 int wr_alignment = (parent->flags & MTD_NO_ERASE) ? in allocate_partition()
40 master->writesize : master->erasesize; in allocate_partition()
41 u64 parent_size = mtd_is_partition(parent) ? in allocate_partition()
42 parent->part.size : parent->size; in allocate_partition()
43 struct mtd_info *child; in allocate_partition() local
49 child = kzalloc(sizeof(*child), GFP_KERNEL); in allocate_partition()
50 name = kstrdup(part->name, GFP_KERNEL); in allocate_partition()
51 if (!name || !child) { in allocate_partition()
53 parent->name); in allocate_partition()
55 kfree(child); in allocate_partition()
56 return ERR_PTR(-ENOMEM); in allocate_partition()
60 child->type = parent->type; in allocate_partition()
61 child->part.flags = parent->flags & ~part->mask_flags; in allocate_partition()
62 child->part.flags |= part->add_flags; in allocate_partition()
63 child->flags = child->part.flags; in allocate_partition()
64 child->part.size = part->size; in allocate_partition()
65 child->writesize = parent->writesize; in allocate_partition()
66 child->writebufsize = parent->writebufsize; in allocate_partition()
67 child->oobsize = parent->oobsize; in allocate_partition()
68 child->oobavail = parent->oobavail; in allocate_partition()
69 child->subpage_sft = parent->subpage_sft; in allocate_partition()
71 child->name = name; in allocate_partition()
72 child->owner = parent->owner; in allocate_partition()
79 * parent conditional on that option. Note, this is a way to in allocate_partition()
80 * distinguish between the parent and its partitions in sysfs. in allocate_partition()
82 child->dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ? in allocate_partition()
83 &parent->dev : parent->dev.parent; in allocate_partition()
84 child->dev.of_node = part->of_node; in allocate_partition()
85 child->parent = parent; in allocate_partition()
86 child->part.offset = part->offset; in allocate_partition()
87 INIT_LIST_HEAD(&child->partitions); in allocate_partition()
89 if (child->part.offset == MTDPART_OFS_APPEND) in allocate_partition()
90 child->part.offset = cur_offset; in allocate_partition()
91 if (child->part.offset == MTDPART_OFS_NXTBLK) { in allocate_partition()
93 child->part.offset = cur_offset; in allocate_partition()
96 child->part.offset += wr_alignment - remainder; in allocate_partition()
98 "0x%012llx -> 0x%012llx\n", partno, in allocate_partition()
100 child->part.offset); in allocate_partition()
103 if (child->part.offset == MTDPART_OFS_RETAIN) { in allocate_partition()
104 child->part.offset = cur_offset; in allocate_partition()
105 if (parent_size - child->part.offset >= child->part.size) { in allocate_partition()
106 child->part.size = parent_size - child->part.offset - in allocate_partition()
107 child->part.size; in allocate_partition()
110 part->name, parent_size - child->part.offset, in allocate_partition()
111 child->part.size); in allocate_partition()
116 if (child->part.size == MTDPART_SIZ_FULL) in allocate_partition()
117 child->part.size = parent_size - child->part.offset; in allocate_partition()
119 printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", in allocate_partition()
120 child->part.offset, child->part.offset + child->part.size, in allocate_partition()
121 child->name); in allocate_partition()
124 if (child->part.offset >= parent_size) { in allocate_partition()
126 child->part.offset = 0; in allocate_partition()
127 child->part.size = 0; in allocate_partition()
129 /* Initialize ->erasesize to make add_mtd_device() happy. */ in allocate_partition()
130 child->erasesize = parent->erasesize; in allocate_partition()
131 printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n", in allocate_partition()
132 part->name); in allocate_partition()
135 if (child->part.offset + child->part.size > parent->size) { in allocate_partition()
136 child->part.size = parent_size - child->part.offset; in allocate_partition()
137 …printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncate… in allocate_partition()
138 part->name, parent->name, child->part.size); in allocate_partition()
141 if (parent->numeraseregions > 1) { in allocate_partition()
143 int i, max = parent->numeraseregions; in allocate_partition()
144 u64 end = child->part.offset + child->part.size; in allocate_partition()
145 struct mtd_erase_region_info *regions = parent->eraseregions; in allocate_partition()
149 for (i = 0; i < max && regions[i].offset <= child->part.offset; in allocate_partition()
154 i--; in allocate_partition()
158 if (child->erasesize < regions[i].erasesize) in allocate_partition()
159 child->erasesize = regions[i].erasesize; in allocate_partition()
161 BUG_ON(child->erasesize == 0); in allocate_partition()
164 child->erasesize = master->erasesize; in allocate_partition()
168 * Child erasesize might differ from the parent one if the parent in allocate_partition()
172 if (!(child->flags & MTD_NO_ERASE)) in allocate_partition()
173 wr_alignment = child->erasesize; in allocate_partition()
175 tmp = mtd_get_master_ofs(child, 0); in allocate_partition()
177 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
181 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
182 …WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n", in allocate_partition()
183 part->name); in allocate_partition()
186 tmp = mtd_get_master_ofs(child, 0) + child->part.size; in allocate_partition()
188 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
189 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
190 …printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n… in allocate_partition()
191 part->name); in allocate_partition()
194 child->size = child->part.size; in allocate_partition()
195 child->ecc_step_size = parent->ecc_step_size; in allocate_partition()
196 child->ecc_strength = parent->ecc_strength; in allocate_partition()
197 child->bitflip_threshold = parent->bitflip_threshold; in allocate_partition()
199 if (master->_block_isbad) { in allocate_partition()
202 while (offs < child->part.size) { in allocate_partition()
203 if (mtd_block_isreserved(child, offs)) in allocate_partition()
204 child->ecc_stats.bbtblocks++; in allocate_partition()
205 else if (mtd_block_isbad(child, offs)) in allocate_partition()
206 child->ecc_stats.badblocks++; in allocate_partition()
207 offs += child->erasesize; in allocate_partition()
212 return child; in allocate_partition()
220 return snprintf(buf, PAGE_SIZE, "%lld\n", mtd->part.offset); in mtd_partition_offset_show()
232 int ret = sysfs_create_files(&new->dev.kobj, mtd_partition_attrs); in mtd_add_partition_attrs()
239 int mtd_add_partition(struct mtd_info *parent, const char *name, in mtd_add_partition() argument
242 struct mtd_info *master = mtd_get_master(parent); in mtd_add_partition()
243 u64 parent_size = mtd_is_partition(parent) ? in mtd_add_partition()
244 parent->part.size : parent->size; in mtd_add_partition()
246 struct mtd_info *child; in mtd_add_partition() local
252 return -EINVAL; in mtd_add_partition()
255 length = parent_size - offset; in mtd_add_partition()
258 return -EINVAL; in mtd_add_partition()
265 child = allocate_partition(parent, &part, -1, offset); in mtd_add_partition()
266 if (IS_ERR(child)) in mtd_add_partition()
267 return PTR_ERR(child); in mtd_add_partition()
269 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
270 list_add_tail(&child->part.node, &parent->partitions); in mtd_add_partition()
271 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
273 ret = add_mtd_device(child); in mtd_add_partition()
277 mtd_add_partition_attrs(child); in mtd_add_partition()
282 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
283 list_del(&child->part.node); in mtd_add_partition()
284 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
286 free_partition(child); in mtd_add_partition()
293 * __mtd_del_partition - delete MTD partition
301 struct mtd_info *child, *next; in __mtd_del_partition() local
304 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __mtd_del_partition()
305 err = __mtd_del_partition(child); in __mtd_del_partition()
310 sysfs_remove_files(&mtd->dev.kobj, mtd_partition_attrs); in __mtd_del_partition()
316 list_del(&child->part.node); in __mtd_del_partition()
328 struct mtd_info *child, *next; in __del_mtd_partitions() local
332 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __del_mtd_partitions()
333 if (mtd_has_partitions(child)) in __del_mtd_partitions()
334 del_mtd_partitions(child); in __del_mtd_partitions()
336 pr_info("Deleting %s MTD partition\n", child->name); in __del_mtd_partitions()
337 ret = del_mtd_device(child); in __del_mtd_partitions()
340 child->name, ret); in __del_mtd_partitions()
345 list_del(&child->part.node); in __del_mtd_partitions()
346 free_partition(child); in __del_mtd_partitions()
357 pr_info("Deleting MTD partitions on \"%s\":\n", mtd->name); in del_mtd_partitions()
359 mutex_lock(&master->master.partitions_lock); in del_mtd_partitions()
361 mutex_unlock(&master->master.partitions_lock); in del_mtd_partitions()
368 struct mtd_info *child, *master = mtd_get_master(mtd); in mtd_del_partition() local
369 int ret = -EINVAL; in mtd_del_partition()
371 mutex_lock(&master->master.partitions_lock); in mtd_del_partition()
372 list_for_each_entry(child, &mtd->partitions, part.node) { in mtd_del_partition()
373 if (child->index == partno) { in mtd_del_partition()
374 ret = __mtd_del_partition(child); in mtd_del_partition()
378 mutex_unlock(&master->master.partitions_lock); in mtd_del_partition()
385 * This function, given a parent MTD object and a partition table, creates
386 * and registers the child MTD objects which are bound to the parent according
389 * For historical reasons, this function's caller only registers the parent
393 int add_mtd_partitions(struct mtd_info *parent, in add_mtd_partitions() argument
397 struct mtd_info *child, *master = mtd_get_master(parent); in add_mtd_partitions() local
402 nbparts, parent->name); in add_mtd_partitions()
405 child = allocate_partition(parent, parts + i, i, cur_offset); in add_mtd_partitions()
406 if (IS_ERR(child)) { in add_mtd_partitions()
407 ret = PTR_ERR(child); in add_mtd_partitions()
411 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
412 list_add_tail(&child->part.node, &parent->partitions); in add_mtd_partitions()
413 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
415 ret = add_mtd_device(child); in add_mtd_partitions()
417 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
418 list_del(&child->part.node); in add_mtd_partitions()
419 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
421 free_partition(child); in add_mtd_partitions()
425 mtd_add_partition_attrs(child); in add_mtd_partitions()
428 parse_mtd_partitions(child, parts[i].types, NULL); in add_mtd_partitions()
430 cur_offset = child->part.offset + child->part.size; in add_mtd_partitions()
451 if (!strcmp(p->name, name) && try_module_get(p->owner)) { in mtd_part_parser_get()
463 module_put(p->owner); in mtd_part_parser_put()
478 p->owner = owner; in __register_mtd_parser()
480 if (!p->cleanup) in __register_mtd_parser()
481 p->cleanup = &mtd_part_parser_cleanup_default; in __register_mtd_parser()
484 list_add(&p->list, &part_parsers); in __register_mtd_parser()
494 list_del(&p->list); in deregister_mtd_parser()
522 ret = (*parser->parse_fn)(master, &pparts->parts, data); in mtd_part_do_parse()
523 pr_debug("%s: parser %s: %i\n", master->name, parser->name, ret); in mtd_part_do_parse()
528 parser->name, master->name); in mtd_part_do_parse()
530 pparts->nr_parts = ret; in mtd_part_do_parse()
531 pparts->parser = parser; in mtd_part_do_parse()
537 * mtd_part_get_compatible_parser - find MTD parser by a compatible string
554 matches = p->of_match_table; in mtd_part_get_compatible_parser()
558 for (; matches->compatible[0]; matches++) { in mtd_part_get_compatible_parser()
559 if (!strcmp(matches->compatible, compat) && in mtd_part_get_compatible_parser()
560 try_module_get(p->owner)) { in mtd_part_get_compatible_parser()
582 const char *fixed = "fixed-partitions"; in mtd_part_of_parse()
607 * For backward compatibility we have to try the "fixed-partitions" in mtd_part_of_parse()
628 * parse_mtd_partitions - parse and register MTD partitions
632 * @data: MTD partition parser-specific data
665 pr_debug("%s: parsing partitions %s\n", master->name, in parse_mtd_partitions()
670 pr_debug("%s: got parser %s\n", master->name, in parse_mtd_partitions()
671 parser ? parser->name : NULL); in parse_mtd_partitions()
702 parser = parts->parser; in mtd_part_parser_cleanup()
704 if (parser->cleanup) in mtd_part_parser_cleanup()
705 parser->cleanup(parts->parts, parts->nr_parts); in mtd_part_parser_cleanup()
716 return master->size; in mtd_get_device_size()