blob: 919756e3ba53591a9132849a6dc7c57771f1aebb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_ATTR_SF_H__
19#define __XFS_ATTR_SF_H__
20
21/*
22 * Attribute storage when stored inside the inode.
23 *
24 * Small attribute lists are packed as tightly as possible so as
25 * to fit into the literal area of the inode.
26 */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/*
29 * Entries are packed toward the top as tight as possible.
30 */
31typedef struct xfs_attr_shortform {
32 struct xfs_attr_sf_hdr { /* constant-structure header block */
Nathan Scott3b244aa2006-03-17 17:29:25 +110033 __be16 totsize; /* total bytes in shortform list */
34 __u8 count; /* count of active entries */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 } hdr;
36 struct xfs_attr_sf_entry {
37 __uint8_t namelen; /* actual length of name (no NULL) */
38 __uint8_t valuelen; /* actual length of value (no NULL) */
39 __uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */
40 __uint8_t nameval[1]; /* name & value bytes concatenated */
41 } list[1]; /* variable sized array */
42} xfs_attr_shortform_t;
43typedef struct xfs_attr_sf_hdr xfs_attr_sf_hdr_t;
44typedef struct xfs_attr_sf_entry xfs_attr_sf_entry_t;
45
46/*
47 * We generate this then sort it, attr_list() must return things in hash-order.
48 */
49typedef struct xfs_attr_sf_sort {
50 __uint8_t entno; /* entry number in original list */
51 __uint8_t namelen; /* length of name value (no null) */
52 __uint8_t valuelen; /* length of value */
53 __uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */
54 xfs_dahash_t hash; /* this entry's hash value */
Dave Chinnera9273ca2010-01-20 10:47:48 +110055 unsigned char *name; /* name value, pointer into buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056} xfs_attr_sf_sort_t;
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define XFS_ATTR_SF_ENTSIZE_BYNAME(nlen,vlen) /* space name/value uses */ \
Nathan Scotta844f452005-11-02 14:38:42 +110059 (((int)sizeof(xfs_attr_sf_entry_t)-1 + (nlen)+(vlen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \
61 ((1 << (NBBY*(int)sizeof(__uint8_t))) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define XFS_ATTR_SF_ENTSIZE(sfep) /* space an entry uses */ \
63 ((int)sizeof(xfs_attr_sf_entry_t)-1 + (sfep)->namelen+(sfep)->valuelen)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \
Nathan Scotta844f452005-11-02 14:38:42 +110065 ((xfs_attr_sf_entry_t *)((char *)(sfep) + XFS_ATTR_SF_ENTSIZE(sfep)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \
Nathan Scott3b244aa2006-03-17 17:29:25 +110067 (be16_to_cpu(((xfs_attr_shortform_t *) \
68 ((dp)->i_afp->if_u1.if_data))->hdr.totsize))
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#endif /* __XFS_ATTR_SF_H__ */