1 /* usmb - mount SMB shares via FUSE and Samba
2 * Copyright (C) 2006-2010 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/>.
18 #include <sys/time.h> // struct timeval needed by libsmbclient.h
19 #include <libsmbclient.h>
20 #include "samba3x-compat.h"
34 int usmb_mkdir (const char *dirname
, mode_t mode
)
36 char *url
= make_url (dirname
);
40 DEBUG (fprintf (stderr
, "mkdir (%s)\n", url
));
41 int ret
= smbc_getFunctionMkdir (ctx
) (ctx
, url
, mode
) ? -errno
: 0;
47 int usmb_rmdir (const char *dirname
)
49 char *url
= make_url (dirname
);
53 DEBUG (fprintf (stderr
, "rmdir (%s)\n", url
));
54 int ret
= smbc_getFunctionRmdir (ctx
) (ctx
, url
) ? -errno
: 0;
61 int usmb_opendir (const char *dirname
, struct fuse_file_info
*fi
)
63 char *url
= make_url (dirname
);
67 DEBUG (fprintf (stderr
, "opendir (%s)", url
));
68 SMBCFILE
*file
= smbc_getFunctionOpendir (ctx
) (ctx
, url
);
69 DEBUG (fprintf (stderr
, " = %p\n", (void *)file
));
71 int ret
= (NULL
== file
) ? -errno
: 0;
73 fi
->fh
= smbcfile_to_fd (file
);
79 int usmb_readdir (const char *path
, void *h
, fuse_fill_dir_t filler
,
80 off_t offset UNUSED
, struct fuse_file_info
*fi UNUSED
)
83 SMBCFILE
*file
= NULL
;
85 struct smbc_dirent
*dirent
;
88 DEBUG (fprintf (stderr
, "readdir (%s)\n", path
));
90 if (!create_smb_context (&ctx_
))
95 url
= make_url (path
);
102 file
= smbc_getFunctionOpendir (ctx_
) (ctx_
, url
);
109 smbc_getFunctionLseekdir (ctx_
) (ctx_
, file
, 0);
111 while (NULL
!= (dirent
= smbc_getFunctionReaddir (ctx_
) (ctx_
, file
)))
115 switch (dirent
->smbc_type
)
118 stbuf
.st_mode
= DT_DIR
<< 12;
122 stbuf
.st_mode
= DT_REG
<< 12;
126 stbuf
.st_mode
= DT_LNK
<< 12;
133 DEBUG (fprintf (stderr
, " %s\n", dirent
->name
));
134 if (1 == filler (h
, dirent
->name
, &stbuf
, 0)) /* if error */
140 } while (false /*CONSTCOND*/);
143 (void)smbc_getFunctionClosedir (ctx_
) (ctx_
, file
);
148 destroy_smb_context (ctx_
, 0);
153 int usmb_releasedir (const char *path UNUSED
, struct fuse_file_info
*fi
)
155 SMBCFILE
*file
= fd_to_smbcfile (fi
->fh
);
156 DEBUG (fprintf (stderr
, "releasedir (%s, %p)\n", path
, (void *)file
));
157 return (0 > smbc_getFunctionClosedir (ctx
) (ctx
, file
)) ? -errno
: 0;
161 int usmb_setxattr (const char *path
, const char *name
, const char *value
,
162 size_t size
, int flags
)
164 char *url
= make_url (path
);
168 DEBUG (fprintf (stderr
, "setxattr (%s, %s, %p, %u, %x)\n",
169 path
, url
, value
, size
, flags
));
170 int ret
= smbc_getFunctionSetxattr (ctx
) (ctx
, url
, name
,
171 value
, size
, flags
) ? -errno
: 0;
177 int usmb_getxattr (const char *path
, const char *name
, char *value
, size_t size
)
179 char *url
= make_url (path
);
183 DEBUG (fprintf (stderr
, "getxattr (%s, %s, %p, %u)\n",
184 path
, url
, value
, size
));
185 int ret
= smbc_getFunctionGetxattr (ctx
) (ctx
, url
, name
,
186 value
, size
) ? -errno
: 0;
192 int usmb_listxattr (const char *path
, char *list
, size_t size
)
194 char *url
= make_url (path
);
198 DEBUG (fprintf (stderr
, "listxattr (%s, %p, %u)\n", url
, list
, size
));
199 int ret
= smbc_getFunctionListxattr (ctx
) (ctx
, url
, list
, size
) ? -errno
: 0;
205 int usmb_removexattr (const char *path
, const char *name
)
207 char *url
= make_url (path
);
211 DEBUG (fprintf (stderr
, "removexattr (%s, %s)\n", url
, name
));
212 int ret
= smbc_getFunctionRemovexattr (ctx
) (ctx
, url
, name
) ? -errno
: 0;