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