]> arthur.barton.de Git - netatalk.git/blob - include/atalk/ea.h
Cleaunup and refactor ad_open
[netatalk.git] / include / atalk / ea.h
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 #ifdef HAVE_SOLARIS_ACLS
23 #include <sys/acl.h>
24 #endif
25
26 #include <atalk/vfs.h>
27
28 /*
29  * This seems to be the current limit fo HFS+, we arbitrarily force that
30  *  which also safes us from buffer overflows
31  */
32 #define MAX_EA_SIZE 3802
33
34 /*
35  * At time of writing the 10.5.6 client adds 8 bytes to the
36  * length of the EA that we send him 
37 */
38 #define MAX_REPLY_EXTRA_BYTES 8
39
40 /* 
41  * Library user must provide a static buffer of size ATTRNAMEBUFSIZ.
42  * It's used when listing EAs as intermediate buffer. For afpd it's
43  * defined in extattrs.c.
44  */
45 #define ATTRNAMEBUFSIZ 4096
46
47 enum {
48     kXAttrNoFollow = 0x1,
49     kXAttrCreate = 0x2,
50     kXAttrReplace = 0x4
51 };
52
53 #if !defined(HAVE_SETXATTR)
54 #define XATTR_CREATE  0x1       /* set value, fail if attr already exists */
55 #define XATTR_REPLACE 0x2       /* set value, fail if attr does not exist */
56 #endif
57
58 /****************************************************************************************
59  * Wrappers for native EA functions taken from Samba
60  ****************************************************************************************/
61 ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size);
62 ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t size);
63 ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size);
64 ssize_t sys_listxattr (const char *path, char *list, size_t size);
65 ssize_t sys_llistxattr (const char *path, char *list, size_t size);
66 ssize_t sys_flistxattr (int filedes, char *list, size_t size);
67 int sys_removexattr (const char *path, const char *name);
68 int sys_lremovexattr (const char *path, const char *name);
69 int sys_fremovexattr (int filedes, const char *name);
70 int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags);
71 int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags);
72 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
73 int sys_copyxattr (const char *src, const char *dst);
74
75 /****************************************************************************************
76  * Stuff for our implementation of storing EAs in files in .AppleDouble dirs
77  ****************************************************************************************/
78
79 #define EA_INITED   0xea494e54  /* ea"INT", for interfacing ea_open w. ea_close */
80 #define EA_MAGIC    0x61644541 /* "adEA" */
81 #define EA_VERSION1 0x01
82 #define EA_VERSION  EA_VERSION1
83
84 typedef enum {
85     /* ea_open flags */
86     EA_CREATE    = (1<<1),      /* create if not existing on ea_open */
87     EA_RDONLY    = (1<<2),      /* open read only */
88     EA_RDWR      = (1<<3),      /* open read/write */
89     /* ea_open internal flags */
90     EA_DIR       = (1<<4)       /* ea header file is for a dir, ea_open adds it as appropiate */
91 } eaflags_t;
92
93 #define EA_MAGIC_OFF   0
94 #define EA_MAGIC_LEN   4
95 #define EA_VERSION_OFF (EA_MAGIC_OFF + EA_MAGIC_LEN)
96 #define EA_VERSION_LEN 2
97 #define EA_COUNT_OFF   (EA_VERSION_OFF + EA_VERSION_LEN)
98 #define EA_COUNT_LEN   2
99 #define EA_HEADER_SIZE (EA_MAGIC_LEN + EA_VERSION_LEN + EA_COUNT_LEN)
100
101 /* 
102  * structs describing the layout of the Extended Attributes bookkeeping file.
103  * This isn't really an AppleDouble structure, it's just a binary blob that
104  * lives in our .AppleDouble directory too.
105  */
106
107 struct ea_entry {
108     size_t       ea_namelen; /* len of ea_name without terminating 0 ie. strlen(ea_name)*/
109     size_t       ea_size;    /* size of EA*/
110     char         *ea_name;   /* name of the EA */
111 };
112
113 /* We read the on-disk data into *ea_data and parse it into this*/
114 struct ea {
115     uint32_t             ea_inited;       /* needed for interfacing ea_open w. ea_close */
116     const struct vol     *vol;            /* vol handle, ea_close needs it */
117     int                  dirfd;           /* for *at (cf openat) semantics, -1 means ignore */
118     char                 *filename;       /* name of file, needed by ea_close too */
119     unsigned int         ea_count;        /* number of EAs in ea_entries array */
120     struct ea_entry      (*ea_entries)[]; /* malloced and realloced as needed by ea_count*/
121     int                  ea_fd;           /* open fd for ea_data */
122     eaflags_t            ea_flags;        /* flags */
123     size_t               ea_size;         /* size of header file = size of ea_data buffer */
124     char                 *ea_data;        /* pointer to buffer into that we actually *
125                                            * read the disc file into                 */
126 };
127
128 /* On-disk format, just for reference ! */
129 #if 0
130 struct ea_entry_ondisk {
131     uint32_t               ea_size;
132     char                   ea_name[]; /* zero terminated string */
133 };
134
135 struct ea_ondisk {
136     u_int32_t              ea_magic;
137     u_int16_t              ea_version;
138     u_int16_t              ea_count;
139     struct ea_entry_ondisk ea_entries[ea_count];
140 };
141 #endif /* 0 */
142
143 /* VFS inderected funcs ... : */
144
145 /* Default adouble EAs */
146 extern int get_easize(VFS_FUNC_ARGS_EA_GETSIZE);
147 extern int get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT);
148 extern int list_eas(VFS_FUNC_ARGS_EA_LIST);
149 extern int set_ea(VFS_FUNC_ARGS_EA_SET);
150 extern int remove_ea(VFS_FUNC_ARGS_EA_REMOVE);
151 /* ... EA VFS funcs that deal with file/dir cp/mv/rm */
152 extern int ea_deletefile(VFS_FUNC_ARGS_DELETEFILE);
153 extern int ea_renamefile(VFS_FUNC_ARGS_RENAMEFILE);
154 extern int ea_copyfile(VFS_FUNC_ARGS_COPYFILE);
155 extern int ea_chown(VFS_FUNC_ARGS_CHOWN);
156 extern int ea_chmod_file(VFS_FUNC_ARGS_SETFILEMODE);
157 extern int ea_chmod_dir(VFS_FUNC_ARGS_SETDIRUNIXMODE);
158
159 /* native EAs */
160 extern int sys_get_easize(VFS_FUNC_ARGS_EA_GETSIZE);
161 extern int sys_get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT);
162 extern int sys_list_eas(VFS_FUNC_ARGS_EA_LIST);
163 extern int sys_set_ea(VFS_FUNC_ARGS_EA_SET);
164 extern int sys_remove_ea(VFS_FUNC_ARGS_EA_REMOVE);
165 /* native EA VFSfile/dir cp/mv/rm */
166 extern int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE);
167
168 /* dbd needs access to these */
169 extern int ea_open(const struct vol * restrict vol,
170                    const char * restrict uname,
171                    eaflags_t eaflags,
172                    struct ea * restrict ea);
173 extern int ea_openat(const struct vol * restrict vol,
174                      int dirfd,
175                      const char * restrict uname,
176                      eaflags_t eaflags,
177                      struct ea * restrict ea);
178 extern int ea_close(struct ea * restrict ea);
179 extern char *ea_path(const struct ea * restrict ea, const char * restrict eaname, int macname);
180
181 #endif /* ATALK_EA_H */