writev.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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, vecs[i].iov_base);
  27. totlen += thislen;
  28. if (ret || thislen != vecs[i].iov_len)
  29. break;
  30. to += vecs[i].iov_len;
  31. }
  32. if (retlen)
  33. *retlen = totlen;
  34. return ret;
  35. }
  36. int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
  37. unsigned long count, loff_t to, size_t *retlen)
  38. {
  39. if (!jffs2_is_writebuffered(c)) {
  40. if (jffs2_sum_active()) {
  41. int res;
  42. res = jffs2_sum_add_kvec(c, vecs, count, (uint32_t) to);
  43. if (res) {
  44. return res;
  45. }
  46. }
  47. }
  48. if (c->mtd->writev)
  49. return c->mtd->writev(c->mtd, vecs, count, to, retlen);
  50. else {
  51. return mtd_fake_writev(c->mtd, vecs, count, to, retlen);
  52. }
  53. }
  54. int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
  55. size_t *retlen, const u_char *buf)
  56. {
  57. int ret;
  58. ret = c->mtd->write(c->mtd, ofs, len, retlen, buf);
  59. if (jffs2_sum_active()) {
  60. struct kvec vecs[1];
  61. int res;
  62. vecs[0].iov_base = (unsigned char *) buf;
  63. vecs[0].iov_len = len;
  64. res = jffs2_sum_add_kvec(c, vecs, 1, (uint32_t) ofs);
  65. if (res) {
  66. return res;
  67. }
  68. }
  69. return ret;
  70. }