Added mention of omitted <password> elements.
[usmb.git] / usmb_dir.c
blob1230e395f0bd0e6c6c13fbae6f89e3f7cd36c842
1 /* usmb - mount SMB shares via FUSE and Samba
2 * Copyright (C) 2006-2008 Geoff Johnstone
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <sys/time.h> // struct timeval needed by libsmbclient.h
18 #include <libsmbclient.h>
19 #include <fuse.h>
20 #include <dirent.h>
21 #include <errno.h>
22 #include <stdarg.h>
23 #include <stddef.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "usmb_dir.h"
28 #include "usmb.h"
29 #include "utils.h"
32 int usmb_mkdir (const char *dirname, mode_t mode)
34 char *url = make_url (dirname);
35 if (NULL == url)
36 return -ENOMEM;
38 DEBUG (fprintf (stderr, "mkdir (%s)\n", url));
39 int ret = ctx->mkdir (ctx, url, mode) ? -errno : 0;
40 free (url);
41 return ret;
45 int usmb_rmdir (const char *dirname)
47 char *url = make_url (dirname);
48 if (NULL == url)
49 return -ENOMEM;
51 DEBUG (fprintf (stderr, "rmdir (%s)\n", url));
52 int ret = ctx->rmdir (ctx, url) ? -errno : 0;
53 free (url);
54 return ret;
58 int usmb_opendir (const char *dirname, struct fuse_file_info *fi)
60 char *url = make_url (dirname);
61 if (NULL == url)
62 return -ENOMEM;
64 DEBUG (fprintf (stderr, "opendir (%s)", url));
65 SMBCFILE *file = ctx->opendir (ctx, url);
66 DEBUG (fprintf (stderr, " = %p\n", (void *)file));
68 int ret = (NULL == file) ? -errno : 0;
69 free (url);
70 fi->fh = smbcfile_to_fd (file);
72 return ret;
76 int usmb_readdir (const char *path, void *h, fuse_fill_dir_t filler,
77 off_t offset, struct fuse_file_info *fi)
79 (void)path;
80 (void)offset;
82 struct smbc_dirent *dirent;
83 errno = 0;
84 SMBCFILE *file = fd_to_smbcfile (fi->fh);
86 DEBUG (fprintf (stderr, "readdir (%s, %p)\n", path, (void *)file));
88 while (NULL != (dirent = ctx->readdir (ctx, file)))
90 struct stat stbuf;
92 switch (dirent->smbc_type)
94 case SMBC_DIR:
95 stbuf.st_mode = DT_DIR << 12;
96 break;
98 case SMBC_FILE:
99 stbuf.st_mode = DT_REG << 12;
100 break;
102 case SMBC_LINK:
103 stbuf.st_mode = DT_LNK << 12;
104 break;
106 default:
107 break;
110 if (1 == filler (h, dirent->name, &stbuf, 0)) /* if error */
111 return -1;
114 return -errno;
118 int usmb_releasedir (const char *path, struct fuse_file_info *fi)
120 (void)path;
122 SMBCFILE *file = fd_to_smbcfile (fi->fh);
123 DEBUG (fprintf (stderr, "releasedir (%s, %p)\n", path, (void *)file));
124 return (ctx->closedir (ctx, file) < 0) ? -errno : 0;
128 int usmb_setxattr (const char *path, const char *name, const char *value,
129 size_t size, int flags)
131 char *url = make_url (path);
132 if (NULL == url)
133 return -ENOMEM;
135 DEBUG (fprintf (stderr, "setxattr (%s, %s, %p, %u, %x)\n",
136 path, url, value, size, flags));
137 int ret = ctx->setxattr (ctx, url, name, value, size, flags) ? -errno : 0;
138 free (url);
139 return ret;
143 int usmb_getxattr (const char *path, const char *name, char *value, size_t size)
145 char *url = make_url (path);
146 if (NULL == url)
147 return -ENOMEM;
149 DEBUG (fprintf (stderr, "getxattr (%s, %s, %p, %u)\n",
150 path, url, value, size));
151 int ret = ctx->getxattr (ctx, url, name, value, size) ? -errno : 0;
152 free (url);
153 return ret;
157 int usmb_listxattr (const char *path, char *list, size_t size)
159 char *url = make_url (path);
160 if (NULL == url)
161 return -ENOMEM;
163 DEBUG (fprintf (stderr, "listxattr (%s, %p, %u)\n", url, list, size));
164 int ret = ctx->listxattr (ctx, url, list, size) ? -errno : 0;
165 free (url);
166 return ret;
170 int usmb_removexattr (const char *path, const char *name)
172 char *url = make_url (path);
173 if (NULL == url)
174 return -ENOMEM;
176 DEBUG (fprintf (stderr, "removexattr (%s, %s)\n", url, name));
177 int ret = ctx->removexattr (ctx, url, name) ? -errno : 0;
178 free (url);
179 return ret;