aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ubifs/io.c')
-rw-r--r--fs/ubifs/io.c74
1 files changed, 33 insertions, 41 deletions
diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
index 9228950a658f..e18b9889a51b 100644
--- a/fs/ubifs/io.c
+++ b/fs/ubifs/io.c
@@ -109,13 +109,13 @@ int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
109 if (err && (err != -EBADMSG || even_ebadmsg)) { 109 if (err && (err != -EBADMSG || even_ebadmsg)) {
110 ubifs_err("reading %d bytes from LEB %d:%d failed, error %d", 110 ubifs_err("reading %d bytes from LEB %d:%d failed, error %d",
111 len, lnum, offs, err); 111 len, lnum, offs, err);
112 dbg_dump_stack(); 112 dump_stack();
113 } 113 }
114 return err; 114 return err;
115} 115}
116 116
117int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, 117int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
118 int len, int dtype) 118 int len)
119{ 119{
120 int err; 120 int err;
121 121
@@ -123,20 +123,19 @@ int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
123 if (c->ro_error) 123 if (c->ro_error)
124 return -EROFS; 124 return -EROFS;
125 if (!dbg_is_tst_rcvry(c)) 125 if (!dbg_is_tst_rcvry(c))
126 err = ubi_leb_write(c->ubi, lnum, buf, offs, len, dtype); 126 err = ubi_leb_write(c->ubi, lnum, buf, offs, len);
127 else 127 else
128 err = dbg_leb_write(c, lnum, buf, offs, len, dtype); 128 err = dbg_leb_write(c, lnum, buf, offs, len);
129 if (err) { 129 if (err) {
130 ubifs_err("writing %d bytes to LEB %d:%d failed, error %d", 130 ubifs_err("writing %d bytes to LEB %d:%d failed, error %d",
131 len, lnum, offs, err); 131 len, lnum, offs, err);
132 ubifs_ro_mode(c, err); 132 ubifs_ro_mode(c, err);
133 dbg_dump_stack(); 133 dump_stack();
134 } 134 }
135 return err; 135 return err;
136} 136}
137 137
138int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len, 138int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
139 int dtype)
140{ 139{
141 int err; 140 int err;
142 141
@@ -144,14 +143,14 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len,
144 if (c->ro_error) 143 if (c->ro_error)
145 return -EROFS; 144 return -EROFS;
146 if (!dbg_is_tst_rcvry(c)) 145 if (!dbg_is_tst_rcvry(c))
147 err = ubi_leb_change(c->ubi, lnum, buf, len, dtype); 146 err = ubi_leb_change(c->ubi, lnum, buf, len);
148 else 147 else
149 err = dbg_leb_change(c, lnum, buf, len, dtype); 148 err = dbg_leb_change(c, lnum, buf, len);
150 if (err) { 149 if (err) {
151 ubifs_err("changing %d bytes in LEB %d failed, error %d", 150 ubifs_err("changing %d bytes in LEB %d failed, error %d",
152 len, lnum, err); 151 len, lnum, err);
153 ubifs_ro_mode(c, err); 152 ubifs_ro_mode(c, err);
154 dbg_dump_stack(); 153 dump_stack();
155 } 154 }
156 return err; 155 return err;
157} 156}
@@ -170,12 +169,12 @@ int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
170 if (err) { 169 if (err) {
171 ubifs_err("unmap LEB %d failed, error %d", lnum, err); 170 ubifs_err("unmap LEB %d failed, error %d", lnum, err);
172 ubifs_ro_mode(c, err); 171 ubifs_ro_mode(c, err);
173 dbg_dump_stack(); 172 dump_stack();
174 } 173 }
175 return err; 174 return err;
176} 175}
177 176
178int ubifs_leb_map(struct ubifs_info *c, int lnum, int dtype) 177int ubifs_leb_map(struct ubifs_info *c, int lnum)
179{ 178{
180 int err; 179 int err;
181 180
@@ -183,13 +182,13 @@ int ubifs_leb_map(struct ubifs_info *c, int lnum, int dtype)
183 if (c->ro_error) 182 if (c->ro_error)
184 return -EROFS; 183 return -EROFS;
185 if (!dbg_is_tst_rcvry(c)) 184 if (!dbg_is_tst_rcvry(c))
186 err = ubi_leb_map(c->ubi, lnum, dtype); 185 err = ubi_leb_map(c->ubi, lnum);
187 else 186 else
188 err = dbg_leb_map(c, lnum, dtype); 187 err = dbg_leb_map(c, lnum);
189 if (err) { 188 if (err) {
190 ubifs_err("mapping LEB %d failed, error %d", lnum, err); 189 ubifs_err("mapping LEB %d failed, error %d", lnum, err);
191 ubifs_ro_mode(c, err); 190 ubifs_ro_mode(c, err);
192 dbg_dump_stack(); 191 dump_stack();
193 } 192 }
194 return err; 193 return err;
195} 194}
@@ -202,7 +201,7 @@ int ubifs_is_mapped(const struct ubifs_info *c, int lnum)
202 if (err < 0) { 201 if (err < 0) {
203 ubifs_err("ubi_is_mapped failed for LEB %d, error %d", 202 ubifs_err("ubi_is_mapped failed for LEB %d, error %d",
204 lnum, err); 203 lnum, err);
205 dbg_dump_stack(); 204 dump_stack();
206 } 205 }
207 return err; 206 return err;
208} 207}
@@ -294,8 +293,8 @@ out_len:
294out: 293out:
295 if (!quiet) { 294 if (!quiet) {
296 ubifs_err("bad node at LEB %d:%d", lnum, offs); 295 ubifs_err("bad node at LEB %d:%d", lnum, offs);
297 dbg_dump_node(c, buf); 296 ubifs_dump_node(c, buf);
298 dbg_dump_stack(); 297 dump_stack();
299 } 298 }
300 return err; 299 return err;
301} 300}
@@ -523,8 +522,7 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf)
523 dirt = sync_len - wbuf->used; 522 dirt = sync_len - wbuf->used;
524 if (dirt) 523 if (dirt)
525 ubifs_pad(c, wbuf->buf + wbuf->used, dirt); 524 ubifs_pad(c, wbuf->buf + wbuf->used, dirt);
526 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, sync_len, 525 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, sync_len);
527 wbuf->dtype);
528 if (err) 526 if (err)
529 return err; 527 return err;
530 528
@@ -562,14 +560,12 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf)
562 * @wbuf: write-buffer 560 * @wbuf: write-buffer
563 * @lnum: logical eraseblock number to seek to 561 * @lnum: logical eraseblock number to seek to
564 * @offs: logical eraseblock offset to seek to 562 * @offs: logical eraseblock offset to seek to
565 * @dtype: data type
566 * 563 *
567 * This function targets the write-buffer to logical eraseblock @lnum:@offs. 564 * This function targets the write-buffer to logical eraseblock @lnum:@offs.
568 * The write-buffer has to be empty. Returns zero in case of success and a 565 * The write-buffer has to be empty. Returns zero in case of success and a
569 * negative error code in case of failure. 566 * negative error code in case of failure.
570 */ 567 */
571int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, 568int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs)
572 int dtype)
573{ 569{
574 const struct ubifs_info *c = wbuf->c; 570 const struct ubifs_info *c = wbuf->c;
575 571
@@ -592,7 +588,6 @@ int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs,
592 wbuf->avail = wbuf->size; 588 wbuf->avail = wbuf->size;
593 wbuf->used = 0; 589 wbuf->used = 0;
594 spin_unlock(&wbuf->lock); 590 spin_unlock(&wbuf->lock);
595 wbuf->dtype = dtype;
596 591
597 return 0; 592 return 0;
598} 593}
@@ -719,8 +714,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
719 dbg_io("flush jhead %s wbuf to LEB %d:%d", 714 dbg_io("flush jhead %s wbuf to LEB %d:%d",
720 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); 715 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs);
721 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, 716 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf,
722 wbuf->offs, wbuf->size, 717 wbuf->offs, wbuf->size);
723 wbuf->dtype);
724 if (err) 718 if (err)
725 goto out; 719 goto out;
726 720
@@ -756,7 +750,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
756 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs); 750 dbg_jhead(wbuf->jhead), wbuf->lnum, wbuf->offs);
757 memcpy(wbuf->buf + wbuf->used, buf, wbuf->avail); 751 memcpy(wbuf->buf + wbuf->used, buf, wbuf->avail);
758 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs, 752 err = ubifs_leb_write(c, wbuf->lnum, wbuf->buf, wbuf->offs,
759 wbuf->size, wbuf->dtype); 753 wbuf->size);
760 if (err) 754 if (err)
761 goto out; 755 goto out;
762 756
@@ -775,7 +769,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
775 dbg_io("write %d bytes to LEB %d:%d", 769 dbg_io("write %d bytes to LEB %d:%d",
776 wbuf->size, wbuf->lnum, wbuf->offs); 770 wbuf->size, wbuf->lnum, wbuf->offs);
777 err = ubifs_leb_write(c, wbuf->lnum, buf, wbuf->offs, 771 err = ubifs_leb_write(c, wbuf->lnum, buf, wbuf->offs,
778 wbuf->size, wbuf->dtype); 772 wbuf->size);
779 if (err) 773 if (err)
780 goto out; 774 goto out;
781 775
@@ -797,7 +791,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
797 dbg_io("write %d bytes to LEB %d:%d", n, wbuf->lnum, 791 dbg_io("write %d bytes to LEB %d:%d", n, wbuf->lnum,
798 wbuf->offs); 792 wbuf->offs);
799 err = ubifs_leb_write(c, wbuf->lnum, buf + written, 793 err = ubifs_leb_write(c, wbuf->lnum, buf + written,
800 wbuf->offs, n, wbuf->dtype); 794 wbuf->offs, n);
801 if (err) 795 if (err)
802 goto out; 796 goto out;
803 wbuf->offs += n; 797 wbuf->offs += n;
@@ -841,9 +835,9 @@ exit:
841out: 835out:
842 ubifs_err("cannot write %d bytes to LEB %d:%d, error %d", 836 ubifs_err("cannot write %d bytes to LEB %d:%d, error %d",
843 len, wbuf->lnum, wbuf->offs, err); 837 len, wbuf->lnum, wbuf->offs, err);
844 dbg_dump_node(c, buf); 838 ubifs_dump_node(c, buf);
845 dbg_dump_stack(); 839 dump_stack();
846 dbg_dump_leb(c, wbuf->lnum); 840 ubifs_dump_leb(c, wbuf->lnum);
847 return err; 841 return err;
848} 842}
849 843
@@ -854,7 +848,6 @@ out:
854 * @len: node length 848 * @len: node length
855 * @lnum: logical eraseblock number 849 * @lnum: logical eraseblock number
856 * @offs: offset within the logical eraseblock 850 * @offs: offset within the logical eraseblock
857 * @dtype: node life-time hint (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)
858 * 851 *
859 * This function automatically fills node magic number, assigns sequence 852 * This function automatically fills node magic number, assigns sequence
860 * number, and calculates node CRC checksum. The length of the @buf buffer has 853 * number, and calculates node CRC checksum. The length of the @buf buffer has
@@ -863,7 +856,7 @@ out:
863 * success and a negative error code in case of failure. 856 * success and a negative error code in case of failure.
864 */ 857 */
865int ubifs_write_node(struct ubifs_info *c, void *buf, int len, int lnum, 858int ubifs_write_node(struct ubifs_info *c, void *buf, int len, int lnum,
866 int offs, int dtype) 859 int offs)
867{ 860{
868 int err, buf_len = ALIGN(len, c->min_io_size); 861 int err, buf_len = ALIGN(len, c->min_io_size);
869 862
@@ -879,9 +872,9 @@ int ubifs_write_node(struct ubifs_info *c, void *buf, int len, int lnum,
879 return -EROFS; 872 return -EROFS;
880 873
881 ubifs_prepare_node(c, buf, len, 1); 874 ubifs_prepare_node(c, buf, len, 1);
882 err = ubifs_leb_write(c, lnum, buf, offs, buf_len, dtype); 875 err = ubifs_leb_write(c, lnum, buf, offs, buf_len);
883 if (err) 876 if (err)
884 dbg_dump_node(c, buf); 877 ubifs_dump_node(c, buf);
885 878
886 return err; 879 return err;
887} 880}
@@ -960,8 +953,8 @@ int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
960 953
961out: 954out:
962 ubifs_err("bad node at LEB %d:%d", lnum, offs); 955 ubifs_err("bad node at LEB %d:%d", lnum, offs);
963 dbg_dump_node(c, buf); 956 ubifs_dump_node(c, buf);
964 dbg_dump_stack(); 957 dump_stack();
965 return -EINVAL; 958 return -EINVAL;
966} 959}
967 960
@@ -1017,8 +1010,8 @@ int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
1017out: 1010out:
1018 ubifs_err("bad node at LEB %d:%d, LEB mapping status %d", lnum, offs, 1011 ubifs_err("bad node at LEB %d:%d, LEB mapping status %d", lnum, offs,
1019 ubi_is_mapped(c->ubi, lnum)); 1012 ubi_is_mapped(c->ubi, lnum));
1020 dbg_dump_node(c, buf); 1013 ubifs_dump_node(c, buf);
1021 dbg_dump_stack(); 1014 dump_stack();
1022 return -EINVAL; 1015 return -EINVAL;
1023} 1016}
1024 1017
@@ -1056,7 +1049,6 @@ int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf)
1056 */ 1049 */
1057 size = c->max_write_size - (c->leb_start % c->max_write_size); 1050 size = c->max_write_size - (c->leb_start % c->max_write_size);
1058 wbuf->avail = wbuf->size = size; 1051 wbuf->avail = wbuf->size = size;
1059 wbuf->dtype = UBI_UNKNOWN;
1060 wbuf->sync_callback = NULL; 1052 wbuf->sync_callback = NULL;
1061 mutex_init(&wbuf->io_mutex); 1053 mutex_init(&wbuf->io_mutex);
1062 spin_lock_init(&wbuf->lock); 1054 spin_lock_init(&wbuf->lock);