yaffs_attribs.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_attribs.h"
  14. void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
  15. {
  16. obj->yst_uid = oh->yst_uid;
  17. obj->yst_gid = oh->yst_gid;
  18. obj->yst_atime = oh->yst_atime;
  19. obj->yst_mtime = oh->yst_mtime;
  20. obj->yst_ctime = oh->yst_ctime;
  21. obj->yst_rdev = oh->yst_rdev;
  22. }
  23. void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj)
  24. {
  25. #ifdef CONFIG_YAFFS_WINCE
  26. oh->win_atime[0] = obj->win_atime[0];
  27. oh->win_ctime[0] = obj->win_ctime[0];
  28. oh->win_mtime[0] = obj->win_mtime[0];
  29. oh->win_atime[1] = obj->win_atime[1];
  30. oh->win_ctime[1] = obj->win_ctime[1];
  31. oh->win_mtime[1] = obj->win_mtime[1];
  32. #else
  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. #endif
  40. }
  41. void yaffs_attribs_init(struct yaffs_obj *obj, u32 gid, u32 uid, u32 rdev)
  42. {
  43. #ifdef CONFIG_YAFFS_WINCE
  44. yfsd_win_file_time_now(obj->win_atime);
  45. obj->win_ctime[0] = obj->win_mtime[0] = obj->win_atime[0];
  46. obj->win_ctime[1] = obj->win_mtime[1] = obj->win_atime[1];
  47. #else
  48. yaffs_load_current_time(obj, 1, 1);
  49. obj->yst_rdev = rdev;
  50. obj->yst_uid = uid;
  51. obj->yst_gid = gid;
  52. #endif
  53. }
  54. void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c)
  55. {
  56. #ifdef CONFIG_YAFFS_WINCE
  57. yfsd_win_file_time_now(the_obj->win_atime);
  58. the_obj->win_ctime[0] = the_obj->win_mtime[0] =
  59. the_obj->win_atime[0];
  60. the_obj->win_ctime[1] = the_obj->win_mtime[1] =
  61. the_obj->win_atime[1];
  62. #else
  63. obj->yst_mtime = Y_CURRENT_TIME;
  64. if (do_a)
  65. obj->yst_atime = obj->yst_atime;
  66. if (do_c)
  67. obj->yst_ctime = obj->yst_atime;
  68. #endif
  69. }
  70. loff_t yaffs_get_file_size(struct yaffs_obj *obj)
  71. {
  72. YCHAR *alias = NULL;
  73. obj = yaffs_get_equivalent_obj(obj);
  74. switch (obj->variant_type) {
  75. case YAFFS_OBJECT_TYPE_FILE:
  76. return obj->variant.file_variant.file_size;
  77. case YAFFS_OBJECT_TYPE_SYMLINK:
  78. alias = obj->variant.symlink_variant.alias;
  79. if (!alias)
  80. return 0;
  81. return yaffs_strnlen(alias, YAFFS_MAX_ALIAS_LENGTH);
  82. default:
  83. return 0;
  84. }
  85. }
  86. int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr)
  87. {
  88. unsigned int valid = attr->ia_valid;
  89. if (valid & ATTR_MODE)
  90. obj->yst_mode = attr->ia_mode;
  91. if (valid & ATTR_UID)
  92. obj->yst_uid = attr->ia_uid;
  93. if (valid & ATTR_GID)
  94. obj->yst_gid = attr->ia_gid;
  95. if (valid & ATTR_ATIME)
  96. obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime);
  97. if (valid & ATTR_CTIME)
  98. obj->yst_ctime = Y_TIME_CONVERT(attr->ia_ctime);
  99. if (valid & ATTR_MTIME)
  100. obj->yst_mtime = Y_TIME_CONVERT(attr->ia_mtime);
  101. if (valid & ATTR_SIZE)
  102. yaffs_resize_file(obj, attr->ia_size);
  103. yaffs_update_oh(obj, NULL, 1, 0, 0, NULL);
  104. return YAFFS_OK;
  105. }
  106. int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr)
  107. {
  108. unsigned int valid = 0;
  109. attr->ia_mode = obj->yst_mode;
  110. valid |= ATTR_MODE;
  111. attr->ia_uid = obj->yst_uid;
  112. valid |= ATTR_UID;
  113. attr->ia_gid = obj->yst_gid;
  114. valid |= ATTR_GID;
  115. Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;
  116. valid |= ATTR_ATIME;
  117. Y_TIME_CONVERT(attr->ia_ctime) = obj->yst_ctime;
  118. valid |= ATTR_CTIME;
  119. Y_TIME_CONVERT(attr->ia_mtime) = obj->yst_mtime;
  120. valid |= ATTR_MTIME;
  121. attr->ia_size = yaffs_get_file_size(obj);
  122. valid |= ATTR_SIZE;
  123. attr->ia_valid = valid;
  124. return YAFFS_OK;
  125. }