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