2 * Samba AppleDouble helpers
4 * Copyright (C) Ralph Boehme, 2019
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "MacExtensions.h"
25 #define ADOUBLE_NAME_PREFIX "._"
27 #define NETATALK_META_XATTR "org.netatalk.Metadata"
28 #define NETATALK_RSRC_XATTR "org.netatalk.ResourceFork"
30 #if defined(HAVE_ATTROPEN)
31 #define AFPINFO_EA_NETATALK NETATALK_META_XATTR
32 #define AFPRESOURCE_EA_NETATALK NETATALK_RSRC_XATTR
34 #define AFPINFO_EA_NETATALK "user." NETATALK_META_XATTR
35 #define AFPRESOURCE_EA_NETATALK "user." NETATALK_RSRC_XATTR
39 * There are two AppleDouble blobs we deal with:
41 * - ADOUBLE_META - AppleDouble blob used by Netatalk for storing
42 * metadata in an xattr
44 * - ADOUBLE_RSRC - AppleDouble blob used by OS X and Netatalk in
47 typedef enum {ADOUBLE_META
, ADOUBLE_RSRC
} adouble_type_t
;
50 #define AD_VERSION2 0x00020000
51 #define AD_VERSION AD_VERSION2
54 * AppleDouble entry IDs.
59 #define ADEID_COMMENT 4
60 #define ADEID_ICONBW 5
61 #define ADEID_ICONCOL 6
63 #define ADEID_FILEDATESI 8
64 #define ADEID_FINDERI 9
65 #define ADEID_MACFILEI 10
66 #define ADEID_PRODOSFILEI 11
67 #define ADEID_MSDOSFILEI 12
68 #define ADEID_SHORTNAME 13
69 #define ADEID_AFPFILEI 14
72 /* Private Netatalk entries */
73 #define ADEID_PRIVDEV 16
74 #define ADEID_PRIVINO 17
75 #define ADEID_PRIVSYN 18
76 #define ADEID_PRIVID 19
77 #define ADEID_MAX (ADEID_PRIVID + 1)
80 * These are the real ids for the private entries,
81 * as stored in the adouble file
83 #define AD_DEV 0x80444556
84 #define AD_INO 0x80494E4F
85 #define AD_SYN 0x8053594E
86 #define AD_ID 0x8053567E
88 /* AppleDouble magic */
89 #define AD_APPLESINGLE_MAGIC 0x00051600
90 #define AD_APPLEDOUBLE_MAGIC 0x00051607
91 #define AD_MAGIC AD_APPLEDOUBLE_MAGIC
94 #define ADEDLEN_NAME 255
95 #define ADEDLEN_COMMENT 200
96 #define ADEDLEN_FILEI 16
97 #define ADEDLEN_FINDERI 32
98 #define ADEDLEN_FILEDATESI 16
99 #define ADEDLEN_SHORTNAME 12 /* length up to 8.3 */
100 #define ADEDLEN_AFPFILEI 4
101 #define ADEDLEN_MACFILEI 4
102 #define ADEDLEN_PRODOSFILEI 8
103 #define ADEDLEN_MSDOSFILEI 2
104 #define ADEDLEN_ICONBW 128
105 #define ADEDLEN_ICONCOL 1024
106 #define ADEDLEN_DID 4
107 #define ADEDLEN_PRIVDEV 8
108 #define ADEDLEN_PRIVINO 8
109 #define ADEDLEN_PRIVSYN 8
110 #define ADEDLEN_PRIVID 4
113 * Sharemode locks fcntl() offsets
115 #if _FILE_OFFSET_BITS == 64 || defined(HAVE_LARGEFILE)
116 #define AD_FILELOCK_BASE (UINT64_C(0x7FFFFFFFFFFFFFFF) - 9)
118 #define AD_FILELOCK_BASE (UINT32_C(0x7FFFFFFF) - 9)
120 #define BYTELOCK_MAX (AD_FILELOCK_BASE - 1)
122 #define AD_FILELOCK_OPEN_WR (AD_FILELOCK_BASE + 0)
123 #define AD_FILELOCK_OPEN_RD (AD_FILELOCK_BASE + 1)
124 #define AD_FILELOCK_RSRC_OPEN_WR (AD_FILELOCK_BASE + 2)
125 #define AD_FILELOCK_RSRC_OPEN_RD (AD_FILELOCK_BASE + 3)
126 #define AD_FILELOCK_DENY_WR (AD_FILELOCK_BASE + 4)
127 #define AD_FILELOCK_DENY_RD (AD_FILELOCK_BASE + 5)
128 #define AD_FILELOCK_RSRC_DENY_WR (AD_FILELOCK_BASE + 6)
129 #define AD_FILELOCK_RSRC_DENY_RD (AD_FILELOCK_BASE + 7)
130 #define AD_FILELOCK_OPEN_NONE (AD_FILELOCK_BASE + 8)
131 #define AD_FILELOCK_RSRC_OPEN_NONE (AD_FILELOCK_BASE + 9)
133 /* Time stuff we overload the bits a little */
134 #define AD_DATE_CREATE 0
135 #define AD_DATE_MODIFY 4
136 #define AD_DATE_BACKUP 8
137 #define AD_DATE_ACCESS 12
138 #define AD_DATE_MASK (AD_DATE_CREATE | AD_DATE_MODIFY | \
139 AD_DATE_BACKUP | AD_DATE_ACCESS)
140 #define AD_DATE_UNIX (1 << 10)
141 #define AD_DATE_START 0x80000000
142 #define AD_DATE_DELTA 946684800
143 #define AD_DATE_FROM_UNIX(x) (htonl((x) - AD_DATE_DELTA))
144 #define AD_DATE_TO_UNIX(x) (ntohl(x) + AD_DATE_DELTA)
146 #define AD_CONV_WIPE_BLANK (1<<0)
147 #define AD_CONV_DELETE (1<<1)
151 size_t ad_getentrylen(const struct adouble
*ad
, int eid
);
152 size_t ad_getentryoff(const struct adouble
*ad
, int eid
);
153 size_t ad_setentrylen(struct adouble
*ad
, int eid
, size_t len
);
154 size_t ad_setentryoff(struct adouble
*ad
, int eid
, size_t off
);
155 char *ad_get_entry(const struct adouble
*ad
, int eid
);
156 int ad_getdate(const struct adouble
*ad
, unsigned int dateoff
, uint32_t *date
);
157 int ad_setdate(struct adouble
*ad
, unsigned int dateoff
, uint32_t date
);
158 int ad_convert(struct vfs_handle_struct
*handle
,
159 const struct smb_filename
*smb_fname
,
160 const char *catia_mappings
,
162 bool ad_unconvert(TALLOC_CTX
*mem_ctx
,
163 struct vfs_handle_struct
*handle
,
164 const char *catia_mappings
,
165 struct smb_filename
*smb_fname
,
167 struct adouble
*ad_init(TALLOC_CTX
*ctx
, adouble_type_t type
);
168 NTSTATUS
adouble_open_from_base_fsp(const struct files_struct
*dirfsp
,
169 struct files_struct
*base_fsp
,
173 struct files_struct
**_ad_fsp
);
174 struct adouble
*ad_get(TALLOC_CTX
*ctx
,
175 vfs_handle_struct
*handle
,
176 const struct smb_filename
*smb_fname
,
177 adouble_type_t type
);
178 struct adouble
*ad_fget(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
179 files_struct
*fsp
, adouble_type_t type
);
180 int ad_fset(struct vfs_handle_struct
*handle
,
183 bool is_adouble_file(const char *path
);
184 int adouble_path(TALLOC_CTX
*ctx
,
185 const struct smb_filename
*smb_fname_in
,
186 struct smb_filename
**pp_smb_fname_out
);
188 AfpInfo
*afpinfo_new(TALLOC_CTX
*ctx
);
189 ssize_t
afpinfo_pack(const AfpInfo
*ai
, char *buf
);
190 AfpInfo
*afpinfo_unpack(TALLOC_CTX
*ctx
, const void *data
);