s3: libsmb: Cleanup in get_dc_list()
[Samba.git] / source3 / lib / adouble.h
blob90a825c502e08f1325856e4a52d10d980992591d
1 /*
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/>.
20 #ifndef _ADOUBLE_H_
21 #define _ADOUBLE_H_
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
33 #else
34 #define AFPINFO_EA_NETATALK "user." NETATALK_META_XATTR
35 #define AFPRESOURCE_EA_NETATALK "user." NETATALK_RSRC_XATTR
36 #endif
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
45 * ._ files
47 typedef enum {ADOUBLE_META, ADOUBLE_RSRC} adouble_type_t;
49 /* Version info */
50 #define AD_VERSION2 0x00020000
51 #define AD_VERSION AD_VERSION2
54 * AppleDouble entry IDs.
56 #define ADEID_DFORK 1
57 #define ADEID_RFORK 2
58 #define ADEID_NAME 3
59 #define ADEID_COMMENT 4
60 #define ADEID_ICONBW 5
61 #define ADEID_ICONCOL 6
62 #define ADEID_FILEI 7
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
70 #define ADEID_DID 15
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
93 /* Field widths */
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_DID 4
105 #define ADEDLEN_PRIVDEV 8
106 #define ADEDLEN_PRIVINO 8
107 #define ADEDLEN_PRIVSYN 8
108 #define ADEDLEN_PRIVID 4
111 * Sharemode locks fcntl() offsets
113 #if _FILE_OFFSET_BITS == 64 || defined(HAVE_LARGEFILE)
114 #define AD_FILELOCK_BASE (UINT64_C(0x7FFFFFFFFFFFFFFF) - 9)
115 #else
116 #define AD_FILELOCK_BASE (UINT32_C(0x7FFFFFFF) - 9)
117 #endif
118 #define BYTELOCK_MAX (AD_FILELOCK_BASE - 1)
120 #define AD_FILELOCK_OPEN_WR (AD_FILELOCK_BASE + 0)
121 #define AD_FILELOCK_OPEN_RD (AD_FILELOCK_BASE + 1)
122 #define AD_FILELOCK_RSRC_OPEN_WR (AD_FILELOCK_BASE + 2)
123 #define AD_FILELOCK_RSRC_OPEN_RD (AD_FILELOCK_BASE + 3)
124 #define AD_FILELOCK_DENY_WR (AD_FILELOCK_BASE + 4)
125 #define AD_FILELOCK_DENY_RD (AD_FILELOCK_BASE + 5)
126 #define AD_FILELOCK_RSRC_DENY_WR (AD_FILELOCK_BASE + 6)
127 #define AD_FILELOCK_RSRC_DENY_RD (AD_FILELOCK_BASE + 7)
128 #define AD_FILELOCK_OPEN_NONE (AD_FILELOCK_BASE + 8)
129 #define AD_FILELOCK_RSRC_OPEN_NONE (AD_FILELOCK_BASE + 9)
131 /* Time stuff we overload the bits a little */
132 #define AD_DATE_CREATE 0
133 #define AD_DATE_MODIFY 4
134 #define AD_DATE_BACKUP 8
135 #define AD_DATE_ACCESS 12
136 #define AD_DATE_MASK (AD_DATE_CREATE | AD_DATE_MODIFY | \
137 AD_DATE_BACKUP | AD_DATE_ACCESS)
138 #define AD_DATE_UNIX (1 << 10)
139 #define AD_DATE_START 0x80000000
140 #define AD_DATE_DELTA 946684800
141 #define AD_DATE_FROM_UNIX(x) (htonl((x) - AD_DATE_DELTA))
142 #define AD_DATE_TO_UNIX(x) (ntohl(x) + AD_DATE_DELTA)
144 #define AD_CONV_WIPE_BLANK (1<<0)
145 #define AD_CONV_DELETE (1<<1)
147 struct adouble;
149 size_t ad_getentrylen(const struct adouble *ad, int eid);
150 size_t ad_getentryoff(const struct adouble *ad, int eid);
151 size_t ad_setentrylen(struct adouble *ad, int eid, size_t len);
152 size_t ad_setentryoff(struct adouble *ad, int eid, size_t off);
153 char *ad_get_entry(const struct adouble *ad, int eid);
154 int ad_getdate(const struct adouble *ad, unsigned int dateoff, uint32_t *date);
155 int ad_setdate(struct adouble *ad, unsigned int dateoff, uint32_t date);
156 int ad_convert(struct vfs_handle_struct *handle,
157 struct files_struct *dirfsp,
158 const struct smb_filename *smb_fname,
159 const char *catia_mappings,
160 uint32_t flags);
161 bool ad_unconvert(TALLOC_CTX *mem_ctx,
162 struct vfs_handle_struct *handle,
163 const char *catia_mappings,
164 struct smb_filename *smb_fname,
165 bool *converted);
166 struct adouble *ad_init(TALLOC_CTX *ctx, adouble_type_t type);
167 struct adouble *ad_get(TALLOC_CTX *ctx,
168 vfs_handle_struct *handle,
169 const struct smb_filename *smb_fname,
170 adouble_type_t type);
171 struct adouble *ad_fget(TALLOC_CTX *ctx, vfs_handle_struct *handle,
172 files_struct *fsp, adouble_type_t type);
173 int ad_set(vfs_handle_struct *handle,
174 struct adouble *ad,
175 const struct smb_filename *smb_fname);
176 int ad_fset(struct vfs_handle_struct *handle,
177 struct adouble *ad,
178 files_struct *fsp);
179 bool is_adouble_file(const char *path);
180 int adouble_path(TALLOC_CTX *ctx,
181 const struct smb_filename *smb_fname_in,
182 struct smb_filename **pp_smb_fname_out);
184 AfpInfo *afpinfo_new(TALLOC_CTX *ctx);
185 ssize_t afpinfo_pack(const AfpInfo *ai, char *buf);
186 AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx, const void *data);
188 #endif