ipanic_vfs.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <linux/file.h>
  2. #include <linux/fs.h>
  3. #include <linux/delay.h>
  4. #include <linux/slab.h>
  5. #include <linux/vmalloc.h>
  6. #include <uapi/asm-generic/fcntl.h>
  7. #include <linux/err.h>
  8. #include "ipanic.h"
  9. struct file *expdb_open(void)
  10. {
  11. static struct file *filp_expdb;
  12. if (!filp_expdb)
  13. filp_expdb = filp_open(AEE_EXPDB_PATH, O_RDWR, 0);
  14. if (IS_ERR(filp_expdb))
  15. LOGD("filp_open(%s) for aee failed (%ld)\n", AEE_EXPDB_PATH, PTR_ERR(filp_expdb));
  16. return filp_expdb;
  17. }
  18. ssize_t expdb_write(struct file *filp, const char *buf, size_t len, loff_t off)
  19. {
  20. return kernel_write(filp, buf, len, off);
  21. }
  22. ssize_t expdb_read(struct file *filp, char *buf, size_t len, loff_t off)
  23. {
  24. return kernel_read(filp, off, buf, len);
  25. }
  26. char *expdb_read_size(int off, int len)
  27. {
  28. int ret;
  29. struct file *filp;
  30. char *data;
  31. int timeout = 0;
  32. do {
  33. filp = expdb_open();
  34. if (timeout++ > 3) {
  35. LOGE("open expdb partition fail [%ld]!\n", PTR_ERR(filp));
  36. return NULL;
  37. }
  38. msleep(500);
  39. } while (IS_ERR(filp));
  40. data = kzalloc(len, GFP_KERNEL);
  41. ret = kernel_read(filp, off, data, len);
  42. fput(filp);
  43. if (IS_ERR(ERR_PTR(ret))) {
  44. kfree(data);
  45. data = NULL;
  46. LOGE("read from expdb fail [%d]!\n", ret);
  47. }
  48. return data;
  49. }