blob: 06ab7b8802126bdc5a5209372e208797f876dc10 [file] [log] [blame]
KaiGai Kohei652ecc22006-05-13 15:18:27 +09001/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +09003 *
KaiGai Kohei652ecc22006-05-13 15:18:27 +09004 * Copyright (C) 2006 NEC Corporation
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +09005 *
KaiGai Kohei652ecc22006-05-13 15:18:27 +09006 * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 */
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090011#ifndef _JFFS2_FS_XATTR_H_
12#define _JFFS2_FS_XATTR_H_
13
14#include <linux/xattr.h>
KaiGai Kohei4470d042006-05-13 15:17:11 +090015#include <linux/list.h>
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090016
17#define JFFS2_XFLAGS_HOT (0x01) /* This datum is HOT */
18#define JFFS2_XFLAGS_BIND (0x02) /* This datum is not reclaimed */
KaiGai Koheic9f700f2006-06-11 10:35:15 +090019#define JFFS2_XFLAGS_INVALID (0x80) /* This datum contains crc error */
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090020
21struct jffs2_xattr_datum
22{
23 void *always_null;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090024 struct jffs2_raw_node_ref *node;
David Woodhouse987d47b2006-05-22 16:32:05 +010025 uint8_t class;
26 uint8_t flags;
KaiGai Koheic9f700f2006-06-11 10:35:15 +090027 uint16_t xprefix; /* see JFFS2_XATTR_PREFIX_* */
David Woodhouse987d47b2006-05-22 16:32:05 +010028
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090029 struct list_head xindex; /* chained from c->xattrindex[n] */
30 uint32_t refcnt; /* # of xattr_ref refers this */
31 uint32_t xid;
32 uint32_t version;
33
34 uint32_t data_crc;
35 uint32_t hashkey;
36 char *xname; /* XATTR name without prefix */
37 uint32_t name_len; /* length of xname */
38 char *xvalue; /* XATTR value */
39 uint32_t value_len; /* length of xvalue */
40};
41
KaiGai Koheiee886b52006-05-13 15:19:03 +090042struct jffs2_inode_cache;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090043struct jffs2_xattr_ref
44{
45 void *always_null;
David Woodhouse987d47b2006-05-22 16:32:05 +010046 struct jffs2_raw_node_ref *node;
47 uint8_t class;
48 uint8_t flags; /* Currently unused */
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090049 u16 unused;
50
KaiGai Koheic9f700f2006-06-11 10:35:15 +090051 uint32_t xseqno;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090052 union {
53 struct jffs2_inode_cache *ic; /* reference to jffs2_inode_cache */
54 uint32_t ino; /* only used in scanning/building */
55 };
56 union {
57 struct jffs2_xattr_datum *xd; /* reference to jffs2_xattr_datum */
58 uint32_t xid; /* only used in sccanning/building */
59 };
KaiGai Kohei8f2b6f42006-05-13 15:15:07 +090060 struct jffs2_xattr_ref *next; /* chained from ic->xref_list */
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090061};
62
KaiGai Koheic9f700f2006-06-11 10:35:15 +090063#define XDATUM_DELETE_MARKER (0xffffffff)
64#define XREF_DELETE_MARKER (0x00000001)
65static inline int is_xattr_datum_dead(struct jffs2_xattr_datum *xd)
66{
67 return (xd->version == XDATUM_DELETE_MARKER);
68}
69
70static inline void set_xattr_datum_dead(struct jffs2_xattr_datum *xd)
71{
72 xd->version = XDATUM_DELETE_MARKER;
73}
74
75static inline int is_xattr_ref_dead(struct jffs2_xattr_ref *ref)
76{
77 return ((ref->xseqno & XREF_DELETE_MARKER) != 0);
78}
79
80static inline void set_xattr_ref_dead(struct jffs2_xattr_ref *ref)
81{
82 ref->xseqno |= XREF_DELETE_MARKER;
83}
84
85static inline void clr_xattr_ref_dead(struct jffs2_xattr_ref *ref)
86{
87 ref->xseqno &= ~XREF_DELETE_MARKER;
88}
89
90
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090091#ifdef CONFIG_JFFS2_FS_XATTR
92
93extern void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c);
94extern void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c);
95extern void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c);
96
97extern struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,
98 uint32_t xid, uint32_t version);
99
100extern void jffs2_xattr_delete_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic);
101extern void jffs2_xattr_free_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic);
102
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900103extern int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd,
104 struct jffs2_raw_node_ref *raw);
105extern int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
106 struct jffs2_raw_node_ref *raw);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900107extern int jffs2_verify_xattr(struct jffs2_sb_info *c);
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900108extern void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd);
109extern void jffs2_release_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900110
111extern int do_jffs2_getxattr(struct inode *inode, int xprefix, const char *xname,
112 char *buffer, size_t size);
113extern int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
114 const char *buffer, size_t size, int flags);
115
116extern struct xattr_handler *jffs2_xattr_handlers[];
117extern struct xattr_handler jffs2_user_xattr_handler;
118extern struct xattr_handler jffs2_trusted_xattr_handler;
119
120extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t);
121#define jffs2_getxattr generic_getxattr
122#define jffs2_setxattr generic_setxattr
123#define jffs2_removexattr generic_removexattr
124
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900125#else
126
127#define jffs2_init_xattr_subsystem(c)
128#define jffs2_build_xattr_subsystem(c)
129#define jffs2_clear_xattr_subsystem(c)
130
131#define jffs2_xattr_delete_inode(c, ic)
132#define jffs2_xattr_free_inode(c, ic)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900133#define jffs2_verify_xattr(c) (1)
134
135#define jffs2_xattr_handlers NULL
136#define jffs2_listxattr NULL
137#define jffs2_getxattr NULL
138#define jffs2_setxattr NULL
139#define jffs2_removexattr NULL
140
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900141#endif /* CONFIG_JFFS2_FS_XATTR */
142
143#ifdef CONFIG_JFFS2_FS_SECURITY
144extern int jffs2_init_security(struct inode *inode, struct inode *dir);
145extern struct xattr_handler jffs2_security_xattr_handler;
146#else
147#define jffs2_init_security(inode,dir) (0)
148#endif /* CONFIG_JFFS2_FS_SECURITY */
149
150#endif /* _JFFS2_FS_XATTR_H_ */