blob: c82dbe01d7137f07d7bc1a90b59bb2ac22f5dd30 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
10#ifndef __EATTR_DOT_H__
11#define __EATTR_DOT_H__
12
Steven Whitehousef2f7ba52006-09-05 10:39:21 -040013struct gfs2_inode;
14struct iattr;
15
David Teiglandb3b94fa2006-01-16 16:50:04 +000016#define GFS2_EA_REC_LEN(ea) be32_to_cpu((ea)->ea_rec_len)
17#define GFS2_EA_DATA_LEN(ea) be32_to_cpu((ea)->ea_data_len)
18
19#define GFS2_EA_SIZE(ea) \
20ALIGN(sizeof(struct gfs2_ea_header) + (ea)->ea_name_len + \
21 ((GFS2_EA_IS_STUFFED(ea)) ? GFS2_EA_DATA_LEN(ea) : \
Al Virob44b84d2006-10-14 10:46:30 -040022 (sizeof(__be64) * (ea)->ea_num_ptrs)), 8)
David Teiglandb3b94fa2006-01-16 16:50:04 +000023
David Teiglandb3b94fa2006-01-16 16:50:04 +000024#define GFS2_EA_IS_STUFFED(ea) (!(ea)->ea_num_ptrs)
25#define GFS2_EA_IS_LAST(ea) ((ea)->ea_flags & GFS2_EAFLAG_LAST)
26
27#define GFS2_EAREQ_SIZE_STUFFED(er) \
28ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + (er)->er_data_len, 8)
29
30#define GFS2_EAREQ_SIZE_UNSTUFFED(sdp, er) \
31ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + \
Al Virob44b84d2006-10-14 10:46:30 -040032 sizeof(__be64) * DIV_ROUND_UP((er)->er_data_len, (sdp)->sd_jbsize), 8)
David Teiglandb3b94fa2006-01-16 16:50:04 +000033
34#define GFS2_EA2NAME(ea) ((char *)((struct gfs2_ea_header *)(ea) + 1))
35#define GFS2_EA2DATA(ea) (GFS2_EA2NAME(ea) + (ea)->ea_name_len)
36
37#define GFS2_EA2DATAPTRS(ea) \
Al Virob44b84d2006-10-14 10:46:30 -040038((__be64 *)(GFS2_EA2NAME(ea) + ALIGN((ea)->ea_name_len, 8)))
David Teiglandb3b94fa2006-01-16 16:50:04 +000039
40#define GFS2_EA2NEXT(ea) \
41((struct gfs2_ea_header *)((char *)(ea) + GFS2_EA_REC_LEN(ea)))
42
43#define GFS2_EA_BH2FIRST(bh) \
44((struct gfs2_ea_header *)((bh)->b_data + sizeof(struct gfs2_meta_header)))
45
46#define GFS2_ERF_MODE 0x80000000
47
48struct gfs2_ea_request {
Steven Whitehousecca195c2006-09-05 13:15:18 -040049 const char *er_name;
David Teiglandb3b94fa2006-01-16 16:50:04 +000050 char *er_data;
51 unsigned int er_name_len;
52 unsigned int er_data_len;
53 unsigned int er_type; /* GFS2_EATYPE_... */
54 int er_flags;
55 mode_t er_mode;
56};
57
58struct gfs2_ea_location {
59 struct buffer_head *el_bh;
60 struct gfs2_ea_header *el_ea;
61 struct gfs2_ea_header *el_prev;
62};
63
David Teiglandb3b94fa2006-01-16 16:50:04 +000064int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er);
65int gfs2_ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er);
66int gfs2_ea_remove_i(struct gfs2_inode *ip, struct gfs2_ea_request *er);
67
68int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er);
69int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er);
70int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er);
71int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er);
72
73int gfs2_ea_dealloc(struct gfs2_inode *ip);
74
David Teiglandb3b94fa2006-01-16 16:50:04 +000075/* Exported to acl.c */
76
77int gfs2_ea_find(struct gfs2_inode *ip,
78 struct gfs2_ea_request *er,
79 struct gfs2_ea_location *el);
80int gfs2_ea_get_copy(struct gfs2_inode *ip,
81 struct gfs2_ea_location *el,
82 char *data);
83int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el,
84 struct iattr *attr, char *data);
85
Ryan O'Hara639b6d72006-05-22 10:08:35 -040086static inline unsigned int gfs2_ea_strlen(struct gfs2_ea_header *ea)
87{
88 switch (ea->ea_type) {
89 case GFS2_EATYPE_USR:
Steven Whitehousecca195c2006-09-05 13:15:18 -040090 return 5 + ea->ea_name_len + 1;
Ryan O'Hara639b6d72006-05-22 10:08:35 -040091 case GFS2_EATYPE_SYS:
Steven Whitehousecca195c2006-09-05 13:15:18 -040092 return 7 + ea->ea_name_len + 1;
Ryan O'Hara639b6d72006-05-22 10:08:35 -040093 case GFS2_EATYPE_SECURITY:
Steven Whitehousecca195c2006-09-05 13:15:18 -040094 return 9 + ea->ea_name_len + 1;
Ryan O'Hara639b6d72006-05-22 10:08:35 -040095 default:
Steven Whitehousecca195c2006-09-05 13:15:18 -040096 return 0;
Ryan O'Hara639b6d72006-05-22 10:08:35 -040097 }
98}
99
David Teiglandb3b94fa2006-01-16 16:50:04 +0000100#endif /* __EATTR_DOT_H__ */