]> arthur.barton.de Git - netatalk.git/blob - include/atalk/ea.h
Extended Attributes support via files in .AppleDouble.
[netatalk.git] / include / atalk / ea.h
1 /*
2    $Id: ea.h,v 1.1 2009-10-02 09:32:40 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 /*
24  * This seems to be the current limit fo HFS+, we arbitrarily force that
25  *  which also safes us from buffer overflows
26  */
27 #define MAX_EA_SIZE 3802
28
29 /*
30  * At time of writing the 10.5.6 client adds 8 bytes to the
31  * length of the EA that we send him 
32 */
33 #define MAX_REPLY_EXTRA_BYTES 8
34
35 /* 
36  * Library user must provide a static buffer of size ATTRNAMEBUFSIZ.
37  * It's used when listing EAs as intermediate buffer. For afpd it's
38  * defined in extattrs.c.
39  */
40 #define ATTRNAMEBUFSIZ 4096
41
42 enum {
43     kXAttrNoFollow = 0x1,
44     kXAttrCreate = 0x2,
45     kXAttrReplace = 0x4
46 };
47
48
49 #define EA_MAGIC    0x61644541 /* "adEA" */
50 #define EA_VERSION1 0x01
51 #define EA_VERSION  EA_VERSION1
52
53 typedef enum {
54     /* ea_open flags */
55     EA_CREATE    = (1<<1),      /* create if not existing on ea_open */
56     EA_RDONLY    = (1<<2),      /* open read only */
57     EA_RDWR      = (1<<3),      /* open read/write */
58     /* ea_open internal flags */
59     EA_DIR       = (1<<4)       /* ea header file is for a dir, ea_open adds it as appropiate */
60 } eaflags_t;
61
62 #define EA_MAGIC_OFF   0
63 #define EA_MAGIC_LEN   4
64 #define EA_VERSION_OFF (EA_MAGIC_OFF + EA_MAGIC_LEN)
65 #define EA_VERSION_LEN 2
66 #define EA_COUNT_OFF   (EA_VERSION_OFF + EA_VERSION_LEN)
67 #define EA_COUNT_LEN   2
68 #define EA_HEADER_SIZE (EA_MAGIC_LEN + EA_VERSION_LEN + EA_COUNT_LEN)
69
70 /* 
71  * structs describing the layout of the Extended Attributes bookkeeping file.
72  * This isn't really an AppleDouble structure, it's just a binary blob that
73  * lives in our .AppleDouble directory too.
74  */
75
76 struct ea_entry {
77     size_t       ea_namelen; /* len of ea_name without terminating 0 ie. strlen(ea_name)*/
78     size_t       ea_size;    /* size of EA*/
79     char         *ea_name;   /* name of the EA */
80 };
81
82 /* We read the on-disk data into *ea_data and parse it into this*/
83 struct ea {
84     const struct vol     *vol;            /* vol handle, ea_close needs it */
85     char                 *filename;       /* name of file, needed by ea_close too */
86     unsigned int         ea_count;        /* number of EAs in ea_entries array */
87     struct ea_entry      (*ea_entries)[]; /* malloced and realloced as needed by ea_count*/
88     int                  ea_fd;           /* open fd for ea_data */
89     eaflags_t            ea_flags;        /* flags */
90     size_t               ea_size;         /* size of header file = size of ea_data buffer */
91     char                 *ea_data;        /* pointer to buffer into that we actually *
92                                            * read the disc file into                 */
93 };
94
95 /* On-disk format, just for reference ! */
96 #if 0
97 struct ea_entry_ondisk {
98     uint32_t               ea_size;
99     char                   ea_name[]; /* zero terminated string */
100 };
101
102 struct ea_ondisk {
103     u_int32_t              ea_magic;
104     u_int16_t              ea_version;
105     u_int16_t              ea_count;
106     struct ea_entry_ondisk ea_entries[ea_count];
107 };
108 #endif /* 0 */
109
110 #endif /* ATALK_EA_H */