aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/struct-funcs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/struct-funcs.c')
-rw-r--r--fs/btrfs/struct-funcs.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/fs/btrfs/struct-funcs.c b/fs/btrfs/struct-funcs.c
new file mode 100644
index 000000000000..cf68fcf9b552
--- /dev/null
+++ b/fs/btrfs/struct-funcs.c
@@ -0,0 +1,97 @@
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
17 */
18
19#include <linux/highmem.h>
20#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
21u##bits btrfs_##name(struct extent_buffer *eb, \
22 type *s) \
23{ \
24 unsigned long offset = (unsigned long)s + \
25 offsetof(type, member); \
26 __le##bits *tmp; \
27 /* ugly, but we want the fast path here */ \
28 if (eb->map_token && offset >= eb->map_start && \
29 offset + sizeof(((type *)0)->member) <= eb->map_start + \
30 eb->map_len) { \
31 tmp = (__le##bits *)(eb->kaddr + offset - \
32 eb->map_start); \
33 return le##bits##_to_cpu(*tmp); \
34 } \
35 { \
36 int err; \
37 char *map_token; \
38 char *kaddr; \
39 int unmap_on_exit = (eb->map_token == NULL); \
40 unsigned long map_start; \
41 unsigned long map_len; \
42 __le##bits res; \
43 err = map_extent_buffer(eb, offset, \
44 sizeof(((type *)0)->member), \
45 &map_token, &kaddr, \
46 &map_start, &map_len, KM_USER1); \
47 if (err) { \
48 read_eb_member(eb, s, type, member, &res); \
49 return le##bits##_to_cpu(res); \
50 } \
51 tmp = (__le##bits *)(kaddr + offset - map_start); \
52 res = le##bits##_to_cpu(*tmp); \
53 if (unmap_on_exit) \
54 unmap_extent_buffer(eb, map_token, KM_USER1); \
55 return res; \
56 } \
57} \
58void btrfs_set_##name(struct extent_buffer *eb, \
59 type *s, u##bits val) \
60{ \
61 unsigned long offset = (unsigned long)s + \
62 offsetof(type, member); \
63 __le##bits *tmp; \
64 /* ugly, but we want the fast path here */ \
65 if (eb->map_token && offset >= eb->map_start && \
66 offset + sizeof(((type *)0)->member) <= eb->map_start + \
67 eb->map_len) { \
68 tmp = (__le##bits *)(eb->kaddr + offset - \
69 eb->map_start); \
70 *tmp = cpu_to_le##bits(val); \
71 return; \
72 } \
73 { \
74 int err; \
75 char *map_token; \
76 char *kaddr; \
77 int unmap_on_exit = (eb->map_token == NULL); \
78 unsigned long map_start; \
79 unsigned long map_len; \
80 err = map_extent_buffer(eb, offset, \
81 sizeof(((type *)0)->member), \
82 &map_token, &kaddr, \
83 &map_start, &map_len, KM_USER1); \
84 if (err) { \
85 val = cpu_to_le##bits(val); \
86 write_eb_member(eb, s, type, member, &val); \
87 return; \
88 } \
89 tmp = (__le##bits *)(kaddr + offset - map_start); \
90 *tmp = cpu_to_le##bits(val); \
91 if (unmap_on_exit) \
92 unmap_extent_buffer(eb, map_token, KM_USER1); \
93 } \
94}
95
96#include "ctree.h"
97