2 Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
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.
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.
23 #include <attr/xattr.h>
24 #elif HAVE_SYS_XATTR_H
25 #include <sys/xattr.h>
32 #ifdef HAVE_SYS_EXTATTR_H
33 #include <sys/extattr.h>
36 #ifdef HAVE_SOLARIS_ACLS
40 #include <atalk/vfs.h>
43 * This seems to be the current limit fo HFS+, we arbitrarily force that
44 * which also safes us from buffer overflows
46 #define MAX_EA_SIZE 3802
49 * At time of writing the 10.5.6 client adds 8 bytes to the
50 * length of the EA that we send him
52 #define MAX_REPLY_EXTRA_BYTES 8
55 * Library user must provide a static buffer of size ATTRNAMEBUFSIZ.
56 * It's used when listing EAs as intermediate buffer. For afpd it's
57 * defined in extattrs.c.
59 #define ATTRNAMEBUFSIZ 4096
67 #if !defined(HAVE_SETXATTR)
68 #define XATTR_CREATE 0x1 /* set value, fail if attr already exists */
69 #define XATTR_REPLACE 0x2 /* set value, fail if attr does not exist */
72 /* Names for our Extended Attributes adouble data */
73 #define AD_EA_META "org.netatalk.Metadata"
74 #define AD_EA_RESO "org.netatalk.ResourceFork"
76 /****************************************************************************************
77 * Wrappers for native EA functions taken from Samba
78 ****************************************************************************************/
79 ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size);
80 ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t size);
81 ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size);
82 ssize_t sys_listxattr (const char *path, char *list, size_t size);
83 ssize_t sys_llistxattr (const char *path, char *list, size_t size);
84 ssize_t sys_flistxattr (int filedes, char *list, size_t size);
85 int sys_removexattr (const char *path, const char *name);
86 int sys_lremovexattr (const char *path, const char *name);
87 int sys_fremovexattr (int filedes, const char *name);
88 int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags);
89 int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags);
90 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
91 int sys_copyxattr (const char *src, const char *dst);
93 /****************************************************************************************
94 * Stuff for our implementation of storing EAs in files in .AppleDouble dirs
95 ****************************************************************************************/
97 #define EA_INITED 0xea494e54 /* ea"INT", for interfacing ea_open w. ea_close */
98 #define EA_MAGIC 0x61644541 /* "adEA" */
99 #define EA_VERSION1 0x01
100 #define EA_VERSION EA_VERSION1
104 EA_CREATE = (1<<1), /* create if not existing on ea_open */
105 EA_RDONLY = (1<<2), /* open read only */
106 EA_RDWR = (1<<3), /* open read/write */
107 /* ea_open internal flags */
108 EA_DIR = (1<<4) /* ea header file is for a dir, ea_open adds it as appropiate */
111 #define EA_MAGIC_OFF 0
112 #define EA_MAGIC_LEN 4
113 #define EA_VERSION_OFF (EA_MAGIC_OFF + EA_MAGIC_LEN)
114 #define EA_VERSION_LEN 2
115 #define EA_COUNT_OFF (EA_VERSION_OFF + EA_VERSION_LEN)
116 #define EA_COUNT_LEN 2
117 #define EA_HEADER_SIZE (EA_MAGIC_LEN + EA_VERSION_LEN + EA_COUNT_LEN)
120 * structs describing the layout of the Extended Attributes bookkeeping file.
121 * This isn't really an AppleDouble structure, it's just a binary blob that
122 * lives in our .AppleDouble directory too.
126 size_t ea_namelen; /* len of ea_name without terminating 0 ie. strlen(ea_name)*/
127 size_t ea_size; /* size of EA*/
128 char *ea_name; /* name of the EA */
131 /* We read the on-disk data into *ea_data and parse it into this*/
133 uint32_t ea_inited; /* needed for interfacing ea_open w. ea_close */
134 const struct vol *vol; /* vol handle, ea_close needs it */
135 int dirfd; /* for *at (cf openat) semantics, -1 means ignore */
136 char *filename; /* name of file, needed by ea_close too */
137 unsigned int ea_count; /* number of EAs in ea_entries array */
138 struct ea_entry (*ea_entries)[]; /* malloced and realloced as needed by ea_count*/
139 int ea_fd; /* open fd for ea_data */
140 eaflags_t ea_flags; /* flags */
141 size_t ea_size; /* size of header file = size of ea_data buffer */
142 char *ea_data; /* pointer to buffer into that we actually *
143 * read the disc file into */
146 /* On-disk format, just for reference ! */
148 struct ea_entry_ondisk {
150 char ea_name[]; /* zero terminated string */
155 u_int16_t ea_version;
157 struct ea_entry_ondisk ea_entries[ea_count];
161 /* VFS inderected funcs ... : */
163 /* Default adouble EAs */
164 extern int get_easize(VFS_FUNC_ARGS_EA_GETSIZE);
165 extern int get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT);
166 extern int list_eas(VFS_FUNC_ARGS_EA_LIST);
167 extern int set_ea(VFS_FUNC_ARGS_EA_SET);
168 extern int remove_ea(VFS_FUNC_ARGS_EA_REMOVE);
169 /* ... EA VFS funcs that deal with file/dir cp/mv/rm */
170 extern int ea_deletefile(VFS_FUNC_ARGS_DELETEFILE);
171 extern int ea_renamefile(VFS_FUNC_ARGS_RENAMEFILE);
172 extern int ea_copyfile(VFS_FUNC_ARGS_COPYFILE);
173 extern int ea_chown(VFS_FUNC_ARGS_CHOWN);
174 extern int ea_chmod_file(VFS_FUNC_ARGS_SETFILEMODE);
175 extern int ea_chmod_dir(VFS_FUNC_ARGS_SETDIRUNIXMODE);
178 extern int sys_get_easize(VFS_FUNC_ARGS_EA_GETSIZE);
179 extern int sys_get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT);
180 extern int sys_list_eas(VFS_FUNC_ARGS_EA_LIST);
181 extern int sys_set_ea(VFS_FUNC_ARGS_EA_SET);
182 extern int sys_remove_ea(VFS_FUNC_ARGS_EA_REMOVE);
183 /* native EA VFSfile/dir cp/mv/rm */
184 extern int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE);
186 /* dbd needs access to these */
187 extern int ea_open(const struct vol * restrict vol,
188 const char * restrict uname,
190 struct ea * restrict ea);
191 extern int ea_openat(const struct vol * restrict vol,
193 const char * restrict uname,
195 struct ea * restrict ea);
196 extern int ea_close(struct ea * restrict ea);
197 extern char *ea_path(const struct ea * restrict ea, const char * restrict eaname, int macname);
199 #endif /* ATALK_EA_H */