Root/target/linux/generic/patches-3.6/512-yaffs-3.5-convert-to-use-kuid_t-kgid_t.patch

1--- a/fs/yaffs2/yaffs_vfs_glue.c
2+++ b/fs/yaffs2/yaffs_vfs_glue.c
3@@ -243,11 +243,10 @@ static inline void yaffs_dec_link_count(
4 }
5 #endif
6 
7-
8 #define update_dir_time(dir) do {\
9             (dir)->i_ctime = (dir)->i_mtime = CURRENT_TIME; \
10         } while(0)
11-
12+
13 static void yaffs_put_super(struct super_block *sb);
14 
15 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
16@@ -397,6 +396,33 @@ static struct address_space_operations y
17 #endif
18 };
19 
20+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
21+#define YCRED_FSUID() from_kuid(&init_user_ns, current_fsuid())
22+#define YCRED_FSGID() from_kgid(&init_user_ns, current_fsgid())
23+#else
24+#define YCRED_FSUID() YCRED(current)->fsuid
25+#define YCRED_FSGID() YCRED(current)->fsgid
26+
27+static inline uid_t i_uid_read(const struct inode *inode)
28+{
29+ return inode->i_uid;
30+}
31+
32+static inline gid_t i_gid_read(const struct inode *inode)
33+{
34+ return inode->i_gid;
35+}
36+
37+static inline void i_uid_write(struct inode *inode, uid_t uid)
38+{
39+ inode->i_uid = uid;
40+}
41+
42+static inline void i_gid_write(struct inode *inode, gid_t gid)
43+{
44+ inode->i_gid = gid;
45+}
46+#endif
47 
48 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
49 static const struct file_operations yaffs_file_operations = {
50@@ -549,7 +575,7 @@ static unsigned yaffs_gc_control_callbac
51 {
52     return yaffs_gc_control;
53 }
54-
55+
56 static void yaffs_gross_lock(yaffs_dev_t *dev)
57 {
58     T(YAFFS_TRACE_LOCK, (TSTR("yaffs locking %p\n"), current));
59@@ -1379,8 +1405,8 @@ static void yaffs_fill_inode_from_obj(st
60 
61         inode->i_ino = obj->obj_id;
62         inode->i_mode = obj->yst_mode;
63- inode->i_uid = obj->yst_uid;
64- inode->i_gid = obj->yst_gid;
65+ i_uid_write(inode, obj->yst_uid);
66+ i_gid_write(inode, obj->yst_gid);
67 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
68         inode->i_blksize = inode->i_sb->s_blocksize;
69 #endif
70@@ -1406,7 +1432,7 @@ static void yaffs_fill_inode_from_obj(st
71 
72         T(YAFFS_TRACE_OS,
73             (TSTR("yaffs_fill_inode mode %x uid %d gid %d size %d count %d\n"),
74- inode->i_mode, inode->i_uid, inode->i_gid,
75+ inode->i_mode, i_uid_read(inode), i_gid_read(inode),
76             (int)inode->i_size, atomic_read(&inode->i_count)));
77 
78         switch (obj->yst_mode & S_IFMT) {
79@@ -1715,8 +1741,8 @@ static int yaffs_mknod(struct inode *dir
80     yaffs_obj_t *parent = yaffs_InodeToObject(dir);
81 
82     int error = -ENOSPC;
83- uid_t uid = YCRED(current)->fsuid;
84- gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
85+ uid_t uid = YCRED_FSUID();
86+ gid_t gid = (dir->i_mode & S_ISGID) ? i_gid_read(dir) : YCRED_FSGID();
87 
88     if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
89         mode |= S_ISGID;
90@@ -1892,8 +1918,8 @@ static int yaffs_symlink(struct inode *d
91 {
92     yaffs_obj_t *obj;
93     yaffs_dev_t *dev;
94- uid_t uid = YCRED(current)->fsuid;
95- gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
96+ uid_t uid = YCRED_FSUID();
97+ gid_t gid = (dir->i_mode & S_ISGID) ? i_gid_read(dir) : YCRED_FSGID();
98 
99     T(YAFFS_TRACE_OS, (TSTR("yaffs_symlink\n")));
100 
101@@ -2009,7 +2035,7 @@ static int yaffs_setattr(struct dentry *
102         (TSTR("yaffs_setattr of object %d\n"),
103         yaffs_InodeToObject(inode)->obj_id));
104 
105- /* Fail if a requested resize >= 2GB */
106+ /* Fail if a requested resize >= 2GB */
107     if (attr->ia_valid & ATTR_SIZE &&
108         (attr->ia_size >> 31))
109         error = -EINVAL;
110@@ -2240,7 +2266,7 @@ static void yaffs_flush_inodes(struct su
111 {
112     struct inode *iptr;
113     yaffs_obj_t *obj;
114-
115+
116     list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
117         obj = yaffs_InodeToObject(iptr);
118         if(obj){
119@@ -2254,10 +2280,10 @@ static void yaffs_flush_inodes(struct su
120 
121 static void yaffs_flush_super(struct super_block *sb, int do_checkpoint)
122 {
123- yaffs_dev_t *dev = yaffs_SuperToDevice(sb);
124+ yaffs_dev_t *dev = yaffs_SuperToDevice(sb);
125     if(!dev)
126         return;
127-
128+
129     yaffs_flush_inodes(sb);
130     yaffs_update_dirty_dirs(dev);
131     yaffs_flush_whole_cache(dev);
132@@ -2325,7 +2351,7 @@ static int yaffs_do_sync_fs(struct super
133  * yaffs_bg_start() launches the background thread.
134  * yaffs_bg_stop() cleans up the background thread.
135  *
136- * NB:
137+ * NB:
138  * The thread should only run after the yaffs is initialised
139  * The thread should be stopped before yaffs is unmounted.
140  * The thread should not do any writing while the fs is in read only.
141@@ -2924,7 +2950,7 @@ static struct super_block *yaffs_interna
142 
143     dev = kmalloc(sizeof(yaffs_dev_t), GFP_KERNEL);
144     context = kmalloc(sizeof(struct yaffs_LinuxContext),GFP_KERNEL);
145-
146+
147     if(!dev || !context ){
148         if(dev)
149             kfree(dev);
150@@ -2957,7 +2983,7 @@ static struct super_block *yaffs_interna
151 #else
152     sb->u.generic_sbp = dev;
153 #endif
154-
155+
156     dev->driver_context = mtd;
157     param->name = mtd->name;
158 
159@@ -3057,7 +3083,7 @@ static struct super_block *yaffs_interna
160     param->gc_control = yaffs_gc_control_callback;
161 
162     yaffs_dev_to_lc(dev)->superBlock= sb;
163-
164+
165 
166 #ifndef CONFIG_YAFFS_DOES_ECC
167     param->use_nand_ecc = 1;
168@@ -3099,10 +3125,10 @@ static struct super_block *yaffs_interna
169     T(YAFFS_TRACE_OS,
170       (TSTR("yaffs_read_super: guts initialised %s\n"),
171        (err == YAFFS_OK) ? "OK" : "FAILED"));
172-
173+
174     if(err == YAFFS_OK)
175         yaffs_bg_start(dev);
176-
177+
178     if(!context->bgThread)
179         param->defered_dir_update = 0;
180 
181@@ -3345,7 +3371,7 @@ static int yaffs_proc_read(char *page,
182         buf += sprintf(buf,"\n");
183     else {
184         step-=2;
185-
186+
187         mutex_lock(&yaffs_context_lock);
188 
189         /* Locate and print the Nth entry. Order N-squared but N is small. */
190@@ -3362,7 +3388,7 @@ static int yaffs_proc_read(char *page,
191                 buf = yaffs_dump_dev_part0(buf, dev);
192             } else
193                 buf = yaffs_dump_dev_part1(buf, dev);
194-
195+
196             break;
197         }
198         mutex_unlock(&yaffs_context_lock);
199@@ -3389,7 +3415,7 @@ static int yaffs_stats_proc_read(char *p
200         int erasedChunks;
201 
202         erasedChunks = dev->n_erased_blocks * dev->param.chunks_per_block;
203-
204+
205         buf += sprintf(buf,"%d, %d, %d, %u, %u, %u, %u\n",
206                 n, dev->n_free_chunks, erasedChunks,
207                 dev->bg_gcs, dev->oldest_dirty_gc_count,
208--- a/fs/yaffs2/yaffs_guts.c
209+++ b/fs/yaffs2/yaffs_guts.c
210@@ -370,7 +370,7 @@ static int yaffs_verify_chunk_written(ya
211     yaffs_ext_tags tempTags;
212     __u8 *buffer = yaffs_get_temp_buffer(dev,__LINE__);
213     int result;
214-
215+
216     result = yaffs_rd_chunk_tags_nand(dev,nand_chunk,buffer,&tempTags);
217     if(memcmp(buffer,data,dev->data_bytes_per_chunk) ||
218         tempTags.obj_id != tags->obj_id ||
219@@ -424,7 +424,7 @@ static int yaffs_write_new_chunk(struct
220          * lot of checks that are most likely not needed.
221          *
222          * Mods to the above
223- * If an erase check fails or the write fails we skip the
224+ * If an erase check fails or the write fails we skip the
225          * rest of the block.
226          */
227 
228@@ -486,7 +486,7 @@ static int yaffs_write_new_chunk(struct
229 }
230 
231 
232-
233+
234 /*
235  * Block retiring for handling a broken block.
236  */
237@@ -496,7 +496,7 @@ static void yaffs_retire_block(yaffs_dev
238     yaffs_block_info_t *bi = yaffs_get_block_info(dev, flash_block);
239 
240     yaffs2_checkpt_invalidate(dev);
241-
242+
243     yaffs2_clear_oldest_dirty_seq(dev,bi);
244 
245     if (yaffs_mark_bad(dev, flash_block) != YAFFS_OK) {
246@@ -899,7 +899,7 @@ static int yaffs_find_chunk_in_group(yaf
247     for (j = 0; theChunk && j < dev->chunk_grp_size; j++) {
248         if (yaffs_check_chunk_bit(dev, theChunk / dev->param.chunks_per_block,
249                 theChunk % dev->param.chunks_per_block)) {
250-
251+
252             if(dev->chunk_grp_size == 1)
253                 return theChunk;
254             else {
255@@ -1802,7 +1802,7 @@ int yaffs_rename_obj(yaffs_obj_t *old_di
256         yaffs_update_parent(old_dir);
257         if(new_dir != old_dir)
258             yaffs_update_parent(new_dir);
259-
260+
261         return result;
262     }
263     return YAFFS_FAIL;
264@@ -2125,7 +2125,7 @@ static int yaffs_gc_block(yaffs_dev_t *d
265 
266     if(bi->block_state == YAFFS_BLOCK_STATE_FULL)
267         bi->block_state = YAFFS_BLOCK_STATE_COLLECTING;
268-
269+
270     bi->has_shrink_hdr = 0; /* clear the flag so that the block can erase */
271 
272     dev->gc_disable = 1;
273@@ -2207,7 +2207,7 @@ static int yaffs_gc_block(yaffs_dev_t *d
274                      * No need to copy this, just forget about it and
275                      * fix up the object.
276                      */
277-
278+
279                     /* Free chunks already includes softdeleted chunks.
280                      * How ever this chunk is going to soon be really deleted
281                      * which will increment free chunks.
282@@ -2752,7 +2752,7 @@ int yaffs_put_chunk_in_file(yaffs_obj_t
283                     NULL);
284     if (!tn)
285         return YAFFS_FAIL;
286-
287+
288     if(!nand_chunk)
289         /* Dummy insert, bail now */
290         return YAFFS_OK;
291@@ -2881,7 +2881,7 @@ void yaffs_chunk_del(yaffs_dev_t *dev, i
292              chunk_id));
293 
294     bi = yaffs_get_block_info(dev, block);
295-
296+
297     yaffs2_update_oldest_dirty_seq(dev, block, bi);
298 
299     T(YAFFS_TRACE_DELETION,
300@@ -2966,8 +2966,8 @@ static int yaffs_wr_data_obj(yaffs_obj_t
301         (TSTR("Writing %d bytes to chunk!!!!!!!!!" TENDSTR), n_bytes));
302         YBUG();
303     }
304-
305-
306+
307+
308     newChunkId =
309         yaffs_write_new_chunk(dev, buffer, &newTags,
310                           useReserve);
311@@ -3795,14 +3795,14 @@ int yaffs_resize_file(yaffs_obj_t *in, l
312 
313     if (new_size == oldFileSize)
314         return YAFFS_OK;
315-
316+
317     if(new_size > oldFileSize){
318         yaffs2_handle_hole(in,new_size);
319         in->variant.file_variant.file_size = new_size;
320     } else {
321- /* new_size < oldFileSize */
322+ /* new_size < oldFileSize */
323         yaffs_resize_file_down(in, new_size);
324- }
325+ }
326 
327     /* Write a new object header to reflect the resize.
328      * show we've shrunk the file, if need be
329@@ -4231,7 +4231,7 @@ static void yaffs_strip_deleted_objs(yaf
330  * This fixes the problem where directories might have inadvertently been deleted
331  * leaving the object "hanging" without being rooted in the directory tree.
332  */
333-
334+
335 static int yaffs_has_null_parent(yaffs_dev_t *dev, yaffs_obj_t *obj)
336 {
337     return (obj == dev->del_dir ||
338@@ -4262,7 +4262,7 @@ static void yaffs_fix_hanging_objs(yaffs
339             if (lh) {
340                 obj = ylist_entry(lh, yaffs_obj_t, hash_link);
341                 parent= obj->parent;
342-
343+
344                 if(yaffs_has_null_parent(dev,obj)){
345                     /* These directories are not hanging */
346                     hanging = 0;
347@@ -4311,7 +4311,7 @@ static void yaffs_del_dir_contents(yaffs
348 
349     if(dir->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
350         YBUG();
351-
352+
353     ylist_for_each_safe(lh, n, &dir->variant.dir_variant.children) {
354         if (lh) {
355             obj = ylist_entry(lh, yaffs_obj_t, siblings);
356@@ -4325,10 +4325,10 @@ static void yaffs_del_dir_contents(yaffs
357             /* Need to use UnlinkObject since Delete would not handle
358              * hardlinked objects correctly.
359              */
360- yaffs_unlink_obj(obj);
361+ yaffs_unlink_obj(obj);
362         }
363     }
364-
365+
366 }
367 
368 static void yaffs_empty_l_n_f(yaffs_dev_t *dev)
369@@ -4410,7 +4410,7 @@ static void yaffs_check_obj_details_load
370  * If the directory updating is defered then yaffs_update_dirty_dirs must be
371  * called periodically.
372  */
373-
374+
375 static void yaffs_update_parent(yaffs_obj_t *obj)
376 {
377     yaffs_dev_t *dev;
378@@ -4422,8 +4422,8 @@ static void yaffs_update_parent(yaffs_ob
379     obj->dirty = 1;
380     obj->yst_mtime = obj->yst_ctime = Y_CURRENT_TIME;
381     if(dev->param.defered_dir_update){
382- struct ylist_head *link = &obj->variant.dir_variant.dirty;
383-
384+ struct ylist_head *link = &obj->variant.dir_variant.dirty;
385+
386         if(ylist_empty(link)){
387             ylist_add(link,&dev->dirty_dirs);
388             T(YAFFS_TRACE_BACKGROUND, (TSTR("Added object %d to dirty directories" TENDSTR),obj->obj_id));
389@@ -4446,7 +4446,7 @@ void yaffs_update_dirty_dirs(yaffs_dev_t
390     while(!ylist_empty(&dev->dirty_dirs)){
391         link = dev->dirty_dirs.next;
392         ylist_del_init(link);
393-
394+
395         dS=ylist_entry(link,yaffs_dir_s,dirty);
396         oV = ylist_entry(dS,yaffs_obj_variant,dir_variant);
397         obj = ylist_entry(oV,yaffs_obj_t,variant);
398@@ -4474,7 +4474,7 @@ static void yaffs_remove_obj_from_dir(ya
399 
400     ylist_del_init(&obj->siblings);
401     obj->parent = NULL;
402-
403+
404     yaffs_verify_dir(parent);
405 }
406 
407@@ -4645,7 +4645,7 @@ yaffs_obj_t *yaffs_get_equivalent_obj(ya
408  * system to share files.
409  *
410  * These automatic unicode are stored slightly differently...
411- * - If the name can fit in the ASCII character space then they are saved as
412+ * - If the name can fit in the ASCII character space then they are saved as
413  * ascii names as per above.
414  * - If the name needs Unicode then the name is saved in Unicode
415  * starting at oh->name[1].
416@@ -4686,7 +4686,7 @@ static void yaffs_load_name_from_oh(yaff
417                 asciiOhName++;
418                 n--;
419             }
420- } else
421+ } else
422             yaffs_strncpy(name,ohName+1, bufferSize -1);
423     } else
424 #endif
425@@ -4705,7 +4705,7 @@ static void yaffs_load_oh_from_name(yaff
426 
427         isAscii = 1;
428         w = name;
429-
430+
431         /* Figure out if the name will fit in ascii character set */
432         while(isAscii && *w){
433             if((*w) & 0xff00)
434@@ -4729,7 +4729,7 @@ static void yaffs_load_oh_from_name(yaff
435             yaffs_strncpy(ohName+1,name, YAFFS_MAX_NAME_LENGTH -2);
436         }
437     }
438- else
439+ else
440 #endif
441         yaffs_strncpy(ohName,name, YAFFS_MAX_NAME_LENGTH - 1);
442 
443@@ -4738,12 +4738,12 @@ static void yaffs_load_oh_from_name(yaff
444 int yaffs_get_obj_name(yaffs_obj_t * obj, YCHAR * name, int buffer_size)
445 {
446     memset(name, 0, buffer_size * sizeof(YCHAR));
447-
448+
449     yaffs_check_obj_details_loaded(obj);
450 
451     if (obj->obj_id == YAFFS_OBJECTID_LOSTNFOUND) {
452         yaffs_strncpy(name, YAFFS_LOSTNFOUND_NAME, buffer_size - 1);
453- }
454+ }
455 #ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM
456     else if (obj->short_name[0]) {
457         yaffs_strcpy(name, obj->short_name);
458@@ -4861,9 +4861,9 @@ int yaffs_set_attribs(yaffs_obj_t *obj,
459     if (valid & ATTR_MODE)
460         obj->yst_mode = attr->ia_mode;
461     if (valid & ATTR_UID)
462- obj->yst_uid = attr->ia_uid;
463+ obj->yst_uid = ia_uid_read(attr);
464     if (valid & ATTR_GID)
465- obj->yst_gid = attr->ia_gid;
466+ obj->yst_gid = ia_gid_read(attr);
467 
468     if (valid & ATTR_ATIME)
469         obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime);
470@@ -4886,9 +4886,9 @@ int yaffs_get_attribs(yaffs_obj_t *obj,
471 
472     attr->ia_mode = obj->yst_mode;
473     valid |= ATTR_MODE;
474- attr->ia_uid = obj->yst_uid;
475+ ia_uid_write(attr, obj->yst_uid);
476     valid |= ATTR_UID;
477- attr->ia_gid = obj->yst_gid;
478+ ia_gid_write(attr, obj->yst_gid);
479     valid |= ATTR_GID;
480 
481     Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;
482--- a/fs/yaffs2/yportenv.h
483+++ b/fs/yaffs2/yportenv.h
484@@ -170,7 +170,7 @@
485 #define O_RDWR 02
486 #endif
487 
488-#ifndef O_CREAT
489+#ifndef O_CREAT
490 #define O_CREAT 0100
491 #endif
492 
493@@ -218,7 +218,7 @@
494 #define EACCES 13
495 #endif
496 
497-#ifndef EXDEV
498+#ifndef EXDEV
499 #define EXDEV 18
500 #endif
501 
502@@ -281,7 +281,7 @@
503 #define S_IFREG 0100000
504 #endif
505 
506-#ifndef S_IREAD
507+#ifndef S_IREAD
508 #define S_IREAD 0000400
509 #endif
510 
511--- a/fs/yaffs2/devextras.h
512+++ b/fs/yaffs2/devextras.h
513@@ -87,6 +87,8 @@ struct iattr {
514     unsigned int ia_attr_flags;
515 };
516 
517+/* TODO: add ia_* functions */
518+
519 #endif
520 
521 #else
522@@ -95,7 +97,48 @@ struct iattr {
523 #include <linux/fs.h>
524 #include <linux/stat.h>
525 
526+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
527+static inline uid_t ia_uid_read(const struct iattr *iattr)
528+{
529+ return from_kuid(&init_user_ns, iattr->ia_uid);
530+}
531+
532+static inline gid_t ia_gid_read(const struct iattr *iattr)
533+{
534+ return from_kgid(&init_user_ns, iattr->ia_gid);
535+}
536+
537+static inline void ia_uid_write(struct iattr *iattr, uid_t uid)
538+{
539+ iattr->ia_uid = make_kuid(&init_user_ns, uid);
540+}
541+
542+static inline void ia_gid_write(struct iattr *iattr, gid_t gid)
543+{
544+ iattr->ia_gid = make_kgid(&init_user_ns, gid);
545+}
546+#else
547+static inline uid_t ia_uid_read(const struct iattr *iattr)
548+{
549+ return iattr->ia_uid;
550+}
551+
552+static inline gid_t ia_gid_read(const struct iattr *inode)
553+{
554+ return iattr->ia_gid;
555+}
556+
557+static inline void ia_uid_write(struct iattr *iattr, uid_t uid)
558+{
559+ iattr->ia_uid = uid;
560+}
561+
562+static inline void ia_gid_write(struct iattr *iattr, gid_t gid)
563+{
564+ iattr->ia_gid = gid;
565+}
566 #endif
567 
568+#endif
569 
570 #endif
571

Archive Download this file



interactive