static int parse_afs_partitions(struct mtd_info *mtd, struct mtd_partition **pparts, struct mtd_part_parser_data *data) { struct mtd_partition *parts; u_int mask, off, idx, sz; int ret = 0; char *str; /* * This is the address mask; we use this to mask off out of * range address bits. */ mask = mtd->size - 1; /* * First, calculate the size of the array we need for the * partition information. We include in this the size of * the strings. */ for (idx = off = sz = 0; off < mtd->size; off += mtd->erasesize) { struct image_info_struct iis; u_int iis_ptr, img_ptr; ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask); if (ret < 0) break; if (ret == 0) continue; ret = afs_read_iis(mtd, &iis, iis_ptr); if (ret < 0) break; if (ret == 0) continue; sz += sizeof(struct mtd_partition); sz += strlen(iis.name) + 1; idx += 1; } if (!sz) return ret; parts = kzalloc(sz, GFP_KERNEL); if (!parts) return -ENOMEM; str = (char *)(parts + idx); /* * Identify the partitions */ for (idx = off = 0; off < mtd->size; off += mtd->erasesize) { struct image_info_struct iis; u_int iis_ptr, img_ptr; /* Read the footer. */ ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask); if (ret < 0) break; if (ret == 0) continue; /* Read the image info block */ ret = afs_read_iis(mtd, &iis, iis_ptr); if (ret < 0) break; if (ret == 0) continue; strcpy(str, iis.name); parts[idx].name = str; parts[idx].size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); parts[idx].offset = img_ptr; parts[idx].mask_flags = 0; printk(" mtd%d: at 0x%08x, %5lluKiB, %8u, %s\n", idx, img_ptr, parts[idx].size / 1024, iis.imageNumber, str); idx += 1; str = str + strlen(iis.name) + 1; } if (!idx) { kfree(parts); parts = NULL; } *pparts = parts; return idx ? idx : ret; }
int parse_afs_partitions(struct mtd_info *mtd, struct mtd_partition **pparts) { struct mtd_partition *parts; u_int mask, off, idx, sz; int ret = 0; char *str; /* * This is the address mask; we use this to mask off out of * range address bits. */ mask = mtd->size - 1; /* * First, calculate the size of the array we need for the * partition information. We include in this the size of * the strings. */ for (idx = off = sz = 0; off < mtd->size; off += mtd->erasesize) { struct image_info_struct iis; u_int iis_ptr, img_ptr; ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask); if (ret < 0) break; if (ret == 1) continue; ret = afs_read_iis(mtd, &iis, iis_ptr); if (ret < 0) break; sz += sizeof(struct mtd_partition); sz += strlen(iis.name) + 1; idx += 1; } if (!sz) return ret; parts = kmalloc(sz, GFP_KERNEL); if (!parts) return -ENOMEM; str = (char *)(parts + idx); /* * Identify the partitions */ for (idx = off = 0; off < mtd->size; off += mtd->erasesize) { struct image_info_struct iis; u_int iis_ptr, img_ptr, size; /* Read the footer. */ ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask); if (ret < 0) break; if (ret == 1) continue; /* Read the image info block */ ret = afs_read_iis(mtd, &iis, iis_ptr); if (ret < 0) break; strcpy(str, iis.name); size = mtd->erasesize + off - img_ptr; /* * In order to support JFFS2 partitions on this layout, * we must lie to MTD about the real size of JFFS2 * partitions; this ensures that the AFS flash footer * won't be erased by JFFS2. Please ensure that your * JFFS2 partitions are given image numbers between * 1000 and 2000 inclusive. */ if (iis.imageNumber >= 1000 && iis.imageNumber < 2000) size -= mtd->erasesize; parts[idx].name = str; parts[idx].size = size; parts[idx].offset = img_ptr; parts[idx].mask_flags = 0; printk(" mtd%d: at 0x%08x, %5dKB, %8u, %s\n", idx, img_ptr, parts[idx].size / 1024, iis.imageNumber, str); idx += 1; str = str + strlen(iis.name) + 1; } if (!idx) { kfree(parts); parts = NULL; } *pparts = parts; return idx ? idx : ret; }