yaffs_attribs.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
  3. *
  4. * Copyright (C) 2002-2011 Aleph One Ltd.
  5. * for Toby Churchill Ltd and Brightstar Engineering
  6. *
  7. * Created by Charles Manning <charles@aleph1.co.uk>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include "yaffs_guts.h"
  14. #include "yaffs_attribs.h"
  15. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
  16. #define IATTR_UID ia_uid
  17. #define IATTR_GID ia_gid
  18. #else
  19. #define IATTR_UID ia_uid.val
  20. #define IATTR_GID ia_gid.val
  21. #endif
  22. void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
  23. {
  24. obj->yst_uid = oh->yst_uid;
  25. obj->yst_gid = oh->yst_gid;
  26. obj->yst_atime = oh->yst_atime;
  27. obj->yst_mtime = oh->yst_mtime;
  28. obj->yst_ctime = oh->yst_ctime;
  29. obj->yst_rdev = oh->yst_rdev;
  30. }
  31. void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj)
  32. {
  33. oh->yst_uid = obj->yst_uid;
  34. oh->yst_gid = obj->yst_gid;
  35. oh->yst_atime = obj->yst_atime;
  36. oh->yst_mtime = obj->yst_mtime;
  37. oh->yst_ctime = obj->yst_ctime;
  38. oh->yst_rdev = obj->yst_rdev;
  39. }
  40. void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c)
  41. {
  42. obj->yst_mtime = Y_CURRENT_TIME;
  43. if (do_a)
  44. obj->yst_atime = obj->yst_mtime;
  45. if (do_c)
  46. obj->yst_ctime = obj->yst_mtime;
  47. }
  48. void yaffs_attribs_init(struct yaffs_obj *obj, u32 gid, u32 uid, u32 rdev)
  49. {
  50. yaffs_load_current_time(obj, 1, 1);
  51. obj->yst_rdev = rdev;
  52. obj->yst_uid = uid;
  53. obj->yst_gid = gid;
  54. }
  55. static loff_t yaffs_get_file_size(struct yaffs_obj *obj)
  56. {
  57. YCHAR *alias = NULL;
  58. obj = yaffs_get_equivalent_obj(obj);
  59. switch (obj->variant_type) {
  60. case YAFFS_OBJECT_TYPE_FILE:
  61. return obj->variant.file_variant.file_size;
  62. case YAFFS_OBJECT_TYPE_SYMLINK:
  63. alias = obj->variant.symlink_variant.alias;
  64. if (!alias)
  65. return 0;
  66. return strnlen(alias, YAFFS_MAX_ALIAS_LENGTH);
  67. default:
  68. return 0;
  69. }
  70. }
  71. int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr)
  72. {
  73. unsigned int valid = attr->ia_valid;
  74. if (valid & ATTR_MODE)
  75. obj->yst_mode = attr->ia_mode;
  76. if (valid & ATTR_UID)
  77. obj->yst_uid = attr->IATTR_UID;
  78. if (valid & ATTR_GID)
  79. obj->yst_gid = attr->IATTR_GID;
  80. if (valid & ATTR_ATIME)
  81. obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime);
  82. if (valid & ATTR_CTIME)
  83. obj->yst_ctime = Y_TIME_CONVERT(attr->ia_ctime);
  84. if (valid & ATTR_MTIME)
  85. obj->yst_mtime = Y_TIME_CONVERT(attr->ia_mtime);
  86. if (valid & ATTR_SIZE)
  87. yaffs_resize_file(obj, attr->ia_size);
  88. yaffs_update_oh(obj, NULL, 1, 0, 0, NULL);
  89. return YAFFS_OK;
  90. }
  91. int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr)
  92. {
  93. unsigned int valid = 0;
  94. attr->ia_mode = obj->yst_mode;
  95. valid |= ATTR_MODE;
  96. attr->IATTR_UID = obj->yst_uid;
  97. valid |= ATTR_UID;
  98. attr->IATTR_GID = obj->yst_gid;
  99. valid |= ATTR_GID;
  100. Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;
  101. valid |= ATTR_ATIME;
  102. Y_TIME_CONVERT(attr->ia_ctime) = obj->yst_ctime;
  103. valid |= ATTR_CTIME;
  104. Y_TIME_CONVERT(attr->ia_mtime) = obj->yst_mtime;
  105. valid |= ATTR_MTIME;
  106. attr->ia_size = yaffs_get_file_size(obj);
  107. valid |= ATTR_SIZE;
  108. attr->ia_valid = valid;
  109. return YAFFS_OK;
  110. }