ubi.h (799dca34ac543485f581bd8464ec9b1c4f0f852a) ubi.h (3291b52f9ff0acc80a8ee3f92a960db937dccecb)
1/*
2 * Copyright (c) International Business Machines Corp., 2006
3 * Copyright (c) Nokia Corporation, 2006, 2007
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

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

162 * POWER_CUT_VID_WRITE: Emulate a power cut when writing a VID header
163 */
164enum {
165 POWER_CUT_EC_WRITE = 0x01,
166 POWER_CUT_VID_WRITE = 0x02,
167};
168
169/**
1/*
2 * Copyright (c) International Business Machines Corp., 2006
3 * Copyright (c) Nokia Corporation, 2006, 2007
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

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

162 * POWER_CUT_VID_WRITE: Emulate a power cut when writing a VID header
163 */
164enum {
165 POWER_CUT_EC_WRITE = 0x01,
166 POWER_CUT_VID_WRITE = 0x02,
167};
168
169/**
170 * struct ubi_vid_io_buf - VID buffer used to read/write VID info to/from the
171 * flash.
172 * @hdr: a pointer to the VID header stored in buffer
173 * @buffer: underlying buffer
174 */
175struct ubi_vid_io_buf {
176 struct ubi_vid_hdr *hdr;
177 void *buffer;
178};
179
180/**
170 * struct ubi_wl_entry - wear-leveling entry.
171 * @u.rb: link in the corresponding (free/used) RB-tree
172 * @u.list: link in the protection queue
173 * @ec: erase counter
174 * @pnum: physical eraseblock number
175 *
176 * This data structure is used in the WL sub-system. Each physical eraseblock
177 * has a corresponding &struct wl_entry object which may be kept in different

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

735 * @min_ec: lowest erase counter value
736 * @max_ec: highest erase counter value
737 * @max_sqnum: highest sequence number value
738 * @mean_ec: mean erase counter value
739 * @ec_sum: a temporary variable used when calculating @mean_ec
740 * @ec_count: a temporary variable used when calculating @mean_ec
741 * @aeb_slab_cache: slab cache for &struct ubi_ainf_peb objects
742 * @ech: temporary EC header. Only available during scan
181 * struct ubi_wl_entry - wear-leveling entry.
182 * @u.rb: link in the corresponding (free/used) RB-tree
183 * @u.list: link in the protection queue
184 * @ec: erase counter
185 * @pnum: physical eraseblock number
186 *
187 * This data structure is used in the WL sub-system. Each physical eraseblock
188 * has a corresponding &struct wl_entry object which may be kept in different

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

746 * @min_ec: lowest erase counter value
747 * @max_ec: highest erase counter value
748 * @max_sqnum: highest sequence number value
749 * @mean_ec: mean erase counter value
750 * @ec_sum: a temporary variable used when calculating @mean_ec
751 * @ec_count: a temporary variable used when calculating @mean_ec
752 * @aeb_slab_cache: slab cache for &struct ubi_ainf_peb objects
753 * @ech: temporary EC header. Only available during scan
743 * @vidh: temporary VID header. Only available during scan
754 * @vidh: temporary VID buffer. Only available during scan
744 *
745 * This data structure contains the result of attaching an MTD device and may
746 * be used by other UBI sub-systems to build final UBI data structures, further
747 * error-recovery and so on.
748 */
749struct ubi_attach_info {
750 struct rb_root volumes;
751 struct list_head corr;

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

765 int min_ec;
766 int max_ec;
767 unsigned long long max_sqnum;
768 int mean_ec;
769 uint64_t ec_sum;
770 int ec_count;
771 struct kmem_cache *aeb_slab_cache;
772 struct ubi_ec_hdr *ech;
755 *
756 * This data structure contains the result of attaching an MTD device and may
757 * be used by other UBI sub-systems to build final UBI data structures, further
758 * error-recovery and so on.
759 */
760struct ubi_attach_info {
761 struct rb_root volumes;
762 struct list_head corr;

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

776 int min_ec;
777 int max_ec;
778 unsigned long long max_sqnum;
779 int mean_ec;
780 uint64_t ec_sum;
781 int ec_count;
782 struct kmem_cache *aeb_slab_cache;
783 struct ubi_ec_hdr *ech;
773 struct ubi_vid_hdr *vidh;
784 struct ubi_vid_io_buf *vidb;
774};
775
776/**
777 * struct ubi_work - UBI work description data structure.
778 * @list: a link in the list of pending works
779 * @func: worker function
780 * @e: physical eraseblock to erase
781 * @vol_id: the volume ID on which this erasure is being performed

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

882 int check);
883int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
884 const void *buf, int offset, int len);
885int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
886 int lnum, const void *buf, int len, int used_ebs);
887int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
888 int lnum, const void *buf, int len);
889int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
785};
786
787/**
788 * struct ubi_work - UBI work description data structure.
789 * @list: a link in the list of pending works
790 * @func: worker function
791 * @e: physical eraseblock to erase
792 * @vol_id: the volume ID on which this erasure is being performed

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

893 int check);
894int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
895 const void *buf, int offset, int len);
896int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
897 int lnum, const void *buf, int len, int used_ebs);
898int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
899 int lnum, const void *buf, int len);
900int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
890 struct ubi_vid_hdr *vid_hdr);
901 struct ubi_vid_io_buf *vidb);
891int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai);
892unsigned long long ubi_next_sqnum(struct ubi_device *ubi);
893int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
894 struct ubi_attach_info *ai_scan);
895
896/* wl.c */
897int ubi_wl_get_peb(struct ubi_device *ubi);
898int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum,

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

917int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture);
918int ubi_io_is_bad(const struct ubi_device *ubi, int pnum);
919int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum);
920int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
921 struct ubi_ec_hdr *ec_hdr, int verbose);
922int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
923 struct ubi_ec_hdr *ec_hdr);
924int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
902int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai);
903unsigned long long ubi_next_sqnum(struct ubi_device *ubi);
904int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
905 struct ubi_attach_info *ai_scan);
906
907/* wl.c */
908int ubi_wl_get_peb(struct ubi_device *ubi);
909int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum,

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

928int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture);
929int ubi_io_is_bad(const struct ubi_device *ubi, int pnum);
930int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum);
931int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
932 struct ubi_ec_hdr *ec_hdr, int verbose);
933int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
934 struct ubi_ec_hdr *ec_hdr);
935int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
925 struct ubi_vid_hdr *vid_hdr, int verbose);
936 struct ubi_vid_io_buf *vidb, int verbose);
926int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
937int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
927 struct ubi_vid_hdr *vid_hdr);
938 struct ubi_vid_io_buf *vidb);
928
929/* build.c */
930int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
931 int vid_hdr_offset, int max_beb_per1024);
932int ubi_detach_mtd_dev(int ubi_num, int anyway);
933struct ubi_device *ubi_get_device(int ubi_num);
934void ubi_put_device(struct ubi_device *ubi);
935struct ubi_device *ubi_get_by_major(int major);

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

1040 struct ubi_ainf_peb *aeb,
1041 struct list_head *list)
1042{
1043 rb_erase(&aeb->u.rb, &av->root);
1044 list_add_tail(&aeb->u.list, list);
1045}
1046
1047/**
939
940/* build.c */
941int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
942 int vid_hdr_offset, int max_beb_per1024);
943int ubi_detach_mtd_dev(int ubi_num, int anyway);
944struct ubi_device *ubi_get_device(int ubi_num);
945void ubi_put_device(struct ubi_device *ubi);
946struct ubi_device *ubi_get_by_major(int major);

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

1051 struct ubi_ainf_peb *aeb,
1052 struct list_head *list)
1053{
1054 rb_erase(&aeb->u.rb, &av->root);
1055 list_add_tail(&aeb->u.list, list);
1056}
1057
1058/**
1048 * ubi_zalloc_vid_hdr - allocate a volume identifier header object.
1049 * @ubi: UBI device description object
1050 * @gfp_flags: GFP flags to allocate with
1051 *
1052 * This function returns a pointer to the newly allocated and zero-filled
1053 * volume identifier header object in case of success and %NULL in case of
1054 * failure.
1059 * ubi_init_vid_buf - Initialize a VID buffer
1060 * @ubi: the UBI device
1061 * @vidb: the VID buffer to initialize
1062 * @buf: the underlying buffer
1055 */
1063 */
1056static inline struct ubi_vid_hdr *
1057ubi_zalloc_vid_hdr(const struct ubi_device *ubi, gfp_t gfp_flags)
1064static inline void ubi_init_vid_buf(const struct ubi_device *ubi,
1065 struct ubi_vid_io_buf *vidb,
1066 void *buf)
1058{
1067{
1059 void *vid_hdr;
1068 if (buf)
1069 memset(buf, 0, ubi->vid_hdr_alsize);
1060
1070
1061 vid_hdr = kzalloc(ubi->vid_hdr_alsize, gfp_flags);
1062 if (!vid_hdr)
1071 vidb->buffer = buf;
1072 vidb->hdr = buf + ubi->vid_hdr_shift;
1073}
1074
1075/**
1076 * ubi_init_vid_buf - Allocate a VID buffer
1077 * @ubi: the UBI device
1078 * @gfp_flags: GFP flags to use for the allocation
1079 */
1080static inline struct ubi_vid_io_buf *
1081ubi_alloc_vid_buf(const struct ubi_device *ubi, gfp_t gfp_flags)
1082{
1083 struct ubi_vid_io_buf *vidb;
1084 void *buf;
1085
1086 vidb = kzalloc(sizeof(*vidb), gfp_flags);
1087 if (!vidb)
1063 return NULL;
1064
1088 return NULL;
1089
1065 /*
1066 * VID headers may be stored at un-aligned flash offsets, so we shift
1067 * the pointer.
1068 */
1069 return vid_hdr + ubi->vid_hdr_shift;
1090 buf = kmalloc(ubi->vid_hdr_alsize, gfp_flags);
1091 if (!buf) {
1092 kfree(vidb);
1093 return NULL;
1094 }
1095
1096 ubi_init_vid_buf(ubi, vidb, buf);
1097
1098 return vidb;
1070}
1071
1072/**
1099}
1100
1101/**
1073 * ubi_free_vid_hdr - free a volume identifier header object.
1074 * @ubi: UBI device description object
1075 * @vid_hdr: the object to free
1102 * ubi_free_vid_buf - Free a VID buffer
1103 * @vidb: the VID buffer to free
1076 */
1104 */
1077static inline void ubi_free_vid_hdr(const struct ubi_device *ubi,
1078 struct ubi_vid_hdr *vid_hdr)
1105static inline void ubi_free_vid_buf(struct ubi_vid_io_buf *vidb)
1079{
1106{
1080 void *p = vid_hdr;
1081
1082 if (!p)
1107 if (!vidb)
1083 return;
1084
1108 return;
1109
1085 kfree(p - ubi->vid_hdr_shift);
1110 kfree(vidb->buffer);
1111 kfree(vidb);
1086}
1087
1112}
1113
1114/**
1115 * ubi_get_vid_hdr - Get the VID header attached to a VID buffer
1116 * @vidb: VID buffer
1117 */
1118static inline struct ubi_vid_hdr *ubi_get_vid_hdr(struct ubi_vid_io_buf *vidb)
1119{
1120 return vidb->hdr;
1121}
1122
1088/*
1089 * This function is equivalent to 'ubi_io_read()', but @offset is relative to
1090 * the beginning of the logical eraseblock, not to the beginning of the
1091 * physical eraseblock.
1092 */
1093static inline int ubi_io_read_data(const struct ubi_device *ubi, void *buf,
1094 int pnum, int offset, int len)
1095{

--- 94 unchanged lines hidden ---
1123/*
1124 * This function is equivalent to 'ubi_io_read()', but @offset is relative to
1125 * the beginning of the logical eraseblock, not to the beginning of the
1126 * physical eraseblock.
1127 */
1128static inline int ubi_io_read_data(const struct ubi_device *ubi, void *buf,
1129 int pnum, int offset, int len)
1130{

--- 94 unchanged lines hidden ---