~ubuntu-branches/ubuntu/wily/xfsprogs/wily

« back to all changes in this revision

Viewing changes to include/xfs_dir_leaf.h

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-08-08 13:49:19 UTC
  • mfrom: (21.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140808134919-lif3mgdkuizl95yo
Tags: 3.2.1ubuntu1
Patch m4/libtool.m4 for powerpc64le and regenerate configure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3
 
 * All Rights Reserved.
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU General Public License as
7
 
 * published by the Free Software Foundation.
8
 
 *
9
 
 * 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.
13
 
 *
14
 
 * 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
17
 
 */
18
 
#ifndef __XFS_DIR_LEAF_H__
19
 
#define __XFS_DIR_LEAF_H__
20
 
 
21
 
/*
22
 
 * Version 1 Directory layout, internal structure, access macros, etc.
23
 
 * to allow various xfsprogs tools to read these structures.
24
 
 *
25
 
 * Large directories are structured around Btrees where all the data
26
 
 * elements are in the leaf nodes.  Filenames are hashed into an int,
27
 
 * then that int is used as the index into the Btree.  Since the hashval
28
 
 * of a filename may not be unique, we may have duplicate keys.  The
29
 
 * internal links in the Btree are logical block offsets into the file.
30
 
 */
31
 
 
32
 
/*========================================================================
33
 
 * Directory Structure when equal to XFS_LBSIZE(mp) bytes.
34
 
 *========================================================================*/
35
 
 
36
 
/*
37
 
 * This is the structure of the leaf nodes in the Btree.
38
 
 *
39
 
 * Struct leaf_entry's are packed from the top.  Names grow from the bottom
40
 
 * but are not packed.  The freemap contains run-length-encoded entries
41
 
 * for the free bytes after the leaf_entry's, but only the N largest such,
42
 
 * smaller runs are dropped.  When the freemap doesn't show enough space
43
 
 * for an allocation, we compact the namelist area and try again.  If we
44
 
 * still don't have enough space, then we have to split the block.
45
 
 *
46
 
 * Since we have duplicate hash keys, for each key that matches, compare
47
 
 * the actual string.  The root and intermediate node search always takes
48
 
 * the first-in-the-block key match found, so we should only have to work
49
 
 * "forw"ard.  If none matches, continue with the "forw"ard leaf nodes
50
 
 * until the hash key changes or the filename is found.
51
 
 *
52
 
 * The parent directory and the self-pointer are explicitly represented
53
 
 * (ie: there are entries for "." and "..").
54
 
 *
55
 
 * Note that the count being a __uint16_t limits us to something like a
56
 
 * blocksize of 1.3MB in the face of worst case (short) filenames.
57
 
 */
58
 
 
59
 
#define XFS_DIR_LEAF_MAGIC      0xfeeb
60
 
 
61
 
#define XFS_DIR_LEAF_MAPSIZE    3       /* how many freespace slots */
62
 
 
63
 
 
64
 
typedef struct xfs_dir_leaf_map {       /* RLE map of free bytes */
65
 
        __be16          base;           /* base of free region */
66
 
        __be16          size;           /* run length of free region */
67
 
} xfs_dir_leaf_map_t;
68
 
 
69
 
typedef struct xfs_dir_leaf_hdr {       /* constant-structure header block */
70
 
        xfs_da_blkinfo_t info;          /* block type, links, etc. */
71
 
        __be16          count;          /* count of active leaf_entry's */
72
 
        __be16          namebytes;      /* num bytes of name strings stored */
73
 
        __be16          firstused;      /* first used byte in name area */
74
 
        __u8            holes;          /* != 0 if blk needs compaction */
75
 
        __u8            pad1;
76
 
        xfs_dir_leaf_map_t freemap[XFS_DIR_LEAF_MAPSIZE];
77
 
} xfs_dir_leaf_hdr_t;
78
 
 
79
 
typedef struct xfs_dir_leaf_entry {     /* sorted on key, not name */
80
 
        __be32          hashval;        /* hash value of name */
81
 
        __be16          nameidx;        /* index into buffer of name */
82
 
        __u8            namelen;        /* length of name string */
83
 
        __u8            pad2;
84
 
} xfs_dir_leaf_entry_t;
85
 
 
86
 
typedef struct xfs_dir_leaf_name {
87
 
        xfs_dir_ino_t   inumber;        /* inode number for this key */
88
 
        __u8            name[1];        /* name string itself */
89
 
} xfs_dir_leaf_name_t;
90
 
 
91
 
typedef struct xfs_dir_leafblock {
92
 
        xfs_dir_leaf_hdr_t      hdr;    /* constant-structure header block */
93
 
        xfs_dir_leaf_entry_t    entries[1];     /* var sized array */
94
 
        xfs_dir_leaf_name_t     namelist[1];    /* grows from bottom of buf */
95
 
} xfs_dir_leafblock_t;
96
 
 
97
 
static inline int xfs_dir_leaf_entsize_byname(int len)
98
 
{
99
 
        return (uint)sizeof(xfs_dir_leaf_name_t)-1 + len;
100
 
}
101
 
 
102
 
static inline int xfs_dir_leaf_entsize_byentry(xfs_dir_leaf_entry_t *entry)
103
 
{
104
 
        return (uint)sizeof(xfs_dir_leaf_name_t)-1 + (entry)->namelen;
105
 
}
106
 
 
107
 
static inline xfs_dir_leaf_name_t *
108
 
xfs_dir_leaf_namestruct(xfs_dir_leafblock_t *leafp, int offset)
109
 
{
110
 
        return (xfs_dir_leaf_name_t *)&((char *)(leafp))[offset];
111
 
}
112
 
 
113
 
#endif /* __XFS_DIR_LEAF_H__ */