74 #include <linux/slab.h>
88 ubifs_warn(
"switched to read-only mode, error %d", err);
100 int len,
int even_ebadmsg)
104 err = ubi_read(c->
ubi, lnum, buf, offs, len);
109 if (err && (err != -
EBADMSG || even_ebadmsg)) {
110 ubifs_err(
"reading %d bytes from LEB %d:%d failed, error %d",
111 len, lnum, offs, err);
125 if (!dbg_is_tst_rcvry(c))
130 ubifs_err(
"writing %d bytes to LEB %d:%d failed, error %d",
131 len, lnum, offs, err);
145 if (!dbg_is_tst_rcvry(c))
150 ubifs_err(
"changing %d bytes in LEB %d failed, error %d",
165 if (!dbg_is_tst_rcvry(c))
170 ubifs_err(
"unmap LEB %d failed, error %d", lnum, err);
184 if (!dbg_is_tst_rcvry(c))
189 ubifs_err(
"mapping LEB %d failed, error %d", lnum, err);
202 ubifs_err(
"ubi_is_mapped failed for LEB %d, error %d",
244 ubifs_assert(lnum >= 0 && lnum < c->leb_cnt && offs >= 0);
250 ubifs_err(
"bad magic %#08x, expected %#08x",
267 if (c->
ranges[type].max_len == 0) {
268 if (node_len != c->
ranges[type].len)
270 }
else if (node_len < c->ranges[type].min_len ||
271 node_len > c->
ranges[type].max_len)
280 if (crc != node_crc) {
282 ubifs_err(
"bad CRC: calculated %#08x, read %#08x",
292 ubifs_err(
"bad node length %d", node_len);
295 ubifs_err(
"bad node at LEB %d:%d", lnum, offs);
348 static unsigned long long next_sqnum(
struct ubifs_info *
c)
350 unsigned long long sqnum;
358 ubifs_err(
"sequence number overflow %llu, end of life",
362 ubifs_warn(
"running out of sequence numbers, end of life soon");
383 unsigned long long sqnum = next_sqnum(c);
416 unsigned long long sqnum = next_sqnum(c);
444 wbuf->
c->need_wbuf_sync = 1;
445 ubifs_wake_up_bgt(wbuf->
c);
453 static void new_wbuf_timer_nolock(
struct ubifs_wbuf *wbuf)
459 dbg_io(
"set timer for jhead %s, %llu-%llu millisecs",
472 static void cancel_wbuf_timer_nolock(
struct ubifs_wbuf *wbuf)
496 int err, dirt, sync_len;
498 cancel_wbuf_timer_nolock(wbuf);
499 if (!wbuf->
used || wbuf->
lnum == -1)
503 dbg_io(
"LEB %d:%d, %d bytes, jhead %s",
522 dirt = sync_len - wbuf->
used;
529 spin_lock(&wbuf->
lock);
530 wbuf->
offs += sync_len;
550 spin_unlock(&wbuf->
lock);
579 spin_lock(&wbuf->
lock);
590 spin_unlock(&wbuf->
lock);
627 if (mutex_is_locked(&wbuf->
io_mutex))
639 ubifs_err(
"cannot sync write-buffer, error %d", err);
653 cancel_wbuf_timer_nolock(wbuf);
678 int err, written,
n, aligned_len =
ALIGN(len, 8);
680 dbg_io(
"%d bytes (%s) to jhead %s wbuf at LEB %d:%d", len,
701 cancel_wbuf_timer_nolock(wbuf);
706 if (aligned_len <= wbuf->
avail) {
713 if (aligned_len == wbuf->
avail) {
714 dbg_io(
"flush jhead %s wbuf to LEB %d:%d",
721 spin_lock(&wbuf->
lock);
730 spin_unlock(&wbuf->
lock);
732 spin_lock(&wbuf->
lock);
733 wbuf->
avail -= aligned_len;
734 wbuf->
used += aligned_len;
735 spin_unlock(&wbuf->
lock);
749 dbg_io(
"flush jhead %s wbuf to LEB %d:%d",
759 aligned_len -= wbuf->
avail;
760 written += wbuf->
avail;
769 dbg_io(
"write %d bytes to LEB %d:%d",
778 aligned_len -= wbuf->
size;
779 written += wbuf->
size;
791 dbg_io(
"write %d bytes to LEB %d:%d", n, wbuf->
lnum,
803 spin_lock(&wbuf->
lock);
817 wbuf->
used = aligned_len;
819 spin_unlock(&wbuf->
lock);
831 new_wbuf_timer_nolock(wbuf);
836 ubifs_err(
"cannot write %d bytes to LEB %d:%d, error %d",
863 dbg_io(
"LEB %d:%d, %s, length %d (aligned %d)",
901 int err, rlen, overlap;
904 dbg_io(
"LEB %d:%d, %s, length %d, jhead %s", lnum, offs,
906 ubifs_assert(wbuf && lnum >= 0 && lnum < c->leb_cnt && offs >= 0);
910 spin_lock(&wbuf->
lock);
911 overlap = (lnum == wbuf->
lnum && offs + len > wbuf->
offs);
914 spin_unlock(&wbuf->
lock);
924 memcpy(buf + rlen, wbuf->
buf + offs + rlen - wbuf->
offs, len - rlen);
925 spin_unlock(&wbuf->
lock);
935 ubifs_err(
"bad node type (%d but expected %d)",
942 ubifs_err(
"expected node type %d", type);
948 ubifs_err(
"bad node length %d, expected %d", rlen, len);
955 ubifs_err(
"bad node at LEB %d:%d", lnum, offs);
981 ubifs_assert(lnum >= 0 && lnum < c->leb_cnt && offs >= 0);
991 ubifs_err(
"bad node type (%d but expected %d)",
998 ubifs_err(
"expected node type %d", type);
1004 ubifs_err(
"bad node length %d, expected %d", l, len);
1011 ubifs_err(
"bad node at LEB %d:%d, LEB mapping status %d", lnum, offs,
1059 wbuf->
timer.function = wbuf_timer_callback_nolock;
1062 wbuf->
delta *= 1000000000ULL;
1080 spin_lock(&wbuf->
lock);
1083 spin_unlock(&wbuf->
lock);
1098 spin_lock(&wbuf->
lock);
1099 for (i = 0; i < wbuf->
next_ino; i++)
1100 if (inum == wbuf->
inodes[i]) {
1104 spin_unlock(&wbuf->
lock);
1134 if (!wbuf_has_ino(wbuf, inode->
i_ino))
1138 if (wbuf_has_ino(wbuf, inode->
i_ino))