mtdcore.c (8273a0c911d8e068297ef70aa7241ee78db4c712) mtdcore.c (664addc248d2fed68d013d26ff2fc796d7134259)
1/*
2 * Core registration and callback routines for MTD
3 * drivers and users.
4 *
5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
6 * Copyright © 2006 Red Hat UK Limited
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 679 unchanged lines hidden (view full) ---

688 * if it completes with a failure.
689 * Callers are supposed to pass a callback function and wait for it
690 * to be called before writing to the block.
691 */
692int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
693{
694 if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
695 return -EINVAL;
1/*
2 * Core registration and callback routines for MTD
3 * drivers and users.
4 *
5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
6 * Copyright © 2006 Red Hat UK Limited
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 679 unchanged lines hidden (view full) ---

688 * if it completes with a failure.
689 * Callers are supposed to pass a callback function and wait for it
690 * to be called before writing to the block.
691 */
692int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
693{
694 if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
695 return -EINVAL;
696 if (!(mtd->flags & MTD_WRITEABLE))
697 return -EROFS;
696 return mtd->_erase(mtd, instr);
697}
698EXPORT_SYMBOL_GPL(mtd_erase);
699
700/*
701 * This stuff for eXecute-In-Place. phys is optional and may be set to NULL.
702 */
703int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,

--- 43 unchanged lines hidden (view full) ---

747 return mtd->_read(mtd, from, len, retlen, buf);
748}
749EXPORT_SYMBOL_GPL(mtd_read);
750
751int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
752 const u_char *buf)
753{
754 *retlen = 0;
698 return mtd->_erase(mtd, instr);
699}
700EXPORT_SYMBOL_GPL(mtd_erase);
701
702/*
703 * This stuff for eXecute-In-Place. phys is optional and may be set to NULL.
704 */
705int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,

--- 43 unchanged lines hidden (view full) ---

749 return mtd->_read(mtd, from, len, retlen, buf);
750}
751EXPORT_SYMBOL_GPL(mtd_read);
752
753int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
754 const u_char *buf)
755{
756 *retlen = 0;
755 if (!mtd->_write)
756 return -EROFS;
757 if (to < 0 || to > mtd->size || len > mtd->size - to)
758 return -EINVAL;
757 if (to < 0 || to > mtd->size || len > mtd->size - to)
758 return -EINVAL;
759 if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
760 return -EROFS;
759 return mtd->_write(mtd, to, len, retlen, buf);
760}
761EXPORT_SYMBOL_GPL(mtd_write);
762
763/*
764 * In blackbox flight recorder like scenarios we want to make successful writes
765 * in interrupt context. panic_write() is only intended to be called when its
766 * known the kernel is about to panic and we need the write to succeed. Since
767 * the kernel is not going to be running for much longer, this function can
768 * break locks and delay to ensure the write succeeds (but not sleep).
769 */
770int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
771 const u_char *buf)
772{
773 *retlen = 0;
774 if (!mtd->_panic_write)
775 return -EOPNOTSUPP;
776 if (to < 0 || to > mtd->size || len > mtd->size - to)
777 return -EINVAL;
761 return mtd->_write(mtd, to, len, retlen, buf);
762}
763EXPORT_SYMBOL_GPL(mtd_write);
764
765/*
766 * In blackbox flight recorder like scenarios we want to make successful writes
767 * in interrupt context. panic_write() is only intended to be called when its
768 * known the kernel is about to panic and we need the write to succeed. Since
769 * the kernel is not going to be running for much longer, this function can
770 * break locks and delay to ensure the write succeeds (but not sleep).
771 */
772int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
773 const u_char *buf)
774{
775 *retlen = 0;
776 if (!mtd->_panic_write)
777 return -EOPNOTSUPP;
778 if (to < 0 || to > mtd->size || len > mtd->size - to)
779 return -EINVAL;
780 if (!(mtd->flags & MTD_WRITEABLE))
781 return -EROFS;
778 return mtd->_panic_write(mtd, to, len, retlen, buf);
779}
780EXPORT_SYMBOL_GPL(mtd_panic_write);
781
782/* Chip-supported device locking */
783int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
784{
785 if (!mtd->_lock)

--- 35 unchanged lines hidden (view full) ---

821EXPORT_SYMBOL_GPL(mtd_block_isbad);
822
823int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
824{
825 if (!mtd->_block_markbad)
826 return -EOPNOTSUPP;
827 if (ofs < 0 || ofs > mtd->size)
828 return -EINVAL;
782 return mtd->_panic_write(mtd, to, len, retlen, buf);
783}
784EXPORT_SYMBOL_GPL(mtd_panic_write);
785
786/* Chip-supported device locking */
787int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
788{
789 if (!mtd->_lock)

--- 35 unchanged lines hidden (view full) ---

825EXPORT_SYMBOL_GPL(mtd_block_isbad);
826
827int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
828{
829 if (!mtd->_block_markbad)
830 return -EOPNOTSUPP;
831 if (ofs < 0 || ofs > mtd->size)
832 return -EINVAL;
833 if (!(mtd->flags & MTD_WRITEABLE))
834 return -EROFS;
829 return mtd->_block_markbad(mtd, ofs);
830}
831EXPORT_SYMBOL_GPL(mtd_block_markbad);
832
833/*
834 * default_mtd_writev - the default writev method
835 * @mtd: mtd device description object pointer
836 * @vecs: the vectors to write

--- 35 unchanged lines hidden (view full) ---

872 *
873 * This function returns zero in case of success and a negative error code in
874 * case of failure.
875 */
876int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
877 unsigned long count, loff_t to, size_t *retlen)
878{
879 *retlen = 0;
835 return mtd->_block_markbad(mtd, ofs);
836}
837EXPORT_SYMBOL_GPL(mtd_block_markbad);
838
839/*
840 * default_mtd_writev - the default writev method
841 * @mtd: mtd device description object pointer
842 * @vecs: the vectors to write

--- 35 unchanged lines hidden (view full) ---

878 *
879 * This function returns zero in case of success and a negative error code in
880 * case of failure.
881 */
882int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
883 unsigned long count, loff_t to, size_t *retlen)
884{
885 *retlen = 0;
886 if (!(mtd->flags & MTD_WRITEABLE))
887 return -EROFS;
880 if (!mtd->_writev)
881 return default_mtd_writev(mtd, vecs, count, to, retlen);
882 return mtd->_writev(mtd, vecs, count, to, retlen);
883}
884EXPORT_SYMBOL_GPL(mtd_writev);
885
886/**
887 * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size

--- 154 unchanged lines hidden ---
888 if (!mtd->_writev)
889 return default_mtd_writev(mtd, vecs, count, to, retlen);
890 return mtd->_writev(mtd, vecs, count, to, retlen);
891}
892EXPORT_SYMBOL_GPL(mtd_writev);
893
894/**
895 * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size

--- 154 unchanged lines hidden ---