diff options
Diffstat (limited to 'fs/ubifs/io.c')
-rw-r--r-- | fs/ubifs/io.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index dfd168b7807e..166951e0dcd3 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c | |||
@@ -393,7 +393,7 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf) | |||
393 | ubifs_assert(wbuf->size % c->min_io_size == 0); | 393 | ubifs_assert(wbuf->size % c->min_io_size == 0); |
394 | ubifs_assert(!c->ro_media && !c->ro_mount); | 394 | ubifs_assert(!c->ro_media && !c->ro_mount); |
395 | if (c->leb_size - wbuf->offs >= c->max_write_size) | 395 | if (c->leb_size - wbuf->offs >= c->max_write_size) |
396 | ubifs_assert(!((wbuf->offs + wbuf->size) % c->max_write_size )); | 396 | ubifs_assert(!((wbuf->offs + wbuf->size) % c->max_write_size)); |
397 | 397 | ||
398 | if (c->ro_error) | 398 | if (c->ro_error) |
399 | return -EROFS; | 399 | return -EROFS; |
@@ -452,8 +452,8 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf) | |||
452 | * @dtype: data type | 452 | * @dtype: data type |
453 | * | 453 | * |
454 | * This function targets the write-buffer to logical eraseblock @lnum:@offs. | 454 | * This function targets the write-buffer to logical eraseblock @lnum:@offs. |
455 | * The write-buffer is synchronized if it is not empty. Returns zero in case of | 455 | * The write-buffer has to be empty. Returns zero in case of success and a |
456 | * success and a negative error code in case of failure. | 456 | * negative error code in case of failure. |
457 | */ | 457 | */ |
458 | int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, | 458 | int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, |
459 | int dtype) | 459 | int dtype) |
@@ -465,13 +465,7 @@ int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, | |||
465 | ubifs_assert(offs >= 0 && offs <= c->leb_size); | 465 | ubifs_assert(offs >= 0 && offs <= c->leb_size); |
466 | ubifs_assert(offs % c->min_io_size == 0 && !(offs & 7)); | 466 | ubifs_assert(offs % c->min_io_size == 0 && !(offs & 7)); |
467 | ubifs_assert(lnum != wbuf->lnum); | 467 | ubifs_assert(lnum != wbuf->lnum); |
468 | 468 | ubifs_assert(wbuf->used == 0); | |
469 | if (wbuf->used > 0) { | ||
470 | int err = ubifs_wbuf_sync_nolock(wbuf); | ||
471 | |||
472 | if (err) | ||
473 | return err; | ||
474 | } | ||
475 | 469 | ||
476 | spin_lock(&wbuf->lock); | 470 | spin_lock(&wbuf->lock); |
477 | wbuf->lnum = lnum; | 471 | wbuf->lnum = lnum; |
@@ -573,7 +567,7 @@ out_timers: | |||
573 | int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | 567 | int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) |
574 | { | 568 | { |
575 | struct ubifs_info *c = wbuf->c; | 569 | struct ubifs_info *c = wbuf->c; |
576 | int err, written, n, aligned_len = ALIGN(len, 8), offs; | 570 | int err, written, n, aligned_len = ALIGN(len, 8); |
577 | 571 | ||
578 | dbg_io("%d bytes (%s) to jhead %s wbuf at LEB %d:%d", len, | 572 | dbg_io("%d bytes (%s) to jhead %s wbuf at LEB %d:%d", len, |
579 | dbg_ntype(((struct ubifs_ch *)buf)->node_type), | 573 | dbg_ntype(((struct ubifs_ch *)buf)->node_type), |
@@ -588,7 +582,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
588 | ubifs_assert(mutex_is_locked(&wbuf->io_mutex)); | 582 | ubifs_assert(mutex_is_locked(&wbuf->io_mutex)); |
589 | ubifs_assert(!c->ro_media && !c->ro_mount); | 583 | ubifs_assert(!c->ro_media && !c->ro_mount); |
590 | if (c->leb_size - wbuf->offs >= c->max_write_size) | 584 | if (c->leb_size - wbuf->offs >= c->max_write_size) |
591 | ubifs_assert(!((wbuf->offs + wbuf->size) % c->max_write_size )); | 585 | ubifs_assert(!((wbuf->offs + wbuf->size) % c->max_write_size)); |
592 | 586 | ||
593 | if (c->leb_size - wbuf->offs - wbuf->used < aligned_len) { | 587 | if (c->leb_size - wbuf->offs - wbuf->used < aligned_len) { |
594 | err = -ENOSPC; | 588 | err = -ENOSPC; |
@@ -636,7 +630,6 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
636 | goto exit; | 630 | goto exit; |
637 | } | 631 | } |
638 | 632 | ||
639 | offs = wbuf->offs; | ||
640 | written = 0; | 633 | written = 0; |
641 | 634 | ||
642 | if (wbuf->used) { | 635 | if (wbuf->used) { |
@@ -653,7 +646,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
653 | if (err) | 646 | if (err) |
654 | goto out; | 647 | goto out; |
655 | 648 | ||
656 | offs += wbuf->size; | 649 | wbuf->offs += wbuf->size; |
657 | len -= wbuf->avail; | 650 | len -= wbuf->avail; |
658 | aligned_len -= wbuf->avail; | 651 | aligned_len -= wbuf->avail; |
659 | written += wbuf->avail; | 652 | written += wbuf->avail; |
@@ -672,7 +665,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
672 | if (err) | 665 | if (err) |
673 | goto out; | 666 | goto out; |
674 | 667 | ||
675 | offs += wbuf->size; | 668 | wbuf->offs += wbuf->size; |
676 | len -= wbuf->size; | 669 | len -= wbuf->size; |
677 | aligned_len -= wbuf->size; | 670 | aligned_len -= wbuf->size; |
678 | written += wbuf->size; | 671 | written += wbuf->size; |
@@ -687,12 +680,13 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
687 | n = aligned_len >> c->max_write_shift; | 680 | n = aligned_len >> c->max_write_shift; |
688 | if (n) { | 681 | if (n) { |
689 | n <<= c->max_write_shift; | 682 | n <<= c->max_write_shift; |
690 | dbg_io("write %d bytes to LEB %d:%d", n, wbuf->lnum, offs); | 683 | dbg_io("write %d bytes to LEB %d:%d", n, wbuf->lnum, |
691 | err = ubi_leb_write(c->ubi, wbuf->lnum, buf + written, offs, n, | 684 | wbuf->offs); |
692 | wbuf->dtype); | 685 | err = ubi_leb_write(c->ubi, wbuf->lnum, buf + written, |
686 | wbuf->offs, n, wbuf->dtype); | ||
693 | if (err) | 687 | if (err) |
694 | goto out; | 688 | goto out; |
695 | offs += n; | 689 | wbuf->offs += n; |
696 | aligned_len -= n; | 690 | aligned_len -= n; |
697 | len -= n; | 691 | len -= n; |
698 | written += n; | 692 | written += n; |
@@ -707,7 +701,6 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len) | |||
707 | */ | 701 | */ |
708 | memcpy(wbuf->buf, buf + written, len); | 702 | memcpy(wbuf->buf, buf + written, len); |
709 | 703 | ||
710 | wbuf->offs = offs; | ||
711 | if (c->leb_size - wbuf->offs >= c->max_write_size) | 704 | if (c->leb_size - wbuf->offs >= c->max_write_size) |
712 | wbuf->size = c->max_write_size; | 705 | wbuf->size = c->max_write_size; |
713 | else | 706 | else |