]> arthur.barton.de Git - netatalk.git/blob - libatalk/cnid/mtab/cnid_mtab.c
Fix type mismatches
[netatalk.git] / libatalk / cnid / mtab / cnid_mtab.c
1
2 /*
3  * $Id: cnid_mtab.c,v 1.3 2009-11-24 08:59:25 franklahm Exp $
4  *
5  * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
6  * All Rights Reserved. See COPYRIGHT.
7  *
8  */
9
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif /* HAVE_CONFIG_H */
13
14 #ifdef CNID_BACKEND_MTAB
15
16 #include "cnid_mtab.h"
17 #include <atalk/logger.h>
18 #include <stdlib.h>
19
20 #ifndef AFS
21 #define CNID_XOR(a) (((a) >> 16) ^ (a))
22 #define CNID_DEV(a) ((((CNID_XOR(major((a)->st_dev)) & 0xf) << 3) |\
23                 (CNID_XOR(minor((a)->st_dev)) & 0x7)) << 24)
24 #define CNID_INODE(a) (((a)->st_ino ^ (((a)->st_ino & 0xff000000) >> 8)) \
25                 & 0x00ffffff)
26 #define CNID_FILE(a) (((a) & 0x1) << 31)
27 #define CNID(a,b) (CNID_DEV(a) | CNID_INODE(a) | CNID_FILE(b))
28 #else
29 #define CNID(a,b) (((a)->st_ino & 0x7fffffff) | CNID_FILE(b))
30 #endif
31
32 /* ------------------------ */
33 cnid_t cnid_mtab_add(struct _cnid_db *cdb, const struct stat *st,
34                      const cnid_t did, char *name, const size_t len, cnid_t hint)
35 {
36     struct stat lst;
37     const struct stat *lstp;
38
39     lstp = lstat(name, &lst) < 0 ? st : &lst;
40
41     return htonl(CNID(lstp, 1));
42 }
43
44
45
46 void cnid_mtab_close(struct _cnid_db *cdb)
47 {
48     free(cdb->volpath);
49     free(cdb);
50 }
51
52
53
54 int cnid_mtab_delete(struct _cnid_db *cdb, const cnid_t id)
55 {
56     return CNID_INVALID;
57 }
58
59
60
61 /* Return CNID for a given did/name. */
62 cnid_t cnid_mtab_get(struct _cnid_db *cdb, const cnid_t did, char *name, const size_t len)
63 {
64     return CNID_INVALID;
65 }
66
67
68 cnid_t cnid_mtab_lookup(struct _cnid_db *cdb, const struct stat *st, const cnid_t did, char *name, const size_t len)
69 {
70     return CNID_INVALID;
71 }
72
73
74 static struct _cnid_db *cnid_mtab_new(const char *volpath)
75 {
76     struct _cnid_db *cdb;
77
78     if ((cdb = (struct _cnid_db *) calloc(1, sizeof(struct _cnid_db))) == NULL)
79         return NULL;
80
81     if ((cdb->volpath = strdup(volpath)) == NULL) {
82         free(cdb);
83         return NULL;
84     }
85
86     cdb->flags = 0;
87     cdb->cnid_add = cnid_mtab_add;
88     cdb->cnid_delete = cnid_mtab_delete;
89     cdb->cnid_get = cnid_mtab_get;
90     cdb->cnid_lookup = cnid_mtab_lookup;
91     cdb->cnid_nextid = NULL;    //cnid_mtab_nextid;
92     cdb->cnid_resolve = cnid_mtab_resolve;
93     cdb->cnid_update = cnid_mtab_update;
94     cdb->cnid_close = cnid_mtab_close;
95     
96     return cdb;
97 }
98
99 struct _cnid_db *cnid_mtab_open(const char *dir, mode_t mask)
100 {
101     struct _cnid_db *cdb;
102
103     if (!dir) {
104         return NULL;
105     }
106
107     if ((cdb = cnid_mtab_new(dir)) == NULL) {
108         LOG(log_error, logtype_default, "cnid_open: Unable to allocate memory for database");
109         return NULL;
110     }
111
112     cdb->_private = NULL;
113     return cdb;
114 }
115
116 struct _cnid_module cnid_mtab_module = {
117     "mtab",
118     {NULL, NULL},
119     cnid_mtab_open,
120 };
121
122
123 /* Return the did/name pair corresponding to a CNID. */
124 char *cnid_mtab_resolve(struct _cnid_db *cdb, cnid_t * id, void *buffer, size_t len)
125 {
126     return NULL;
127 }
128
129
130 int cnid_mtab_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                      /*, const char *info, const int infolen */ )
133 {
134     return 0;
135 }
136
137 #endif /* CNID_BACKEND_MTAB */