netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
ea.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13*/
14
15#ifndef ATALK_EA_H
16#define ATALK_EA_H
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#if HAVE_ATTR_XATTR_H
23#include <attr/xattr.h>
24#elif HAVE_SYS_XATTR_H
25#include <sys/xattr.h>
26#endif
27
28#ifdef HAVE_SYS_EA_H
29#include <sys/ea.h>
30#endif
31
32#ifdef HAVE_SYS_EXTATTR_H
33#include <sys/extattr.h>
34#endif
35
36#if defined(SOLARIS) && defined(HAVE_SYS_ATTR_H)
37#include <sys/attr.h>
38#endif
39
40#ifndef ENOATTR
41#define ENOATTR ENODATA
42#endif
43
44#include <atalk/vfs.h>
45
50#define MAX_EA_SIZE 3802
51
56#define MAX_REPLY_EXTRA_BYTES 6
57
63#define ATTRNAMEBUFSIZ 4096
64
65 enum {
66 kXAttrNoFollow = 0x1,
67 kXAttrCreate = 0x2,
68 kXAttrReplace = 0x4
69};
70
71#if !defined(HAVE_SETXATTR)
72#define XATTR_CREATE 0x1
73#define XATTR_REPLACE 0x2
74#endif
75
76#if defined(SOLARIS) && defined(HAVE_SYS_ATTR_H)
77#define SMB_ATTR_PREFIX "SUNWsmb:"
78#define SMB_ATTR_PREFIX_LEN (sizeof(SMB_ATTR_PREFIX) - 1)
79#endif
80
81/* Names for our Extended Attributes adouble data */
82#define AD_EA_META "org.netatalk.Metadata"
83#define AD_EA_META_LEN (sizeof(AD_EA_META) - 1)
84#ifdef __APPLE__
85#define AD_EA_RESO "com.apple.ResourceFork"
86#define EA_FINFO "com.apple.FinderInfo"
87#define NOT_NETATALK_EA(a) (strcmp((a), AD_EA_META) != 0) && (strcmp((a), AD_EA_RESO) != 0) && (strcmp((a), EA_FINFO) != 0)
88#else
89#define AD_EA_RESO "org.netatalk.ResourceFork"
90#define NOT_NETATALK_EA(a) (strcmp((a), AD_EA_META) != 0) && (strcmp((a), AD_EA_RESO) != 0)
91#endif
92
93/****************************************************************************************
94 * Wrappers for native EA functions taken from Samba
95 ****************************************************************************************/
96ssize_t sys_getxattr(const char *path, const char *name, void *value,
97 size_t size);
98ssize_t sys_lgetxattr(const char *path, const char *name, void *value,
99 size_t size);
100ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size);
101ssize_t sys_listxattr(const char *path, char *list, size_t size);
102ssize_t sys_llistxattr(const char *path, char *list, size_t size);
103#if 0
104ssize_t sys_flistxattr(int filedes, char *list, size_t size);
105#endif
106ssize_t sys_flistxattr(int filedes, const char *path, char *list, size_t size);
107 int sys_removexattr(const char *path, const char *name);
108 int sys_lremovexattr(const char *path, const char *name);
109#if 0
110 int sys_fremovexattr(int filedes, const char *name);
111#endif
112 int sys_fremovexattr(int filedes, const char *path, const char *name);
113 int sys_setxattr(const char *path, const char *name, const void *value,
114 size_t size, int flags);
115 int sys_lsetxattr(const char *path, const char *name, const void *value,
116 size_t size, int flags);
117 int sys_fsetxattr(int filedes, const char *name, const void *value, size_t size,
118 int flags);
119 int sys_copyxattr(const char *src, const char *dst);
120 int sys_getxattrfd(int fd, const char *uname, int oflag, ...);
121
122/****************************************************************************************
123 * Stuff for our implementation of storing EAs in files in .AppleDouble dirs
124 ****************************************************************************************/
125
126#define EA_INITED 0xea494e54
128#define EA_MAGIC 0x61644541
129#define EA_VERSION1 0x01
130#define EA_VERSION EA_VERSION1
131
132 typedef enum {
133 /* ea_open flags */
134 EA_CREATE = (1 << 1),
135 EA_RDONLY = (1 << 2),
136 EA_RDWR = (1 << 3),
137 /* ea_open internal flags */
138 EA_DIR = (1 << 4)
140} eaflags_t;
141
142#define EA_MAGIC_OFF 0
143#define EA_MAGIC_LEN 4
144#define EA_VERSION_OFF (EA_MAGIC_OFF + EA_MAGIC_LEN)
145#define EA_VERSION_LEN 2
146#define EA_COUNT_OFF (EA_VERSION_OFF + EA_VERSION_LEN)
147#define EA_COUNT_LEN 2
148#define EA_HEADER_SIZE (EA_MAGIC_LEN + EA_VERSION_LEN + EA_COUNT_LEN)
149
150/*
151 * structs describing the layout of the Extended Attributes bookkeeping file.
152 * This isn't really an AppleDouble structure, it's just a binary blob that
153 * lives in our .AppleDouble directory too.
154 */
155
156 struct ea_entry {
157 size_t ea_namelen;
159 size_t ea_size;
160 char *ea_name;
161};
162
163/* We read the on-disk data into *ea_data and parse it into this*/
164 struct ea {
165 uint32_t ea_inited;
167 const struct vol *vol;
168 int dirfd;
170 char *filename;
172 unsigned int ea_count;
173 struct ea_entry(*ea_entries)[];
175 int ea_fd;
176 eaflags_t ea_flags;
177 size_t ea_size;
179 char *ea_data;
181};
182
183/* On-disk format, just for reference ! */
184#if 0
185 struct ea_entry_ondisk {
186 uint32_t ea_size;
187 /* zero terminated string */
188 char ea_name[];
189};
190
191 struct ea_ondisk {
192 uint32_t ea_magic;
193 uint16_t ea_version;
194 uint16_t ea_count;
195 struct ea_entry_ondisk ea_entries[ea_count];
196};
197#endif /* 0 */
198
199/* VFS inderected funcs ... : */
200
201/* Default adouble EAs */
202 extern int get_easize(const struct vol *vol, char *rbuf, size_t *rbuflen,
203 const char *uname, int oflag, const char *attruname, int fd);
204 extern int get_eacontent(const struct vol *vol, char *rbuf, size_t *rbuflen,
205 const char *uname, int oflag, const char *attruname, int maxreply, int fd);
206 extern int list_eas(const struct vol *vol, char *attrnamebuf, size_t *buflen,
207 const char *uname, int oflag, int fd);
208 extern int set_ea(const struct vol *vol, const char *uname,
209 const char *attruname, const char *ibuf, size_t attrsize, int oflag, int fd);
210 extern int remove_ea(const struct vol *vol, const char *uname,
211 const char *attruname, int oflag, int fd);
212/* ... EA VFS funcs that deal with file/dir cp/mv/rm */
213 extern int ea_deletefile(const struct vol *vol, int dirfd, const char *file);
214 extern int ea_renamefile(const struct vol *vol, int dirfd, const char *src,
215 const char *dst);
216 extern int ea_copyfile(const struct vol *vol, int sfd, const char *src,
217 const char *dst);
218 extern int ea_chown(const struct vol *vol, const char *path, uid_t uid,
219 gid_t gid);
220 extern int ea_chmod_file(const struct vol *vol, const char *name, mode_t mode,
221 struct stat *st);
222 extern int ea_chmod_dir(const struct vol *vol, const char *name, mode_t mode,
223 struct stat *st);
224
225/* native EAs */
226 extern int sys_get_easize(const struct vol *vol, char *rbuf, size_t *rbuflen,
227 const char *uname, int oflag, const char *attruname, int fd);
228 extern int sys_get_eacontent(const struct vol *vol, char *rbuf, size_t *rbuflen,
229 const char *uname, int oflag, const char *attruname, int maxreply, int fd);
230 extern int sys_list_eas(const struct vol *vol, char *attrnamebuf,
231 size_t *buflen, const char *uname, int oflag, int fd);
232 extern int sys_set_ea(const struct vol *vol, const char *uname,
233 const char *attruname, const char *ibuf, size_t attrsize, int oflag, int fd);
234 extern int sys_remove_ea(const struct vol *vol, const char *uname,
235 const char *attruname, int oflag, int fd);
236/* native EA VFSfile/dir cp/mv/rm */
237 extern int sys_ea_copyfile(const struct vol *vol, int sfd, const char *src,
238 const char *dst);
239
240/* dbd needs access to these */
241 extern int ea_open(const struct vol *vol,
242 const char *uname,
243 eaflags_t eaflags,
244 struct ea *ea);
245 extern int ea_openat(const struct vol *vol,
246 int dirfd,
247 const char *uname,
248 eaflags_t eaflags,
249 struct ea *ea);
250 extern int ea_close(struct ea *ea);
251 extern char *ea_path(const struct ea *ea, const char *eaname, int macname);
252
253#endif /* ATALK_EA_H */
rbuflen
static size_t rbuflen
Definition afpfunc_helpers.c:45
rbuf
static char rbuf[rbufsize]
Definition afpfunc_helpers.c:44
flags
static dbd_flags_t flags
Definition cmd_dbd.c:43
config.h
sys_lsetxattr
int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
Definition extattr.c:756
sys_set_ea
int sys_set_ea(const struct vol *vol, const char *uname, const char *attruname, const char *ibuf, size_t attrsize, int oflag, int fd)
set a native EA
Definition ea_sys.c:403
sys_flistxattr
ssize_t sys_flistxattr(int filedes, const char *path, char *list, size_t size)
Definition extattr.c:468
sys_listxattr
ssize_t sys_listxattr(const char *path, char *list, size_t size)
Definition extattr.c:435
sys_fsetxattr
int sys_fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags)
Definition extattr.c:688
sys_getxattr
ssize_t sys_getxattr(const char *path, const char *name, void *value, size_t size)
Definition extattr.c:120
ea_chown
int ea_chown(const struct vol *vol, const char *path, uid_t uid, gid_t gid)
Definition ea_ad.c:1567
sys_setxattr
int sys_setxattr(const char *path, const char *name, const void *value, size_t size, int flags)
Definition extattr.c:623
list_eas
int list_eas(const struct vol *vol, char *attrnamebuf, size_t *buflen, const char *uname, int oflag, int fd)
copy names of EAs into attrnamebuf
Definition ea_ad.c:1114
sys_list_eas
int sys_list_eas(const struct vol *vol, char *attrnamebuf, size_t *buflen, const char *uname, int oflag, int fd)
copy names of native EAs into attrnamebuf
Definition ea_sys.c:307
ea_open
int ea_open(const struct vol *vol, const char *uname, eaflags_t eaflags, struct ea *ea)
open EA header file, create if it doesnt exits and called with O_CREATE
Definition ea_ad.c:614
sys_llistxattr
ssize_t sys_llistxattr(const char *path, char *list, size_t size)
Definition extattr.c:502
sys_getxattrfd
int sys_getxattrfd(int fd, const char *uname, int oflag,...)
Definition extattr.c:94
ea_close
int ea_close(struct ea *ea)
flushes and closes an ea handle
Definition ea_ad.c:830
remove_ea
int remove_ea(const struct vol *vol, const char *uname, const char *attruname, int oflag, int fd)
remove a EA from a file
Definition ea_ad.c:1249
set_ea
int set_ea(const struct vol *vol, const char *uname, const char *attruname, const char *ibuf, size_t attrsize, int oflag, int fd)
set a Solaris native EA
Definition ea_ad.c:1197
sys_lgetxattr
ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
Definition extattr.c:250
sys_get_eacontent
int sys_get_eacontent(const struct vol *vol, char *rbuf, size_t *rbuflen, const char *uname, int oflag, const char *attruname, int maxreply, int fd)
copy native EA into rbuf
Definition ea_sys.c:168
ea_chmod_file
int ea_chmod_file(const struct vol *vol, const char *name, mode_t mode, struct stat *st)
Definition ea_ad.c:1632
kXAttrReplace
@ kXAttrReplace
Definition ea.h:68
kXAttrCreate
@ kXAttrCreate
Definition ea.h:67
kXAttrNoFollow
@ kXAttrNoFollow
Definition ea.h:66
sys_lremovexattr
int sys_lremovexattr(const char *path, const char *name)
Definition extattr.c:595
sys_get_easize
int sys_get_easize(const struct vol *vol, char *rbuf, size_t *rbuflen, const char *uname, int oflag, const char *attruname, int fd)
get size of a native EA
Definition ea_sys.c:69
ea_path
char * ea_path(const struct ea *ea, const char *eaname, int macname)
return name of ea header filename
Definition ea_ad.c:561
sys_copyxattr
int sys_copyxattr(const char *src, const char *dst)
sys_remove_ea
int sys_remove_ea(const struct vol *vol, const char *uname, const char *attruname, int oflag, int fd)
remove a native EA
Definition ea_sys.c:523
sys_ea_copyfile
int sys_ea_copyfile(const struct vol *vol, int sfd, const char *src, const char *dst)
copy EAs
Definition ea_sys.c:596
sys_fgetxattr
ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
Definition extattr.c:187
sys_removexattr
int sys_removexattr(const char *path, const char *name)
Definition extattr.c:535
sys_fremovexattr
int sys_fremovexattr(int filedes, const char *path, const char *name)
Definition extattr.c:565
ea_deletefile
int ea_deletefile(const struct vol *vol, int dirfd, const char *file)
Definition ea_ad.c:1293
get_eacontent
int get_eacontent(const struct vol *vol, char *rbuf, size_t *rbuflen, const char *uname, int oflag, const char *attruname, int maxreply, int fd)
copy EA into rbuf
Definition ea_ad.c:1014
ea_openat
int ea_openat(const struct vol *vol, int dirfd, const char *uname, eaflags_t eaflags, struct ea *ea)
openat like wrapper for ea_open, takes a additional file descriptor
Definition ea_ad.c:785
ea_renamefile
int ea_renamefile(const struct vol *vol, int dirfd, const char *src, const char *dst)
Definition ea_ad.c:1353
eaflags_t
eaflags_t
Definition ea.h:132
EA_RDONLY
@ EA_RDONLY
Definition ea.h:135
EA_CREATE
@ EA_CREATE
Definition ea.h:134
EA_RDWR
@ EA_RDWR
Definition ea.h:136
EA_DIR
@ EA_DIR
Definition ea.h:138
ea_copyfile
int ea_copyfile(const struct vol *vol, int sfd, const char *src, const char *dst)
copy EAs
Definition ea_ad.c:1471
ea_chmod_dir
int ea_chmod_dir(const struct vol *vol, const char *name, mode_t mode, struct stat *st)
Definition ea_ad.c:1706
get_easize
int get_easize(const struct vol *vol, char *rbuf, size_t *rbuflen, const char *uname, int oflag, const char *attruname, int fd)
get size of an EA
Definition ea_ad.c:949
ea_entry
Definition ea.h:156
ea_entry::ea_name
char * ea_name
Definition ea.h:160
ea_entry::ea_namelen
size_t ea_namelen
Definition ea.h:157
ea_entry::ea_size
size_t ea_size
Definition ea.h:159
ea
Definition ea.h:164
ea::ea_flags
eaflags_t ea_flags
Definition ea.h:176
ea::filename
char * filename
Definition ea.h:170
ea::dirfd
int dirfd
Definition ea.h:168
ea::ea_size
size_t ea_size
Definition ea.h:177
ea::ea_data
char * ea_data
Definition ea.h:179
ea::ea_count
unsigned int ea_count
Definition ea.h:172
ea::ea_fd
int ea_fd
Definition ea.h:175
ea::ea_inited
uint32_t ea_inited
Definition ea.h:165
ea::vol
const struct vol * vol
Definition ea.h:167
ea::ea_entries
struct ea_entry(* ea_entries)[]
Definition ea.h:173
list
Definition etc/atalkd/list.h:6
path
Definition include/atalk/directory.h:123
vol
Definition include/atalk/volume.h:33
vfs.h