501-yaffs-3.5-convert-to-use-kuid_t-kgid_t.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. --- a/fs/yaffs2/yaffs_vfs.c
  2. +++ b/fs/yaffs2/yaffs_vfs.c
  3. @@ -329,6 +329,33 @@ static int yaffs_readpage(struct file *f
  4. return ret;
  5. }
  6. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  7. +#define YCRED_FSUID() from_kuid(&init_user_ns, current_fsuid())
  8. +#define YCRED_FSGID() from_kgid(&init_user_ns, current_fsgid())
  9. +#else
  10. +#define YCRED_FSUID() YCRED(current)->fsuid
  11. +#define YCRED_FSGID() YCRED(current)->fsgid
  12. +
  13. +static inline uid_t i_uid_read(const struct inode *inode)
  14. +{
  15. + return inode->i_uid;
  16. +}
  17. +
  18. +static inline gid_t i_gid_read(const struct inode *inode)
  19. +{
  20. + return inode->i_gid;
  21. +}
  22. +
  23. +static inline void i_uid_write(struct inode *inode, uid_t uid)
  24. +{
  25. + inode->i_uid = uid;
  26. +}
  27. +
  28. +static inline void i_gid_write(struct inode *inode, gid_t gid)
  29. +{
  30. + inode->i_gid = gid;
  31. +}
  32. +#endif
  33. static void yaffs_set_super_dirty_val(struct yaffs_dev *dev, int val)
  34. {
  35. @@ -1225,9 +1252,9 @@ static int yaffs_mknod(struct inode *dir
  36. struct yaffs_obj *parent = yaffs_inode_to_obj(dir);
  37. int error = -ENOSPC;
  38. - uid_t uid = YCRED(current)->fsuid;
  39. + uid_t uid = YCRED_FSUID();
  40. gid_t gid =
  41. - (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
  42. + (dir->i_mode & S_ISGID) ? i_gid_read(dir) : YCRED_FSGID();
  43. if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
  44. mode |= S_ISGID;
  45. @@ -1424,9 +1451,9 @@ static int yaffs_symlink(struct inode *d
  46. {
  47. struct yaffs_obj *obj;
  48. struct yaffs_dev *dev;
  49. - uid_t uid = YCRED(current)->fsuid;
  50. + uid_t uid = YCRED_FSUID();
  51. gid_t gid =
  52. - (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
  53. + (dir->i_mode & S_ISGID) ? i_gid_read(dir) : YCRED_FSGID();
  54. yaffs_trace(YAFFS_TRACE_OS, "yaffs_symlink");
  55. @@ -1829,8 +1856,8 @@ static void yaffs_fill_inode_from_obj(st
  56. inode->i_ino = obj->obj_id;
  57. inode->i_mode = obj->yst_mode;
  58. - inode->i_uid = obj->yst_uid;
  59. - inode->i_gid = obj->yst_gid;
  60. + i_uid_write(inode, obj->yst_uid);
  61. + i_gid_write(inode, obj->yst_gid);
  62. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
  63. inode->i_blksize = inode->i_sb->s_blocksize;
  64. #endif
  65. @@ -1856,7 +1883,7 @@ static void yaffs_fill_inode_from_obj(st
  66. yaffs_trace(YAFFS_TRACE_OS,
  67. "yaffs_fill_inode mode %x uid %d gid %d size %lld count %d",
  68. - inode->i_mode, inode->i_uid, inode->i_gid,
  69. + inode->i_mode, i_uid_read(inode), i_gid_read(inode),
  70. inode->i_size, atomic_read(&inode->i_count));
  71. switch (obj->yst_mode & S_IFMT) {
  72. --- a/fs/yaffs2/yaffs_attribs.c
  73. +++ b/fs/yaffs2/yaffs_attribs.c
  74. @@ -14,6 +14,48 @@
  75. #include "yaffs_guts.h"
  76. #include "yaffs_attribs.h"
  77. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  78. +static inline uid_t ia_uid_read(const struct iattr *iattr)
  79. +{
  80. + return from_kuid(&init_user_ns, iattr->ia_uid);
  81. +}
  82. +
  83. +static inline gid_t ia_gid_read(const struct iattr *iattr)
  84. +{
  85. + return from_kgid(&init_user_ns, iattr->ia_gid);
  86. +}
  87. +
  88. +static inline void ia_uid_write(struct iattr *iattr, uid_t uid)
  89. +{
  90. + iattr->ia_uid = make_kuid(&init_user_ns, uid);
  91. +}
  92. +
  93. +static inline void ia_gid_write(struct iattr *iattr, gid_t gid)
  94. +{
  95. + iattr->ia_gid = make_kgid(&init_user_ns, gid);
  96. +}
  97. +#else
  98. +static inline uid_t ia_uid_read(const struct iattr *iattr)
  99. +{
  100. + return iattr->ia_uid;
  101. +}
  102. +
  103. +static inline gid_t ia_gid_read(const struct iattr *inode)
  104. +{
  105. + return iattr->ia_gid;
  106. +}
  107. +
  108. +static inline void ia_uid_write(struct iattr *iattr, uid_t uid)
  109. +{
  110. + iattr->ia_uid = uid;
  111. +}
  112. +
  113. +static inline void ia_gid_write(struct iattr *iattr, gid_t gid)
  114. +{
  115. + iattr->ia_gid = gid;
  116. +}
  117. +#endif
  118. +
  119. void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
  120. {
  121. obj->yst_uid = oh->yst_uid;
  122. @@ -77,9 +119,9 @@ int yaffs_set_attribs(struct yaffs_obj *
  123. if (valid & ATTR_MODE)
  124. obj->yst_mode = attr->ia_mode;
  125. if (valid & ATTR_UID)
  126. - obj->yst_uid = attr->ia_uid;
  127. + obj->yst_uid = ia_uid_read(attr);
  128. if (valid & ATTR_GID)
  129. - obj->yst_gid = attr->ia_gid;
  130. + obj->yst_gid = ia_gid_read(attr);
  131. if (valid & ATTR_ATIME)
  132. obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime);
  133. @@ -103,9 +145,9 @@ int yaffs_get_attribs(struct yaffs_obj *
  134. attr->ia_mode = obj->yst_mode;
  135. valid |= ATTR_MODE;
  136. - attr->ia_uid = obj->yst_uid;
  137. + ia_uid_write(attr, obj->yst_uid);
  138. valid |= ATTR_UID;
  139. - attr->ia_gid = obj->yst_gid;
  140. + ia_gid_write(attr, obj->yst_gid);
  141. valid |= ATTR_GID;
  142. Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;