2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 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.
15 #include "yaffs_guts.h"
16 #include "yaffs_attribs.h"
18 void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
20 obj->yst_uid = oh->yst_uid;
21 obj->yst_gid = oh->yst_gid;
22 obj->yst_atime = oh->yst_atime;
23 obj->yst_mtime = oh->yst_mtime;
24 obj->yst_ctime = oh->yst_ctime;
25 obj->yst_rdev = oh->yst_rdev;
28 void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj)
30 oh->yst_uid = obj->yst_uid;
31 oh->yst_gid = obj->yst_gid;
32 oh->yst_atime = obj->yst_atime;
33 oh->yst_mtime = obj->yst_mtime;
34 oh->yst_ctime = obj->yst_ctime;
35 oh->yst_rdev = obj->yst_rdev;
39 void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c)
41 obj->yst_mtime = Y_CURRENT_TIME;
43 obj->yst_atime = obj->yst_atime;
45 obj->yst_ctime = obj->yst_atime;
48 void yaffs_attribs_init(struct yaffs_obj *obj, u32 gid, u32 uid, u32 rdev)
50 yaffs_load_current_time(obj,1,1);
57 loff_t yaffs_get_file_size(struct yaffs_obj *obj)
60 obj = yaffs_get_equivalent_obj(obj);
62 switch (obj->variant_type) {
63 case YAFFS_OBJECT_TYPE_FILE:
64 return obj->variant.file_variant.file_size;
65 case YAFFS_OBJECT_TYPE_SYMLINK:
66 alias = obj->variant.symlink_variant.alias;
69 return yaffs_strnlen(alias,YAFFS_MAX_ALIAS_LENGTH);
75 int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr)
77 unsigned int valid = attr->ia_valid;
79 if (valid & ATTR_MODE)
80 obj->yst_mode = attr->ia_mode;
82 obj->yst_uid = attr->ia_uid;
84 obj->yst_gid = attr->ia_gid;
86 if (valid & ATTR_ATIME)
87 obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime);
88 if (valid & ATTR_CTIME)
89 obj->yst_ctime = Y_TIME_CONVERT(attr->ia_ctime);
90 if (valid & ATTR_MTIME)
91 obj->yst_mtime = Y_TIME_CONVERT(attr->ia_mtime);
93 if (valid & ATTR_SIZE)
94 yaffs_resize_file(obj, attr->ia_size);
96 yaffs_update_oh(obj, NULL, 1, 0, 0, NULL);
102 int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr)
104 unsigned int valid = 0;
106 attr->ia_mode = obj->yst_mode;
108 attr->ia_uid = obj->yst_uid;
110 attr->ia_gid = obj->yst_gid;
113 Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;
115 Y_TIME_CONVERT(attr->ia_ctime) = obj->yst_ctime;
117 Y_TIME_CONVERT(attr->ia_mtime) = obj->yst_mtime;
120 attr->ia_size = yaffs_get_file_size(obj);
123 attr->ia_valid = valid;