/** * test_update - check volume update and atomic LEB change capabilities. * * @type volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) * * This function returns %0 in case of success and %-1 in case of failure. */ static int test_update(int type) { struct ubi_mkvol_request req; const char *name = TESTNAME ":io_update()"; int alignments[] = ALIGNMENTS(dev_info.leb_size); struct ubi_vol_info vol_info; char vol_node[strlen(UBI_VOLUME_PATTERN) + 100]; unsigned int i; for (i = 0; i < sizeof(alignments)/sizeof(int); i++) { int leb_size; req.vol_id = UBI_VOL_NUM_AUTO; req.vol_type = type; req.name = name; req.alignment = alignments[i]; req.alignment -= req.alignment % dev_info.min_io_size; if (req.alignment == 0) req.alignment = dev_info.min_io_size; leb_size = dev_info.leb_size - dev_info.leb_size % req.alignment; req.bytes = MIN_AVAIL_EBS * leb_size; if (ubi_mkvol(libubi, node, &req)) { failed("ubi_mkvol"); return -1; } sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num, req.vol_id); if (ubi_get_vol_info(libubi, vol_node, &vol_info)) { failed("ubi_get_vol_info"); goto remove; } if (test_update1(&vol_info, 0)) { err_msg("alignment = %d", req.alignment); goto remove; } if (vol_info.type != UBI_STATIC_VOLUME) { if (test_update1(&vol_info, 1)) { err_msg("alignment = %d", req.alignment); goto remove; } } if (ubi_rmvol(libubi, node, req.vol_id)) { failed("ubi_rmvol"); return -1; } } return 0; remove: ubi_rmvol(libubi, node, req.vol_id); return -1; }
/** * test_aligned - test volume alignment feature. * * @type volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) * * Thus function returns %0 in case of success and %-1 in case of failure. */ static int test_aligned(int type) { unsigned int i, ebsz; struct ubi_mkvol_request req; const char *name = TESTNAME ":test_aligned()"; char vol_node[strlen(UBI_VOLUME_PATTERN) + 100]; int alignments[] = ALIGNMENTS(dev_info.leb_size); req.vol_type = type; req.name = name; for (i = 0; i < sizeof(alignments)/sizeof(int); i++) { req.vol_id = UBI_VOL_NUM_AUTO; req.alignment = alignments[i]; req.alignment -= req.alignment % dev_info.min_io_size; if (req.alignment == 0) req.alignment = dev_info.min_io_size; ebsz = dev_info.leb_size - dev_info.leb_size % req.alignment; req.bytes = MIN_AVAIL_EBS * ebsz; if (ubi_mkvol(libubi, node, &req)) { failed("ubi_mkvol"); return -1; } sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num, req.vol_id); /* Make sure newly created volume contains only 0xFF bytes */ if (check_vol_patt(vol_node, 0xFF)) goto remove; /* Write 0xA5 bytes to the volume */ if (update_vol_patt(vol_node, req.bytes, 0xA5)) goto remove; if (check_vol_patt(vol_node, 0xA5)) goto remove; if (ubi_rmvol(libubi, node, req.vol_id)) { failed("ubi_rmvol"); return -1; } } return 0; remove: ubi_rmvol(libubi, node, req.vol_id); return -1; }
/** * mkvol_alignment - create volumes with different alignments. * * Thus function returns %0 in case of success and %-1 in case of failure. */ static int mkvol_alignment(void) { struct ubi_mkvol_request req; int i, vol_id, ebsz; const char *name = PROGRAM_NAME ":mkvol_alignment()"; int alignments[] = ALIGNMENTS(dev_info.leb_size); for (i = 0; i < sizeof(alignments)/sizeof(int); i++) { req.vol_id = UBI_VOL_NUM_AUTO; /* Alignment should actually be multiple of min. I/O size */ req.alignment = alignments[i]; req.alignment -= req.alignment % dev_info.min_io_size; if (req.alignment == 0) req.alignment = dev_info.min_io_size; /* Bear in mind alignment reduces EB size */ ebsz = dev_info.leb_size - dev_info.leb_size % req.alignment; req.bytes = (long long)dev_info.avail_lebs * ebsz; req.vol_type = UBI_DYNAMIC_VOLUME; req.name = name; if (ubi_mkvol(libubi, node, &req)) { failed("ubi_mkvol"); errorm("alignment %d", req.alignment); return -1; } vol_id = req.vol_id; if (check_volume(vol_id, &req)) goto remove; if (ubi_rmvol(libubi, node, vol_id)) { failed("ubi_rmvol"); return -1; } } return 0; remove: ubi_rmvol(libubi, node, vol_id); return -1; }