diff options
author | David Howells <dhowells@redhat.com> | 2018-04-06 09:17:25 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2018-04-09 16:54:48 -0400 |
commit | 4ea219a839bf85cf774299e2f817e609ba7ef331 (patch) | |
tree | f00eade2eda7690143b1a7b26bd845b69a858491 /fs | |
parent | f3ddee8dc4e2cff37936afbeed2fdaa95b7fb7c6 (diff) |
afs: Split the directory content defs into a header
Split the directory content definitions into a header file so that they can
be used by multiple .c files.
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/afs/dir.c | 56 | ||||
-rw-r--r-- | fs/afs/xdr_fs.h | 63 |
2 files changed, 67 insertions, 52 deletions
diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 8beecbcd9679..a2422fbcbf72 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/sched.h> | 18 | #include <linux/sched.h> |
19 | #include <linux/task_io_accounting_ops.h> | 19 | #include <linux/task_io_accounting_ops.h> |
20 | #include "internal.h" | 20 | #include "internal.h" |
21 | #include "xdr_fs.h" | ||
21 | 22 | ||
22 | static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry, | 23 | static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry, |
23 | unsigned int flags); | 24 | unsigned int flags); |
@@ -86,55 +87,6 @@ const struct dentry_operations afs_fs_dentry_operations = { | |||
86 | .d_automount = afs_d_automount, | 87 | .d_automount = afs_d_automount, |
87 | }; | 88 | }; |
88 | 89 | ||
89 | #define AFS_DIR_HASHTBL_SIZE 128 | ||
90 | #define AFS_DIR_DIRENT_SIZE 32 | ||
91 | #define AFS_DIRENT_PER_BLOCK 64 | ||
92 | |||
93 | union afs_dirent { | ||
94 | struct { | ||
95 | uint8_t valid; | ||
96 | uint8_t unused[1]; | ||
97 | __be16 hash_next; | ||
98 | __be32 vnode; | ||
99 | __be32 unique; | ||
100 | uint8_t name[16]; | ||
101 | uint8_t overflow[4]; /* if any char of the name (inc | ||
102 | * NUL) reaches here, consume | ||
103 | * the next dirent too */ | ||
104 | } u; | ||
105 | uint8_t extended_name[32]; | ||
106 | }; | ||
107 | |||
108 | /* AFS directory page header (one at the beginning of every 2048-byte chunk) */ | ||
109 | struct afs_dir_pagehdr { | ||
110 | __be16 npages; | ||
111 | __be16 magic; | ||
112 | #define AFS_DIR_MAGIC htons(1234) | ||
113 | uint8_t nentries; | ||
114 | uint8_t bitmap[8]; | ||
115 | uint8_t pad[19]; | ||
116 | }; | ||
117 | |||
118 | /* directory block layout */ | ||
119 | union afs_dir_block { | ||
120 | |||
121 | struct afs_dir_pagehdr pagehdr; | ||
122 | |||
123 | struct { | ||
124 | struct afs_dir_pagehdr pagehdr; | ||
125 | uint8_t alloc_ctrs[128]; | ||
126 | /* dir hash table */ | ||
127 | uint16_t hashtable[AFS_DIR_HASHTBL_SIZE]; | ||
128 | } hdr; | ||
129 | |||
130 | union afs_dirent dirents[AFS_DIRENT_PER_BLOCK]; | ||
131 | }; | ||
132 | |||
133 | /* layout on a linux VM page */ | ||
134 | struct afs_dir_page { | ||
135 | union afs_dir_block blocks[PAGE_SIZE / sizeof(union afs_dir_block)]; | ||
136 | }; | ||
137 | |||
138 | struct afs_lookup_one_cookie { | 90 | struct afs_lookup_one_cookie { |
139 | struct dir_context ctx; | 91 | struct dir_context ctx; |
140 | struct qstr name; | 92 | struct qstr name; |
@@ -371,8 +323,8 @@ static int afs_dir_iterate_block(struct dir_context *ctx, | |||
371 | curr = (ctx->pos - blkoff) / sizeof(union afs_dirent); | 323 | curr = (ctx->pos - blkoff) / sizeof(union afs_dirent); |
372 | 324 | ||
373 | /* walk through the block, an entry at a time */ | 325 | /* walk through the block, an entry at a time */ |
374 | for (offset = AFS_DIRENT_PER_BLOCK - block->pagehdr.nentries; | 326 | for (offset = (blkoff == 0 ? AFS_DIR_RESV_BLOCKS0 : AFS_DIR_RESV_BLOCKS); |
375 | offset < AFS_DIRENT_PER_BLOCK; | 327 | offset < AFS_DIR_SLOTS_PER_BLOCK; |
376 | offset = next | 328 | offset = next |
377 | ) { | 329 | ) { |
378 | next = offset + 1; | 330 | next = offset + 1; |
@@ -401,7 +353,7 @@ static int afs_dir_iterate_block(struct dir_context *ctx, | |||
401 | 353 | ||
402 | /* work out where the next possible entry is */ | 354 | /* work out where the next possible entry is */ |
403 | for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_dirent)) { | 355 | for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_dirent)) { |
404 | if (next >= AFS_DIRENT_PER_BLOCK) { | 356 | if (next >= AFS_DIR_SLOTS_PER_BLOCK) { |
405 | _debug("ENT[%zu.%u]:" | 357 | _debug("ENT[%zu.%u]:" |
406 | " %u travelled beyond end dir block" | 358 | " %u travelled beyond end dir block" |
407 | " (len %u/%zu)", | 359 | " (len %u/%zu)", |
diff --git a/fs/afs/xdr_fs.h b/fs/afs/xdr_fs.h index 24e23e40c979..63e87ccbb55b 100644 --- a/fs/afs/xdr_fs.h +++ b/fs/afs/xdr_fs.h | |||
@@ -37,4 +37,67 @@ struct afs_xdr_AFSFetchStatus { | |||
37 | __be32 abort_code; | 37 | __be32 abort_code; |
38 | } __packed; | 38 | } __packed; |
39 | 39 | ||
40 | #define AFS_DIR_HASHTBL_SIZE 128 | ||
41 | #define AFS_DIR_DIRENT_SIZE 32 | ||
42 | #define AFS_DIR_SLOTS_PER_BLOCK 64 | ||
43 | #define AFS_DIR_BLOCK_SIZE 2048 | ||
44 | #define AFS_DIR_BLOCKS_PER_PAGE (PAGE_SIZE / AFS_DIR_BLOCK_SIZE) | ||
45 | #define AFS_DIR_MAX_SLOTS 65536 | ||
46 | #define AFS_DIR_BLOCKS_WITH_CTR 128 | ||
47 | #define AFS_DIR_MAX_BLOCKS 1023 | ||
48 | #define AFS_DIR_RESV_BLOCKS 1 | ||
49 | #define AFS_DIR_RESV_BLOCKS0 13 | ||
50 | |||
51 | /* | ||
52 | * Directory entry structure. | ||
53 | */ | ||
54 | union afs_dirent { | ||
55 | struct { | ||
56 | uint8_t valid; | ||
57 | uint8_t unused[1]; | ||
58 | __be16 hash_next; | ||
59 | __be32 vnode; | ||
60 | __be32 unique; | ||
61 | uint8_t name[16]; | ||
62 | uint8_t overflow[4]; /* if any char of the name (inc | ||
63 | * NUL) reaches here, consume | ||
64 | * the next dirent too */ | ||
65 | } u; | ||
66 | uint8_t extended_name[32]; | ||
67 | }; | ||
68 | |||
69 | /* | ||
70 | * Directory page header (one at the beginning of every 2048-byte chunk). | ||
71 | */ | ||
72 | struct afs_dir_pagehdr { | ||
73 | __be16 npages; | ||
74 | __be16 magic; | ||
75 | #define AFS_DIR_MAGIC htons(1234) | ||
76 | uint8_t reserved; | ||
77 | uint8_t bitmap[8]; | ||
78 | uint8_t pad[19]; | ||
79 | }; | ||
80 | |||
81 | /* | ||
82 | * Directory block layout | ||
83 | */ | ||
84 | union afs_dir_block { | ||
85 | struct afs_dir_pagehdr pagehdr; | ||
86 | |||
87 | struct { | ||
88 | struct afs_dir_pagehdr pagehdr; | ||
89 | uint8_t alloc_ctrs[AFS_DIR_MAX_BLOCKS]; | ||
90 | __be16 hashtable[AFS_DIR_HASHTBL_SIZE]; | ||
91 | } hdr; | ||
92 | |||
93 | union afs_dirent dirents[AFS_DIR_SLOTS_PER_BLOCK]; | ||
94 | }; | ||
95 | |||
96 | /* | ||
97 | * Directory layout on a linux VM page. | ||
98 | */ | ||
99 | struct afs_dir_page { | ||
100 | union afs_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE]; | ||
101 | }; | ||
102 | |||
40 | #endif /* XDR_FS_H */ | 103 | #endif /* XDR_FS_H */ |