1 /* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
3 /* This describes the static_stat item, used to hold all information needed by the stat() syscall.
5 In the case where each file has not less than the fields needed by the
6 stat() syscall, it is more compact to store those fields in this
9 If this item does not exist, then all stats are dynamically resolved.
10 At the moment, we either resolve all stats dynamically or all of them
11 statically. If you think this is not fully optimal, and the rest of
12 reiser4 is working, then fix it...:-)
16 #if !defined( __FS_REISER4_PLUGIN_ITEM_STATIC_STAT_H__ )
17 #define __FS_REISER4_PLUGIN_ITEM_STATIC_STAT_H__
19 #include "../../forward.h"
20 #include "../../dformat.h"
22 #include <linux/fs.h> /* for struct inode */
24 /* Stat data layout: goals and implementation.
26 We want to be able to have lightweight files which have complete flexibility in what semantic metadata is attached to
27 them, including not having semantic metadata attached to them.
29 There is one problem with doing that, which is that if in fact you have exactly the same metadata for most files you
30 want to store, then it takes more space to store that metadata in a dynamically sized structure than in a statically
31 sized structure because the statically sized structure knows without recording it what the names and lengths of the
34 This leads to a natural compromise, which is to special case those files which have simply the standard unix file
35 attributes, and only employ the full dynamic stat data mechanism for those files that differ from the standard unix
36 file in their use of file attributes.
38 Yet this compromise deserves to be compromised a little.
40 We accommodate the case where you have no more than the standard unix file attributes by using an "extension
41 bitmask": each bit in it indicates presence or absence of or particular stat data extension (see sd_ext_bits enum).
43 If the first bit of the extension bitmask bit is 0, we have light-weight file whose attributes are either inherited
44 from parent directory (as uid, gid) or initialised to some sane values.
46 To capitalize on existing code infrastructure, extensions are
47 implemented as plugins of type REISER4_SD_EXT_PLUGIN_TYPE.
48 Each stat-data extension plugin implements four methods:
50 ->present() called by sd_load() when this extension is found in stat-data
51 ->absent() called by sd_load() when this extension is not found in stat-data
52 ->save_len() called by sd_len() to calculate total length of stat-data
53 ->save() called by sd_save() to store extension data into stat-data
55 Implementation is in fs/reiser4/plugin/item/static_stat.c
58 /* stat-data extension. Please order this by presumed frequency of use */
60 /* support for light-weight files */
62 /* data required to implement unix stat(2) call. Layout is in
63 reiser4_unix_stat. If this is not present, file is light-weight */
65 /* this contains additional set of 32bit [anc]time fields to implement
66 nanosecond resolution. Layout is in reiser4_large_times_stat. Usage
67 if this extension is governed by 32bittimes mount option. */
69 /* stat data has link name included */
71 /* on-disk slots of non-standard plugins for main plugin table
72 (@reiser4_inode->pset), that is, plugins that cannot be deduced
73 from file mode bits), for example, aggregation, interpolation etc. */
75 /* this extension contains persistent inode flags. These flags are
76 single bits: immutable, append, only, etc. Layout is in
77 reiser4_flags_stat. */
79 /* this extension contains capabilities sets, associated with this
80 file. Layout is in reiser4_capabilities_stat */
82 /* this extension contains size and public id of the secret key.
83 Layout is in reiser4_crypto_stat */
85 /* on-disk slots of non-default plugins for inheritance, which
86 are extracted to special plugin table (@reiser4_inode->hset).
87 By default, children of the object will inherit plugins from
88 its main plugin table (pset). */
92 * init_inode_static_sd() iterates over extension mask until all
93 * non-zero bits are processed. This means, that neither ->present(),
94 * nor ->absent() methods will be called for stat-data extensions that
95 * go after last present extension. But some basic extensions, we want
96 * either ->absent() or ->present() method to be called, because these
97 * extensions set up something in inode even when they are not
98 * present. This is what LAST_IMPORTANT_SD_EXTENSION is for: for all
99 * extensions before and including LAST_IMPORTANT_SD_EXTENSION either
100 * ->present(), or ->absent() method will be called, independently of
101 * what other extensions are present.
103 LAST_IMPORTANT_SD_EXTENSION
= PLUGIN_STAT
106 /* minimal stat-data. This allows to support light-weight files. */
107 typedef struct reiser4_stat_data_base
{
108 /* 0 */ __le16 extmask
;
110 } PACKED reiser4_stat_data_base
;
112 typedef struct reiser4_light_weight_stat
{
114 /* 2 */ __le32 nlink
;
118 } PACKED reiser4_light_weight_stat
;
120 typedef struct reiser4_unix_stat
{
126 /* 8 */ __le32 atime
;
127 /* modification time */
128 /* 12 */ __le32 mtime
;
130 /* 16 */ __le32 ctime
;
132 /* minor:major for device files */
133 /* 20 */ __le64 rdev
;
134 /* bytes used by file */
135 /* 20 */ __le64 bytes
;
138 } PACKED reiser4_unix_stat
;
140 /* symlink stored as part of inode */
141 typedef struct reiser4_symlink_stat
{
143 } PACKED reiser4_symlink_stat
;
145 typedef struct reiser4_plugin_slot
{
146 /* 0 */ __le16 pset_memb
;
148 /* 4 *//* here plugin stores its persistent state */
149 } PACKED reiser4_plugin_slot
;
151 /* stat-data extension for files with non-standard plugin. */
152 typedef struct reiser4_plugin_stat
{
153 /* number of additional plugins, associated with this object */
154 /* 0 */ __le16 plugins_no
;
155 /* 2 */ reiser4_plugin_slot slot
[0];
157 } PACKED reiser4_plugin_stat
;
159 /* stat-data extension for inode flags. Currently it is just fixed-width 32
160 * bit mask. If need arise, this can be replaced with variable width
162 typedef struct reiser4_flags_stat
{
163 /* 0 */ __le32 flags
;
165 } PACKED reiser4_flags_stat
;
167 typedef struct reiser4_capabilities_stat
{
168 /* 0 */ __le32 effective
;
169 /* 8 */ __le32 permitted
;
171 } PACKED reiser4_capabilities_stat
;
173 typedef struct reiser4_cluster_stat
{
174 /* this defines cluster size (an attribute of cryptcompress objects) as PAGE_SIZE << cluster shift */
175 /* 0 */ d8 cluster_shift
;
177 } PACKED reiser4_cluster_stat
;
179 typedef struct reiser4_crypto_stat
{
180 /* secret key size, bits */
185 } PACKED reiser4_crypto_stat
;
187 typedef struct reiser4_large_times_stat
{
190 /* modification time */
195 } PACKED reiser4_large_times_stat
;
197 /* this structure is filled by sd_item_stat */
198 typedef struct sd_stat
{
204 /* plugin->item.common.* */
205 extern void print_sd(const char *prefix
, coord_t
* coord
);
206 extern void item_stat_static_sd(const coord_t
* coord
, void *vp
);
208 /* plugin->item.s.sd.* */
209 extern int init_inode_static_sd(struct inode
*inode
, char *sd
, int len
);
210 extern int save_len_static_sd(struct inode
*inode
);
211 extern int save_static_sd(struct inode
*inode
, char **area
);
213 /* __FS_REISER4_PLUGIN_ITEM_STATIC_STAT_H__ */
218 c-indentation-style: "K&R"