]> arthur.barton.de Git - netatalk.git/blob - include/atalk/ea.h
Convert afp_moveandrename and all called funcs to XXXat semantics if available
[netatalk.git] / include / atalk / ea.h
1 /*
2    $Id: ea.h,v 1.11 2010-03-12 15:16:49 franklahm Exp $
3    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9  
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 */
15
16 #ifndef ATALK_EA_H
17 #define ATALK_EA_H
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #ifdef HAVE_NFSv4_ACLS
24 #include <sys/acl.h>
25 #endif
26
27 #include <atalk/vfs.h>
28
29 /*
30  * This seems to be the current limit fo HFS+, we arbitrarily force that
31  *  which also safes us from buffer overflows
32  */
33 #define MAX_EA_SIZE 3802
34
35 /*
36  * At time of writing the 10.5.6 client adds 8 bytes to the
37  * length of the EA that we send him 
38 */
39 #define MAX_REPLY_EXTRA_BYTES 8
40
41 /* 
42  * Library user must provide a static buffer of size ATTRNAMEBUFSIZ.
43  * It's used when listing EAs as intermediate buffer. For afpd it's
44  * defined in extattrs.c.
45  */
46 #define ATTRNAMEBUFSIZ 4096
47
48 enum {
49     kXAttrNoFollow = 0x1,
50     kXAttrCreate = 0x2,
51     kXAttrReplace = 0x4
52 };
53
54 #if !defined(HAVE_SETXATTR)
55 #define XATTR_CREATE  0x1       /* set value, fail if attr already exists */
56 #define XATTR_REPLACE 0x2       /* set value, fail if attr does not exist */
57 #endif
58
59
60 /****************************************************************************************
61  * Stuff for our implementation of storing EAs in files in .AppleDouble dirs
62  ****************************************************************************************/
63
64 #define EA_INITED   0xea494e54  /* ea"INT", for interfacing ea_open w. ea_close */
65 #define EA_MAGIC    0x61644541 /* "adEA" */
66 #define EA_VERSION1 0x01
67 #define EA_VERSION  EA_VERSION1
68
69 typedef enum {
70     /* ea_open flags */
71     EA_CREATE    = (1<<1),      /* create if not existing on ea_open */
72     EA_RDONLY    = (1<<2),      /* open read only */
73     EA_RDWR      = (1<<3),      /* open read/write */
74     /* ea_open internal flags */
75     EA_DIR       = (1<<4)       /* ea header file is for a dir, ea_open adds it as appropiate */
76 } eaflags_t;
77
78 #define EA_MAGIC_OFF   0
79 #define EA_MAGIC_LEN   4
80 #define EA_VERSION_OFF (EA_MAGIC_OFF + EA_MAGIC_LEN)
81 #define EA_VERSION_LEN 2
82 #define EA_COUNT_OFF   (EA_VERSION_OFF + EA_VERSION_LEN)
83 #define EA_COUNT_LEN   2
84 #define EA_HEADER_SIZE (EA_MAGIC_LEN + EA_VERSION_LEN + EA_COUNT_LEN)
85
86 /* 
87  * structs describing the layout of the Extended Attributes bookkeeping file.
88  * This isn't really an AppleDouble structure, it's just a binary blob that
89  * lives in our .AppleDouble directory too.
90  */
91
92 struct ea_entry {
93     size_t       ea_namelen; /* len of ea_name without terminating 0 ie. strlen(ea_name)*/
94     size_t       ea_size;    /* size of EA*/
95     char         *ea_name;   /* name of the EA */
96 };
97
98 /* We read the on-disk data into *ea_data and parse it into this*/
99 struct ea {
100     uint32_t             ea_inited;       /* needed for interfacing ea_open w. ea_close */
101     const struct vol     *vol;            /* vol handle, ea_close needs it */
102     int                  dirfd;           /* for *at (cf openat) semantics, -1 means ignore */
103     char                 *filename;       /* name of file, needed by ea_close too */
104     unsigned int         ea_count;        /* number of EAs in ea_entries array */
105     struct ea_entry      (*ea_entries)[]; /* malloced and realloced as needed by ea_count*/
106     int                  ea_fd;           /* open fd for ea_data */
107     eaflags_t            ea_flags;        /* flags */
108     size_t               ea_size;         /* size of header file = size of ea_data buffer */
109     char                 *ea_data;        /* pointer to buffer into that we actually *
110                                            * read the disc file into                 */
111 };
112
113 /* On-disk format, just for reference ! */
114 #if 0
115 struct ea_entry_ondisk {
116     uint32_t               ea_size;
117     char                   ea_name[]; /* zero terminated string */
118 };
119
120 struct ea_ondisk {
121     u_int32_t              ea_magic;
122     u_int16_t              ea_version;
123     u_int16_t              ea_count;
124     struct ea_entry_ondisk ea_entries[ea_count];
125 };
126 #endif /* 0 */
127
128 /* VFS inderected funcs ... : */
129
130 /* Default adouble EAs */
131 extern int get_easize(VFS_FUNC_ARGS_EA_GETSIZE);
132 extern int get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT);
133 extern int list_eas(VFS_FUNC_ARGS_EA_LIST);
134 extern int set_ea(VFS_FUNC_ARGS_EA_SET);
135 extern int remove_ea(VFS_FUNC_ARGS_EA_REMOVE);
136 /* ... EA VFS funcs that deal with file/dir cp/mv/rm */
137 extern int ea_deletefile(VFS_FUNC_ARGS_DELETEFILE);
138 extern int ea_renamefile(VFS_FUNC_ARGS_RENAMEFILE);
139 extern int ea_copyfile(VFS_FUNC_ARGS_COPYFILE);
140 extern int ea_chown(VFS_FUNC_ARGS_CHOWN);
141 extern int ea_chmod_file(VFS_FUNC_ARGS_SETFILEMODE);
142 extern int ea_chmod_dir(VFS_FUNC_ARGS_SETDIRUNIXMODE);
143
144 /* native EAs */
145 extern int sys_get_easize(VFS_FUNC_ARGS_EA_GETSIZE);
146 extern int sys_get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT);
147 extern int sys_list_eas(VFS_FUNC_ARGS_EA_LIST);
148 extern int sys_set_ea(VFS_FUNC_ARGS_EA_SET);
149 extern int sys_remove_ea(VFS_FUNC_ARGS_EA_REMOVE);
150 /* native EA VFSfile/dir cp/mv/rm */
151 extern int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE);
152
153 /* dbd needs access to these */
154 extern int ea_open(const struct vol * restrict vol,
155                    const char * restrict uname,
156                    eaflags_t eaflags,
157                    struct ea * restrict ea);
158 extern int ea_openat(const struct vol * restrict vol,
159                      int dirfd,
160                      const char * restrict uname,
161                      eaflags_t eaflags,
162                      struct ea * restrict ea);
163 extern int ea_close(struct ea * restrict ea);
164 extern char *ea_path(const struct ea * restrict ea, const char * restrict eaname, int macname);
165
166 #endif /* ATALK_EA_H */