2 Copyright (C) 2010 Proxmox Server Solutions GmbH
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Affero General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
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 Affero General Public License for more details.
14 You should have received a copy of the GNU Affero General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Author: Dietmar Maurer <dietmar@proxmox.com>
23 #endif /* HAVE_CONFIG_H */
30 #include <sys/types.h>
37 #include "cfs-utils.h"
41 static struct cfs_operations cfs_ops
;
43 static cfs_plug_t
*cfs_plug_link_lookup_plug(cfs_plug_t
*plug
, char **path
)
45 g_return_val_if_fail(plug
!= NULL
, NULL
);
46 g_return_val_if_fail(plug
->ops
== &cfs_ops
, NULL
);
48 return (!*path
|| !(*path
)[0]) ? plug
: NULL
;
51 static int cfs_plug_link_getattr(cfs_plug_t
*plug
, const char *path
, struct stat
*stbuf
)
53 g_return_val_if_fail(plug
!= NULL
, PARAM_CHECK_ERRNO
);
54 g_return_val_if_fail(plug
->ops
== &cfs_ops
, PARAM_CHECK_ERRNO
);
55 g_return_val_if_fail(path
!= NULL
, PARAM_CHECK_ERRNO
);
56 g_return_val_if_fail(stbuf
!= NULL
, PARAM_CHECK_ERRNO
);
58 cfs_debug("enter cfs_plug_link_getattr %s", path
);
60 memset(stbuf
, 0, sizeof(struct stat
));
62 if (cfs_is_quorate()) {
63 stbuf
->st_mode
= S_IFLNK
| 0777;
65 stbuf
->st_mode
= S_IFLNK
| 0555;
73 static int cfs_plug_link_readlink(cfs_plug_t
*plug
, const char *path
, char *buf
, size_t max
)
75 g_return_val_if_fail(plug
!= NULL
, PARAM_CHECK_ERRNO
);
76 g_return_val_if_fail(plug
->ops
== &cfs_ops
, PARAM_CHECK_ERRNO
);
77 g_return_val_if_fail(path
!= NULL
, PARAM_CHECK_ERRNO
);
78 g_return_val_if_fail(buf
!= NULL
, PARAM_CHECK_ERRNO
);
80 cfs_debug("enter cfs_plug_link_readlink %s", path
);
84 cfs_plug_link_t
*lnk
= (cfs_plug_link_t
*)plug
;
89 strncpy(buf
, lnk
->symlink
, max
);
98 static void cfs_plug_link_destroy(cfs_plug_t
*plug
)
100 g_return_if_fail(plug
!= NULL
);
101 g_return_if_fail(plug
->ops
== &cfs_ops
);
103 cfs_plug_link_t
*lnk
= (cfs_plug_link_t
*)plug
;
105 cfs_debug("enter cfs_plug_link_destroy %s", plug
->name
);
109 g_free(lnk
->symlink
);
114 static struct cfs_operations cfs_ops
= {
115 .getattr
= cfs_plug_link_getattr
,
116 .readlink
= cfs_plug_link_readlink
,
120 cfs_plug_link_t
*cfs_plug_link_new(const char *name
, const char *symlink
)
122 g_return_val_if_fail(name
!= NULL
, NULL
);
123 g_return_val_if_fail(symlink
!= NULL
, NULL
);
125 cfs_plug_link_t
*lnk
= g_new0(cfs_plug_link_t
, 1);
127 lnk
->plug
.ops
= &cfs_ops
;
129 lnk
->plug
.lookup_plug
= cfs_plug_link_lookup_plug
;
130 lnk
->plug
.destroy_plug
= cfs_plug_link_destroy
;
132 lnk
->plug
.name
= g_strdup(name
);
134 lnk
->symlink
= g_strdup(symlink
);