2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2011 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
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.
14 #include "yaffs_guts.h"
15 #include "yaffs_attribs.h"
17 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
18 #define IATTR_UID ia_uid
19 #define IATTR_GID ia_gid
21 #define IATTR_UID ia_uid.val
22 #define IATTR_GID ia_gid.val
25 void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
27 obj->yst_uid = oh->yst_uid;
28 obj->yst_gid = oh->yst_gid;
29 obj->yst_atime = oh->yst_atime;
30 obj->yst_mtime = oh->yst_mtime;
31 obj->yst_ctime = oh->yst_ctime;
32 obj->yst_rdev = oh->yst_rdev;
35 void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj)
37 oh->yst_uid = obj->yst_uid;
38 oh->yst_gid = obj->yst_gid;
39 oh->yst_atime = obj->yst_atime;
40 oh->yst_mtime = obj->yst_mtime;
41 oh->yst_ctime = obj->yst_ctime;
42 oh->yst_rdev = obj->yst_rdev;
46 void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c)
48 obj->yst_mtime = Y_CURRENT_TIME;
50 obj->yst_atime = obj->yst_mtime;
52 obj->yst_ctime = obj->yst_mtime;
55 void yaffs_attribs_init(struct yaffs_obj *obj, u32 gid, u32 uid, u32 rdev)
57 yaffs_load_current_time(obj, 1, 1);
63 static loff_t yaffs_get_file_size(struct yaffs_obj *obj)
66 obj = yaffs_get_equivalent_obj(obj);
68 switch (obj->variant_type) {
69 case YAFFS_OBJECT_TYPE_FILE:
70 return obj->variant.file_variant.file_size;
71 case YAFFS_OBJECT_TYPE_SYMLINK:
72 alias = obj->variant.symlink_variant.alias;
75 return strnlen(alias, YAFFS_MAX_ALIAS_LENGTH);
81 int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr)
83 unsigned int valid = attr->ia_valid;
85 if (valid & ATTR_MODE)
86 obj->yst_mode = attr->ia_mode;
88 obj->yst_uid = attr->IATTR_UID;
90 obj->yst_gid = attr->IATTR_GID;
92 if (valid & ATTR_ATIME)
93 obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime);
94 if (valid & ATTR_CTIME)
95 obj->yst_ctime = Y_TIME_CONVERT(attr->ia_ctime);
96 if (valid & ATTR_MTIME)
97 obj->yst_mtime = Y_TIME_CONVERT(attr->ia_mtime);
99 if (valid & ATTR_SIZE)
100 yaffs_resize_file(obj, attr->ia_size);
102 yaffs_update_oh(obj, NULL, 1, 0, 0, NULL);
108 int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr)
110 unsigned int valid = 0;
112 attr->ia_mode = obj->yst_mode;
114 attr->IATTR_UID = obj->yst_uid;
116 attr->IATTR_GID = obj->yst_gid;
119 Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;
121 Y_TIME_CONVERT(attr->ia_ctime) = obj->yst_ctime;
123 Y_TIME_CONVERT(attr->ia_mtime) = obj->yst_mtime;
126 attr->ia_size = yaffs_get_file_size(obj);
129 attr->ia_valid = valid;