writev.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright © 2001-2007 Red Hat, Inc.
  5. *
  6. * Created by David Woodhouse <dwmw2@infradead.org>
  7. *
  8. * For licensing information, see the file 'LICENCE' in this directory.
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/mtd/mtd.h>
  13. #include "nodelist.h"
  14. /* This ought to be in core MTD code. All registered MTD devices
  15. without writev should have this put in place. Bug the MTD
  16. maintainer */
  17. static inline int mtd_fake_writev(struct mtd_info *mtd, const struct kvec *vecs,
  18. unsigned long count, loff_t to, size_t *retlen)
  19. {
  20. unsigned long i;
  21. size_t totlen = 0, thislen;
  22. int ret = 0;
  23. for (i=0; i<count; i++) {
  24. if (!vecs[i].iov_len)
  25. continue;
  26. ret = mtd_write(mtd, to, vecs[i].iov_len, &thislen,
  27. vecs[i].iov_base);
  28. totlen += thislen;
  29. if (ret || thislen != vecs[i].iov_len)
  30. break;
  31. to += vecs[i].iov_len;
  32. }
  33. if (retlen)
  34. *retlen = totlen;
  35. return ret;
  36. }
  37. int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
  38. unsigned long count, loff_t to, size_t *retlen)
  39. {
  40. if (!jffs2_is_writebuffered(c)) {
  41. if (jffs2_sum_active()) {
  42. int res;
  43. res = jffs2_sum_add_kvec(c, vecs, count, (uint32_t) to);
  44. if (res) {
  45. return res;
  46. }
  47. }
  48. }
  49. if (c->mtd->writev)
  50. return mtd_writev(c->mtd, vecs, count, to, retlen);
  51. else {
  52. return mtd_fake_writev(c->mtd, vecs, count, to, retlen);
  53. }
  54. }
  55. int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
  56. size_t *retlen, const u_char *buf)
  57. {
  58. int ret;
  59. ret = mtd_write(c->mtd, ofs, len, retlen, buf);
  60. if (jffs2_sum_active()) {
  61. struct kvec vecs[1];
  62. int res;
  63. vecs[0].iov_base = (unsigned char *) buf;
  64. vecs[0].iov_len = len;
  65. res = jffs2_sum_add_kvec(c, vecs, 1, (uint32_t) ofs);
  66. if (res) {
  67. return res;
  68. }
  69. }
  70. return ret;
  71. }