yaffs_attribs.c 3.0 KB

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