blob: 81927cb9437a554104169d74da103c96db4e4b26 [file] [log] [blame]
Charles Manning753ac612012-05-09 16:55:17 +00001/*
2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3 *
4 * Copyright (C) 2002-2011 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
6 *
7 * Created by Charles Manning <charles@aleph1.co.uk>
8 *
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.
12 */
13
14#include "yaffs_attribs.h"
15
Charles Manning753ac612012-05-09 16:55:17 +000016void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
17{
18 obj->yst_uid = oh->yst_uid;
19 obj->yst_gid = oh->yst_gid;
20 obj->yst_atime = oh->yst_atime;
21 obj->yst_mtime = oh->yst_mtime;
22 obj->yst_ctime = oh->yst_ctime;
23 obj->yst_rdev = oh->yst_rdev;
24}
25
Charles Manning753ac612012-05-09 16:55:17 +000026void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj)
27{
28#ifdef CONFIG_YAFFS_WINCE
29 oh->win_atime[0] = obj->win_atime[0];
30 oh->win_ctime[0] = obj->win_ctime[0];
31 oh->win_mtime[0] = obj->win_mtime[0];
32 oh->win_atime[1] = obj->win_atime[1];
33 oh->win_ctime[1] = obj->win_ctime[1];
34 oh->win_mtime[1] = obj->win_mtime[1];
35#else
36 oh->yst_uid = obj->yst_uid;
37 oh->yst_gid = obj->yst_gid;
38 oh->yst_atime = obj->yst_atime;
39 oh->yst_mtime = obj->yst_mtime;
40 oh->yst_ctime = obj->yst_ctime;
41 oh->yst_rdev = obj->yst_rdev;
42#endif
43
44}
45
46void yaffs_attribs_init(struct yaffs_obj *obj, u32 gid, u32 uid, u32 rdev)
47{
48
49#ifdef CONFIG_YAFFS_WINCE
50 yfsd_win_file_time_now(obj->win_atime);
51 obj->win_ctime[0] = obj->win_mtime[0] = obj->win_atime[0];
52 obj->win_ctime[1] = obj->win_mtime[1] = obj->win_atime[1];
53
54#else
55 yaffs_load_current_time(obj, 1, 1);
56 obj->yst_rdev = rdev;
57 obj->yst_uid = uid;
58 obj->yst_gid = gid;
59#endif
60}
61
62void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c)
63{
64#ifdef CONFIG_YAFFS_WINCE
65 yfsd_win_file_time_now(the_obj->win_atime);
66 the_obj->win_ctime[0] = the_obj->win_mtime[0] =
67 the_obj->win_atime[0];
68 the_obj->win_ctime[1] = the_obj->win_mtime[1] =
69 the_obj->win_atime[1];
70
71#else
72
73 obj->yst_mtime = Y_CURRENT_TIME;
74 if (do_a)
75 obj->yst_atime = obj->yst_atime;
76 if (do_c)
77 obj->yst_ctime = obj->yst_atime;
78#endif
79}
80
81loff_t yaffs_get_file_size(struct yaffs_obj *obj)
82{
83 YCHAR *alias = NULL;
84 obj = yaffs_get_equivalent_obj(obj);
85
86 switch (obj->variant_type) {
87 case YAFFS_OBJECT_TYPE_FILE:
88 return obj->variant.file_variant.file_size;
89 case YAFFS_OBJECT_TYPE_SYMLINK:
90 alias = obj->variant.symlink_variant.alias;
91 if (!alias)
92 return 0;
93 return yaffs_strnlen(alias, YAFFS_MAX_ALIAS_LENGTH);
94 default:
95 return 0;
96 }
97}
98
99int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr)
100{
101 unsigned int valid = attr->ia_valid;
102
103 if (valid & ATTR_MODE)
104 obj->yst_mode = attr->ia_mode;
105 if (valid & ATTR_UID)
106 obj->yst_uid = attr->ia_uid;
107 if (valid & ATTR_GID)
108 obj->yst_gid = attr->ia_gid;
109
110 if (valid & ATTR_ATIME)
111 obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime);
112 if (valid & ATTR_CTIME)
113 obj->yst_ctime = Y_TIME_CONVERT(attr->ia_ctime);
114 if (valid & ATTR_MTIME)
115 obj->yst_mtime = Y_TIME_CONVERT(attr->ia_mtime);
116
117 if (valid & ATTR_SIZE)
118 yaffs_resize_file(obj, attr->ia_size);
119
120 yaffs_update_oh(obj, NULL, 1, 0, 0, NULL);
121
122 return YAFFS_OK;
123
124}
125
126int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr)
127{
128 unsigned int valid = 0;
129
130 attr->ia_mode = obj->yst_mode;
131 valid |= ATTR_MODE;
132 attr->ia_uid = obj->yst_uid;
133 valid |= ATTR_UID;
134 attr->ia_gid = obj->yst_gid;
135 valid |= ATTR_GID;
136
137 Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime;
138 valid |= ATTR_ATIME;
139 Y_TIME_CONVERT(attr->ia_ctime) = obj->yst_ctime;
140 valid |= ATTR_CTIME;
141 Y_TIME_CONVERT(attr->ia_mtime) = obj->yst_mtime;
142 valid |= ATTR_MTIME;
143
144 attr->ia_size = yaffs_get_file_size(obj);
145 valid |= ATTR_SIZE;
146
147 attr->ia_valid = valid;
148
149 return YAFFS_OK;
150}