netatalk  4.4.0dev
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 <[email protected]>
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
46/*
47 * This seems to be the current limit fo HFS+, we arbitrarily force that
48 * which also safes us from buffer overflows
49 */
50#define MAX_EA_SIZE 3802
51
52/*
53 * req_count has space for AFP response bitmap and length as well, so
54 * 6 bytes
55 */
56#define MAX_REPLY_EXTRA_BYTES 6
57
58/*
59 * Library user must provide a static buffer of size ATTRNAMEBUFSIZ.
60 * It's used when listing EAs as intermediate buffer. For afpd it's
61 * defined in extattrs.c.
62 */
63#define ATTRNAMEBUFSIZ 4096
64
65enum {
69};
70
71#if !defined(HAVE_SETXATTR)
72#define XATTR_CREATE 0x1 /* set value, fail if attr already exists */
73#define XATTR_REPLACE 0x2 /* set value, fail if attr does not exist */
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);
107int sys_removexattr(const char *path, const char *name);
108int sys_lremovexattr(const char *path, const char *name);
109#if 0
110int sys_fremovexattr(int filedes, const char *name);
111#endif
112int sys_fremovexattr(int filedes, const char *path, const char *name);
113int sys_setxattr(const char *path, const char *name, const void *value,
114 size_t size, int flags);
115int sys_lsetxattr(const char *path, const char *name, const void *value,
116 size_t size, int flags);
117int sys_fsetxattr(int filedes, const char *name, const void *value, size_t size,
118 int flags);
119int sys_copyxattr(const char *src, const char *dst);
120int 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 /* ea"INT", for interfacing ea_open w. ea_close */
127#define EA_MAGIC 0x61644541 /* "adEA" */
128#define EA_VERSION1 0x01
129#define EA_VERSION EA_VERSION1
130
131typedef enum {
132 /* ea_open flags */
133 EA_CREATE = (1 << 1), /* create if not existing on ea_open */
134 EA_RDONLY = (1 << 2), /* open read only */
135 EA_RDWR = (1 << 3), /* open read/write */
136 /* ea_open internal flags */
137 EA_DIR = (1 << 4) /* ea header file is for a dir, ea_open adds it as appropriate */
138} eaflags_t;
139
140#define EA_MAGIC_OFF 0
141#define EA_MAGIC_LEN 4
142#define EA_VERSION_OFF (EA_MAGIC_OFF + EA_MAGIC_LEN)
143#define EA_VERSION_LEN 2
144#define EA_COUNT_OFF (EA_VERSION_OFF + EA_VERSION_LEN)
145#define EA_COUNT_LEN 2
146#define EA_HEADER_SIZE (EA_MAGIC_LEN + EA_VERSION_LEN + EA_COUNT_LEN)
147
148/*
149 * structs describing the layout of the Extended Attributes bookkeeping file.
150 * This isn't really an AppleDouble structure, it's just a binary blob that
151 * lives in our .AppleDouble directory too.
152 */
153
154struct ea_entry {
155 /* len of ea_name without terminating 0 i.e. strlen(ea_name)*/
157 /* size of EA */
158 size_t ea_size;
159 /* name of the EA */
160 char *ea_name;
161};
162
163/* We read the on-disk data into *ea_data and parse it into this*/
164struct ea {
165 /* needed for interfacing ea_open w. ea_close */
166 uint32_t ea_inited;
167 /* vol handle, ea_close needs it */
168 const struct vol *vol;
169 /* for *at (cf openat) semantics, -1 means ignore */
170 int dirfd;
171 /* name of file, needed by ea_close too */
172 char *filename;
173 /* number of EAs in ea_entries array */
174 unsigned int ea_count;
175 /* malloced and realloced as needed by ea_count*/
176 struct ea_entry(*ea_entries)[];
177 /* open fd for ea_data */
178 int ea_fd;
179 /* flags */
181 /* size of header file = size of ea_data buffer */
182 size_t ea_size;
183 /* pointer to buffer into that we actually *
184 * read the disc file into */
185 char *ea_data;
186};
187
188/* On-disk format, just for reference ! */
189#if 0
190struct ea_entry_ondisk {
191 uint32_t ea_size;
192 /* zero terminated string */
193 char ea_name[];
194};
195
196struct ea_ondisk {
197 uint32_t ea_magic;
198 uint16_t ea_version;
199 uint16_t ea_count;
200 struct ea_entry_ondisk ea_entries[ea_count];
201};
202#endif /* 0 */
203
204/* VFS inderected funcs ... : */
205
206/* Default adouble EAs */
210extern int set_ea(VFS_FUNC_ARGS_EA_SET);
212/* ... EA VFS funcs that deal with file/dir cp/mv/rm */
216extern int ea_chown(VFS_FUNC_ARGS_CHOWN);
219
220/* native EAs */
226/* native EA VFSfile/dir cp/mv/rm */
228
229/* dbd needs access to these */
230extern int ea_open(const struct vol *restrict vol,
231 const char *restrict uname,
232 eaflags_t eaflags,
233 struct ea *restrict ea);
234extern int ea_openat(const struct vol *restrict vol,
235 int dirfd,
236 const char *restrict uname,
237 eaflags_t eaflags,
238 struct ea *restrict ea);
239extern int ea_close(struct ea *restrict ea);
240extern char *ea_path(const struct ea *restrict ea,
241 const char *restrict eaname, int macname);
242
243#endif /* ATALK_EA_H */
static dbd_flags_t flags
Definition cmd_dbd.c:45
int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
Definition extattr.c:756
ssize_t sys_flistxattr(int filedes, const char *path, char *list, size_t size)
Definition extattr.c:468
ssize_t sys_listxattr(const char *path, char *list, size_t size)
Definition extattr.c:435
int sys_fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags)
Definition extattr.c:688
ssize_t sys_getxattr(const char *path, const char *name, void *value, size_t size)
Definition extattr.c:120
@ kXAttrReplace
Definition ea.h:68
@ kXAttrCreate
Definition ea.h:67
@ kXAttrNoFollow
Definition ea.h:66
int sys_get_easize(VFS_FUNC_ARGS_EA_GETSIZE)
Definition ea_sys.c:64
int list_eas(VFS_FUNC_ARGS_EA_LIST)
Definition ea_ad.c:1198
int sys_setxattr(const char *path, const char *name, const void *value, size_t size, int flags)
Definition extattr.c:623
int sys_remove_ea(VFS_FUNC_ARGS_EA_REMOVE)
Definition ea_sys.c:522
int sys_list_eas(VFS_FUNC_ARGS_EA_LIST)
Definition ea_sys.c:301
ssize_t sys_llistxattr(const char *path, char *list, size_t size)
Definition extattr.c:502
int sys_getxattrfd(int fd, const char *uname, int oflag,...)
int ea_chmod_file(VFS_FUNC_ARGS_SETFILEMODE)
Definition ea_ad.c:1720
int set_ea(VFS_FUNC_ARGS_EA_SET)
Definition ea_ad.c:1285
char * ea_path(const struct ea *restrict ea, const char *restrict eaname, int macname)
Definition ea_ad.c:634
int ea_deletefile(VFS_FUNC_ARGS_DELETEFILE)
Definition ea_ad.c:1375
int ea_open(const struct vol *restrict vol, const char *restrict uname, eaflags_t eaflags, struct ea *restrict ea)
Definition ea_ad.c:687
ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
Definition extattr.c:250
int ea_chmod_dir(VFS_FUNC_ARGS_SETDIRUNIXMODE)
Definition ea_ad.c:1795
int remove_ea(VFS_FUNC_ARGS_EA_REMOVE)
Definition ea_ad.c:1337
int sys_lremovexattr(const char *path, const char *name)
Definition extattr.c:595
int sys_copyxattr(const char *src, const char *dst)
int sys_get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT)
Definition ea_sys.c:163
int get_easize(VFS_FUNC_ARGS_EA_GETSIZE)
Definition ea_ad.c:1038
ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
Definition extattr.c:187
int sys_removexattr(const char *path, const char *name)
Definition extattr.c:535
int sys_fremovexattr(int filedes, const char *path, const char *name)
Definition extattr.c:565
int ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
Definition ea_ad.c:1558
int ea_openat(const struct vol *restrict vol, int dirfd, const char *restrict uname, eaflags_t eaflags, struct ea *restrict ea)
Definition ea_ad.c:863
int get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT)
Definition ea_ad.c:1101
int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
Definition ea_sys.c:595
int sys_set_ea(VFS_FUNC_ARGS_EA_SET)
Definition ea_sys.c:402
eaflags_t
Definition ea.h:131
@ EA_RDONLY
Definition ea.h:134
@ EA_CREATE
Definition ea.h:133
@ EA_RDWR
Definition ea.h:135
@ EA_DIR
Definition ea.h:137
int ea_renamefile(VFS_FUNC_ARGS_RENAMEFILE)
Definition ea_ad.c:1435
int ea_chown(VFS_FUNC_ARGS_CHOWN)
Definition ea_ad.c:1653
int ea_close(struct ea *restrict ea)
Definition ea_ad.c:914
Definition ea.h:154
char * ea_name
Definition ea.h:160
size_t ea_namelen
Definition ea.h:156
size_t ea_size
Definition ea.h:158
Definition ea.h:164
eaflags_t ea_flags
Definition ea.h:180
char * filename
Definition ea.h:172
int dirfd
Definition ea.h:170
size_t ea_size
Definition ea.h:182
char * ea_data
Definition ea.h:185
unsigned int ea_count
Definition ea.h:174
int ea_fd
Definition ea.h:178
uint32_t ea_inited
Definition ea.h:166
const struct vol * vol
Definition ea.h:168
struct ea_entry(* ea_entries)[]
Definition ea.h:176
Definition etc/atalkd/list.h:6
Definition include/atalk/directory.h:97
Definition include/atalk/volume.h:32
#define VFS_FUNC_ARGS_SETFILEMODE
Definition vfs.h:44
#define VFS_FUNC_ARGS_SETDIRUNIXMODE
Definition vfs.h:50
#define VFS_FUNC_ARGS_DELETEFILE
Definition vfs.h:56
#define VFS_FUNC_ARGS_COPYFILE
Definition vfs.h:62
#define VFS_FUNC_ARGS_EA_REMOVE
Definition vfs.h:89
#define VFS_FUNC_ARGS_CHOWN
Definition vfs.h:35
#define VFS_FUNC_ARGS_EA_LIST
Definition vfs.h:83
#define VFS_FUNC_ARGS_EA_GETSIZE
Definition vfs.h:77
#define VFS_FUNC_ARGS_RENAMEFILE
Definition vfs.h:59
#define VFS_FUNC_ARGS_EA_GETCONTENT
Definition vfs.h:80
#define VFS_FUNC_ARGS_EA_SET
Definition vfs.h:86