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(
8 #define update_dir_time(dir) do {\
9 (dir)->i_ctime = (dir)->i_mtime = CURRENT_TIME; \
13 static void yaffs_put_super(struct super_block *sb);
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
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())
24 +#define YCRED_FSUID() YCRED(current)->fsuid
25 +#define YCRED_FSGID() YCRED(current)->fsgid
27 +static inline uid_t i_uid_read(const struct inode *inode)
29 + return inode->i_uid;
32 +static inline gid_t i_gid_read(const struct inode *inode)
34 + return inode->i_gid;
37 +static inline void i_uid_write(struct inode *inode, uid_t uid)
42 +static inline void i_gid_write(struct inode *inode, gid_t gid)
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
52 return yaffs_gc_control;
56 static void yaffs_gross_lock(yaffs_dev_t *dev)
58 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locking %p\n"), current));
59 @@ -1379,8 +1405,8 @@ static void yaffs_fill_inode_from_obj(st
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;
70 @@ -1406,7 +1432,7 @@ static void yaffs_fill_inode_from_obj(st
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)));
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);
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();
88 if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
90 @@ -1892,8 +1918,8 @@ static int yaffs_symlink(struct inode *d
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();
99 T(YAFFS_TRACE_OS, (TSTR("yaffs_symlink\n")));
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));
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))
110 @@ -2240,7 +2266,7 @@ static void yaffs_flush_inodes(struct su
116 list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
117 obj = yaffs_InodeToObject(iptr);
119 @@ -2254,10 +2280,10 @@ static void yaffs_flush_inodes(struct su
121 static void yaffs_flush_super(struct super_block *sb, int do_checkpoint)
123 - yaffs_dev_t *dev = yaffs_SuperToDevice(sb);
124 + yaffs_dev_t *dev = yaffs_SuperToDevice(sb);
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.
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
143 dev = kmalloc(sizeof(yaffs_dev_t), GFP_KERNEL);
144 context = kmalloc(sizeof(struct yaffs_LinuxContext),GFP_KERNEL);
147 if(!dev || !context ){
150 @@ -2957,7 +2983,7 @@ static struct super_block *yaffs_interna
152 sb->u.generic_sbp = dev;
156 dev->driver_context = mtd;
157 param->name = mtd->name;
159 @@ -3057,7 +3083,7 @@ static struct super_block *yaffs_interna
160 param->gc_control = yaffs_gc_control_callback;
162 yaffs_dev_to_lc(dev)->superBlock= sb;
166 #ifndef CONFIG_YAFFS_DOES_ECC
167 param->use_nand_ecc = 1;
168 @@ -3099,10 +3125,10 @@ static struct super_block *yaffs_interna
170 (TSTR("yaffs_read_super: guts initialised %s\n"),
171 (err == YAFFS_OK) ? "OK" : "FAILED"));
178 if(!context->bgThread)
179 param->defered_dir_update = 0;
181 @@ -3345,7 +3371,7 @@ static int yaffs_proc_read(char *page,
182 buf += sprintf(buf,"\n");
187 mutex_lock(&yaffs_context_lock);
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);
193 buf = yaffs_dump_dev_part1(buf, dev);
198 mutex_unlock(&yaffs_context_lock);
199 @@ -3389,7 +3415,7 @@ static int yaffs_stats_proc_read(char *p
202 erasedChunks = dev->n_erased_blocks * dev->param.chunks_per_block;
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__);
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.
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
228 @@ -486,7 +486,7 @@ static int yaffs_write_new_chunk(struct
235 * Block retiring for handling a broken block.
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);
240 yaffs2_checkpt_invalidate(dev);
243 yaffs2_clear_oldest_dirty_seq(dev,bi);
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)) {
252 if(dev->chunk_grp_size == 1)
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);
264 @@ -2125,7 +2125,7 @@ static int yaffs_gc_block(yaffs_dev_t *d
266 if(bi->block_state == YAFFS_BLOCK_STATE_FULL)
267 bi->block_state = YAFFS_BLOCK_STATE_COLLECTING;
270 bi->has_shrink_hdr = 0; /* clear the flag so that the block can erase */
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
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
289 /* Dummy insert, bail now */
291 @@ -2881,7 +2881,7 @@ void yaffs_chunk_del(yaffs_dev_t *dev, i
294 bi = yaffs_get_block_info(dev, block);
297 yaffs2_update_oldest_dirty_seq(dev, block, bi);
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));
309 yaffs_write_new_chunk(dev, buffer, &newTags,
311 @@ -3795,14 +3795,14 @@ int yaffs_resize_file(yaffs_obj_t *in, l
313 if (new_size == oldFileSize)
317 if(new_size > oldFileSize){
318 yaffs2_handle_hole(in,new_size);
319 in->variant.file_variant.file_size = new_size;
321 - /* new_size < oldFileSize */
322 + /* new_size < oldFileSize */
323 yaffs_resize_file_down(in, new_size);
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.
335 static int yaffs_has_null_parent(yaffs_dev_t *dev, yaffs_obj_t *obj)
337 return (obj == dev->del_dir ||
338 @@ -4262,7 +4262,7 @@ static void yaffs_fix_hanging_objs(yaffs
340 obj = ylist_entry(lh, yaffs_obj_t, hash_link);
344 if(yaffs_has_null_parent(dev,obj)){
345 /* These directories are not hanging */
347 @@ -4311,7 +4311,7 @@ static void yaffs_del_dir_contents(yaffs
349 if(dir->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
353 ylist_for_each_safe(lh, n, &dir->variant.dir_variant.children) {
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.
360 - yaffs_unlink_obj(obj);
361 + yaffs_unlink_obj(obj);
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.
375 static void yaffs_update_parent(yaffs_obj_t *obj)
378 @@ -4422,8 +4422,8 @@ static void yaffs_update_parent(yaffs_ob
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;
384 + struct ylist_head *link = &obj->variant.dir_variant.dirty;
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);
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
400 ylist_del_init(&obj->siblings);
404 yaffs_verify_dir(parent);
407 @@ -4645,7 +4645,7 @@ yaffs_obj_t *yaffs_get_equivalent_obj(ya
408 * system to share files.
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
422 yaffs_strncpy(name,ohName+1, bufferSize -1);
425 @@ -4705,7 +4705,7 @@ static void yaffs_load_oh_from_name(yaff
431 /* Figure out if the name will fit in ascii character set */
432 while(isAscii && *w){
434 @@ -4729,7 +4729,7 @@ static void yaffs_load_oh_from_name(yaff
435 yaffs_strncpy(ohName+1,name, YAFFS_MAX_NAME_LENGTH -2);
441 yaffs_strncpy(ohName,name, YAFFS_MAX_NAME_LENGTH - 1);
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)
446 memset(name, 0, buffer_size * sizeof(YCHAR));
449 yaffs_check_obj_details_loaded(obj);
451 if (obj->obj_id == YAFFS_OBJECTID_LOSTNFOUND) {
452 yaffs_strncpy(name, YAFFS_LOSTNFOUND_NAME, buffer_size - 1);
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);
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,
472 attr->ia_mode = obj->yst_mode;
474 - attr->ia_uid = obj->yst_uid;
475 + ia_uid_write(attr, obj->yst_uid);
477 - attr->ia_gid = obj->yst_gid;
478 + ia_gid_write(attr, obj->yst_gid);
481 Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;
482 --- a/fs/yaffs2/yportenv.h
483 +++ b/fs/yaffs2/yportenv.h
503 #define S_IFREG 0100000
508 #define S_IREAD 0000400
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;
517 +/* TODO: add ia_* functions */
522 @@ -95,7 +97,48 @@ struct iattr {
523 #include <linux/fs.h>
524 #include <linux/stat.h>
526 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
527 +static inline uid_t ia_uid_read(const struct iattr *iattr)
529 + return from_kuid(&init_user_ns, iattr->ia_uid);
532 +static inline gid_t ia_gid_read(const struct iattr *iattr)
534 + return from_kgid(&init_user_ns, iattr->ia_gid);
537 +static inline void ia_uid_write(struct iattr *iattr, uid_t uid)
539 + iattr->ia_uid = make_kuid(&init_user_ns, uid);
542 +static inline void ia_gid_write(struct iattr *iattr, gid_t gid)
544 + iattr->ia_gid = make_kgid(&init_user_ns, gid);
547 +static inline uid_t ia_uid_read(const struct iattr *iattr)
549 + return iattr->ia_uid;
552 +static inline gid_t ia_gid_read(const struct iattr *inode)
554 + return iattr->ia_gid;
557 +static inline void ia_uid_write(struct iattr *iattr, uid_t uid)
559 + iattr->ia_uid = uid;
562 +static inline void ia_gid_write(struct iattr *iattr, gid_t gid)
564 + iattr->ia_gid = gid;