btrfs-progs: convert: add support for converting reiserfs
[platform/upstream/btrfs-progs.git] / convert / source-reiserfs.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public
4  * License v2 as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9  * General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the
13  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14  * Boston, MA 021110-1307, USA.
15  */
16
17 #ifndef __BTRFS_CONVERT_SOURCE_REISERFS_H__
18 #define __BTRFS_CONVERT_SOURCE_REISERFS_H__
19
20 #if BTRFSCONVERT_REISERFS
21
22 #include "kerncompat.h"
23 #include <reiserfs/misc.h>
24 #include <reiserfs/io.h>
25 #include <reiserfs/reiserfs_lib.h>
26 #include <reiserfs/reiserfs_fs.h>
27 #include <linux/kdev_t.h>
28 #include "convert/source-fs.h"
29
30 #define REISERFS_ACL_VERSION    0x0001
31
32 /* 23.2.5 acl_tag_t values */
33
34 #define ACL_UNDEFINED_TAG       (0x00)
35 #define ACL_USER_OBJ            (0x01)
36 #define ACL_USER                (0x02)
37 #define ACL_GROUP_OBJ           (0x04)
38 #define ACL_GROUP               (0x08)
39 #define ACL_MASK                (0x10)
40 #define ACL_OTHER               (0x20)
41
42 /* 23.2.7 ACL qualifier constants */
43
44 #define ACL_UNDEFINED_ID        ((id_t)-1)
45
46 typedef struct {
47         __le16          e_tag;
48         __le16          e_perm;
49         __le32          e_id;
50 } ext2_acl_entry;
51
52 typedef struct {
53         __le16          e_tag;
54         __le16          e_perm;
55 } ext2_acl_entry_short;
56
57 typedef struct {
58         __le32          a_version;
59 } ext2_acl_header;
60
61 #define ACL_EA_VERSION          0x0002
62
63 typedef struct {
64         __le16          e_tag;
65         __le16          e_perm;
66         __le32          e_id;
67 } acl_ea_entry;
68
69 typedef struct {
70         __le32          a_version;
71         acl_ea_entry    a_entries[0];
72 } acl_ea_header;
73
74 static inline int ext2_acl_count(size_t size)
75 {
76         ssize_t s;
77         size -= sizeof(ext2_acl_header);
78         s = size - 4 * sizeof(ext2_acl_entry_short);
79         if (s < 0) {
80                 if (size % sizeof(ext2_acl_entry_short))
81                         return -1;
82                 return size / sizeof(ext2_acl_entry_short);
83         } else {
84                 if (s % sizeof(ext2_acl_entry))
85                         return -1;
86                 return s / sizeof(ext2_acl_entry) + 4;
87         }
88 }
89
90
91 static inline size_t acl_ea_size(int count)
92 {
93         return sizeof(acl_ea_header) + count * sizeof(acl_ea_entry);
94 }
95
96 static inline dev_t new_decode_dev(u32 dev)
97 {
98         unsigned major = (dev & 0xfff00) >> 8;
99         unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
100
101         return MKDEV(major, minor);
102 }
103
104 #endif  /* BTRFSCONVERT_REISERFS */
105
106 #endif