/** * ubi_volume_notify - send a volume change notification. * @ubi: UBI device description object * @vol: volume description object of the changed volume * @ntype: notification type to send (%UBI_VOLUME_ADDED, etc) * * This is a helper function which notifies all subscribers about a volume * change event (creation, removal, re-sizing, re-naming, updating). Returns * zero in case of success and a negative error code in case of failure. */ int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol, int ntype) { #ifdef CONFIG_MTD_UBI_FASTMAP switch (ntype) { case UBI_VOLUME_ADDED: case UBI_VOLUME_REMOVED: case UBI_VOLUME_RESIZED: case UBI_VOLUME_RENAMED: if (ubi_update_fastmap(ubi)) { ubi_err("Unable to update fastmap!"); ubi_ro_mode(ubi); } } #endif return 0; }
/** * ubi_eba_read_leb - read data. * @ubi: UBI device description object * @vol: volume description object * @lnum: logical eraseblock number * @buf: buffer to store the read data * @offset: offset from where to read * @len: how many bytes to read * @check: data CRC check flag * * If the logical eraseblock @lnum is unmapped, @buf is filled with 0xFF * bytes. The @check flag only makes sense for static volumes and forces * eraseblock data CRC checking. * * In case of success this function returns zero. In case of a static volume, * if data CRC mismatches - %-EBADMSG is returned. %-EBADMSG may also be * returned for any volume type if an ECC error was detected by the MTD device * driver. Other negative error cored may be returned in case of other errors. */ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, void *buf, int offset, int len, int check) { int err, pnum, scrub = 0, vol_id = vol->vol_id; struct ubi_vid_hdr *vid_hdr; uint32_t uninitialized_var(crc); err = leb_read_lock(ubi, vol_id, lnum); if (err) return err; pnum = vol->eba_tbl[lnum]; if (pnum < 0) { /* * The logical eraseblock is not mapped, fill the whole buffer * with 0xFF bytes. The exception is static volumes for which * it is an error to read unmapped logical eraseblocks. */ dbg_eba("read %d bytes from offset %d of LEB %d:%d (unmapped)", len, offset, vol_id, lnum); leb_read_unlock(ubi, vol_id, lnum); ubi_assert(vol->vol_type != UBI_STATIC_VOLUME); memset(buf, 0xFF, len); return 0; } dbg_eba("read %d bytes from offset %d of LEB %d:%d, PEB %d", len, offset, vol_id, lnum, pnum); if (vol->vol_type == UBI_DYNAMIC_VOLUME) check = 0; retry: if (check) { vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); if (!vid_hdr) { err = -ENOMEM; goto out_unlock; } err = ubi_io_read_vid_hdr(ubi, pnum, vid_hdr, 1); if (err && err != UBI_IO_BITFLIPS) { if (err > 0) { /* * The header is either absent or corrupted. * The former case means there is a bug - * switch to read-only mode just in case. * The latter case means a real corruption - we * may try to recover data. FIXME: but this is * not implemented. */ <<<<<<< HEAD if (err == UBI_IO_BAD_HDR_EBADMSG || err == UBI_IO_BAD_HDR) { ======= if (err == UBI_IO_BAD_VID_HDR) { >>>>>>> 296c66da8a02d52243f45b80521febece5ed498a ubi_warn("corrupted VID header at PEB " "%d, LEB %d:%d", pnum, vol_id, lnum); err = -EBADMSG; } else ubi_ro_mode(ubi); }