]> arthur.barton.de Git - netatalk.git/blob - include/atalk/cnid.h
9c8e0bacd065a69afb363b499ee78024c41f26f3
[netatalk.git] / include / atalk / cnid.h
1 /*
2  * Copyright (c) 2003 the Netatalk Team
3  * Copyright (c) 2003 Rafal Lewczuk <rlewczuk@pronet.pl>
4  * Copyright (c) 2010 Frank Lahm
5  *
6  * This program is free software; you can redistribute and/or modify
7  * it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation version 2 of the License or later
9  * version if explicitly stated by any of above copyright holders.
10  *
11  */
12
13 /*
14  * This file contains all generic CNID related stuff
15  * declarations. Included:
16  * - CNID factory, which retrieves (eventually instantiates)
17  *   CNID objects on demand
18  * - selection of CNID backends (default, detected by volume)
19  * - full set of CNID operations needed by server core.
20  */
21
22 #ifndef _ATALK_CNID__H
23 #define _ATALK_CNID__H 1
24
25 #include <atalk/adouble.h>
26 #include <atalk/list.h>
27 #include <atalk/uuid.h>
28
29 /* CNID object flags */
30 #define CNID_FLAG_PERSISTENT   0x01      /* This backend implements DID persistence */
31 #define CNID_FLAG_MANGLING     0x02      /* This backend has name mangling feature. */
32 #define CNID_FLAG_SETUID       0x04      /* Set db owner to parent folder owner. */
33 #define CNID_FLAG_BLOCK        0x08      /* block signals in update. */
34 #define CNID_FLAG_NODEV        0x10      /* don't use device number only inode */
35 #define CNID_FLAG_LAZY_INIT    0x20      /* */
36 #define CNID_FLAG_MEMORY       0x40  /* this is a memory only db */
37 #define CNID_FLAG_INODE        0x80  /* in cnid_add the inode is authoritative */
38
39 #define CNID_INVALID   0
40 /* first valid ID */
41 #define CNID_START     17
42
43 #define CNID_ERR_PARAM 0x80000001
44 #define CNID_ERR_PATH  0x80000002
45 #define CNID_ERR_DB    0x80000003
46 #define CNID_ERR_CLOSE 0x80000004   /* the db was not open */
47 #define CNID_ERR_MAX   0x80000005
48
49 /*
50  * This is instance of CNID database object.
51  */
52 struct _cnid_db {
53     uint32_t flags;             /* Flags describing some CNID backend aspects. */
54     char *volpath;               /* Volume path this particular CNID db refers to. */
55     void *_private;              /* back-end speficic data */
56
57     cnid_t (*cnid_add)         (struct _cnid_db *cdb, const struct stat *st, cnid_t did,
58                                 const char *name, size_t, cnid_t hint);
59     int    (*cnid_delete)      (struct _cnid_db *cdb, cnid_t id);
60     cnid_t (*cnid_get)         (struct _cnid_db *cdb, cnid_t did, const char *name, size_t);
61     cnid_t (*cnid_lookup)      (struct _cnid_db *cdb, const struct stat *st, cnid_t did,
62                                 const char *name, size_t);
63     cnid_t (*cnid_nextid)      (struct _cnid_db *cdb);
64     char * (*cnid_resolve)     (struct _cnid_db *cdb, cnid_t *id, void *buffer, size_t len);
65     int    (*cnid_update)      (struct _cnid_db *cdb, cnid_t id, const struct stat *st,
66                                 cnid_t did, const char *name, size_t len);
67     void   (*cnid_close)       (struct _cnid_db *cdb);
68     int    (*cnid_getstamp)    (struct _cnid_db *cdb, void *buffer, const size_t len);
69     cnid_t (*cnid_rebuild_add) (struct _cnid_db *, const struct stat *, cnid_t,
70                                 const char *, size_t, cnid_t);
71     int    (*cnid_find)        (struct _cnid_db *cdb, const char *name, size_t namelen,
72                                 void *buffer, size_t buflen);
73     int    (*cnid_wipe)        (struct _cnid_db *cdb);
74 };
75 typedef struct _cnid_db cnid_db;
76
77 /*
78  * Consolidation of args passedn from main cnid_open to modules cnid_XXX_open, so
79  * that it's easier to add aditional args as required.
80  */
81 struct cnid_open_args {
82     const char *dir;
83     mode_t mask;
84     uint32_t flags;
85
86     /* for dbd */
87     const char *cnidserver;
88     const char *cnidport;
89
90     /* for MySQL */
91     const void *obj;
92     char *voluuid;
93 };
94
95 /*
96  * CNID module - represents particular CNID implementation
97  */
98 struct _cnid_module {
99     char *name;
100     struct list_head db_list;   /* CNID modules are also stored on a bidirectional list. */
101     struct _cnid_db *(*cnid_open)(struct cnid_open_args *args);
102     uint32_t flags;            /* Flags describing some CNID backend aspects. */
103
104 };
105 typedef struct _cnid_module cnid_module;
106
107 /* Inititalize the CNID backends */
108 void cnid_init();
109
110 /* Registers new CNID backend module */
111 void cnid_register(struct _cnid_module *module);
112
113 /* This function opens a CNID database for selected volume. */
114 struct _cnid_db *cnid_open(const char *volpath,
115                            mode_t mask,
116                            char *type,
117                            int flags,
118                            const char *cnidsrv,
119                            const char *cnidport,
120                            const void *obj,
121                            char *uuid);
122 cnid_t cnid_add        (struct _cnid_db *cdb, const struct stat *st, const cnid_t did,
123                         const char *name, const size_t len, cnid_t hint);
124 int    cnid_delete     (struct _cnid_db *cdb, cnid_t id);
125 cnid_t cnid_get        (struct _cnid_db *cdb, const cnid_t did, char *name,const size_t len);
126 int    cnid_getstamp   (struct _cnid_db *cdb, void *buffer, const size_t len);
127 cnid_t cnid_lookup     (struct _cnid_db *cdb, const struct stat *st, const cnid_t did,
128                         char *name, const size_t len);
129 char  *cnid_resolve    (struct _cnid_db *cdb, cnid_t *id, void *buffer, size_t len);
130 int    cnid_update     (struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
131                         const cnid_t did, char *name, const size_t len);
132 cnid_t cnid_rebuild_add(struct _cnid_db *cdb, const struct stat *st, const cnid_t did,
133                         char *name, const size_t len, cnid_t hint);
134 int    cnid_find       (struct _cnid_db *cdb, const char *name, size_t namelen,
135                         void *buffer, size_t buflen);
136 int    cnid_wipe       (struct _cnid_db *cdb);
137 void   cnid_close      (struct _cnid_db *db);
138
139 #endif