yaffs_attribs.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
  3. *
  4. * Copyright (C) 2002-2010 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. void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
  16. {
  17. obj->yst_uid = oh->yst_uid;
  18. obj->yst_gid = oh->yst_gid;
  19. obj->yst_atime = oh->yst_atime;
  20. obj->yst_mtime = oh->yst_mtime;
  21. obj->yst_ctime = oh->yst_ctime;
  22. obj->yst_rdev = oh->yst_rdev;
  23. }
  24. void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj)
  25. {
  26. oh->yst_uid = obj->yst_uid;
  27. oh->yst_gid = obj->yst_gid;
  28. oh->yst_atime = obj->yst_atime;
  29. oh->yst_mtime = obj->yst_mtime;
  30. oh->yst_ctime = obj->yst_ctime;
  31. oh->yst_rdev = obj->yst_rdev;
  32. }
  33. void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c)
  34. {
  35. obj->yst_mtime = Y_CURRENT_TIME;
  36. if (do_a)
  37. obj->yst_atime = obj->yst_mtime;
  38. if (do_c)
  39. obj->yst_ctime = obj->yst_mtime;
  40. }
  41. void yaffs_attribs_init(struct yaffs_obj *obj, u32 gid, u32 uid, u32 rdev)
  42. {
  43. yaffs_load_current_time(obj, 1, 1);
  44. obj->yst_rdev = rdev;
  45. obj->yst_uid = uid;
  46. obj->yst_gid = gid;
  47. }
  48. loff_t yaffs_get_file_size(struct yaffs_obj *obj)
  49. {
  50. YCHAR *alias = NULL;
  51. obj = yaffs_get_equivalent_obj(obj);
  52. switch (obj->variant_type) {
  53. case YAFFS_OBJECT_TYPE_FILE:
  54. return obj->variant.file_variant.file_size;
  55. case YAFFS_OBJECT_TYPE_SYMLINK:
  56. alias = obj->variant.symlink_variant.alias;
  57. if (!alias)
  58. return 0;
  59. return strnlen(alias, YAFFS_MAX_ALIAS_LENGTH);
  60. default:
  61. return 0;
  62. }
  63. }
  64. int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr)
  65. {
  66. unsigned int valid = attr->ia_valid;
  67. if (valid & ATTR_MODE)
  68. obj->yst_mode = attr->ia_mode;
  69. if (valid & ATTR_UID)
  70. obj->yst_uid = attr->ia_uid;
  71. if (valid & ATTR_GID)
  72. obj->yst_gid = attr->ia_gid;
  73. if (valid & ATTR_ATIME)
  74. obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime);
  75. if (valid & ATTR_CTIME)
  76. obj->yst_ctime = Y_TIME_CONVERT(attr->ia_ctime);
  77. if (valid & ATTR_MTIME)
  78. obj->yst_mtime = Y_TIME_CONVERT(attr->ia_mtime);
  79. if (valid & ATTR_SIZE)
  80. yaffs_resize_file(obj, attr->ia_size);
  81. yaffs_update_oh(obj, NULL, 1, 0, 0, NULL);
  82. return YAFFS_OK;
  83. }
  84. int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr)
  85. {
  86. unsigned int valid = 0;
  87. attr->ia_mode = obj->yst_mode;
  88. valid |= ATTR_MODE;
  89. attr->ia_uid = obj->yst_uid;
  90. valid |= ATTR_UID;
  91. attr->ia_gid = obj->yst_gid;
  92. valid |= ATTR_GID;
  93. Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;
  94. valid |= ATTR_ATIME;
  95. Y_TIME_CONVERT(attr->ia_ctime) = obj->yst_ctime;
  96. valid |= ATTR_CTIME;
  97. Y_TIME_CONVERT(attr->ia_mtime) = obj->yst_mtime;
  98. valid |= ATTR_MTIME;
  99. attr->ia_size = yaffs_get_file_size(obj);
  100. valid |= ATTR_SIZE;
  101. attr->ia_valid = valid;
  102. return YAFFS_OK;
  103. }