Use a new context for usmb_readdir(). - susmb - mounting of SMB/CIFS shares via FUSE
(HTM) git clone git://git.codemadness.org/susmb
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit c2d69fd5b355cd1b982bb9919d4e9910ef447e7c
(DIR) parent 0e9a2c7d1d573efa1409280752f4660dfcb84a70
(HTM) Author: Geoff Johnstone <qwerty@acm.org>
Date: Fri, 10 Apr 2009 13:46:02 +0100
Use a new context for usmb_readdir().
Diffstat:
M usmb.c | 26 +++-----------------------
M usmb.h | 3 ++-
M usmb_dir.c | 86 +++++++++++++++++++++----------
3 files changed, 63 insertions(+), 52 deletions(-)
---
(DIR) diff --git a/usmb.c b/usmb.c
@@ -76,7 +76,7 @@ static void auth_fn (const char *srv UNUSED, const char *shr UNUSED,
}
-static void destroy_smb_context (SMBCCTX *ctx, int shutdown)
+void destroy_smb_context (SMBCCTX *ctx, int shutdown)
{
// Samba frees the workgroup and user strings but we want to persist them.
smbc_setWorkgroup (ctx, NULL);
@@ -85,7 +85,7 @@ static void destroy_smb_context (SMBCCTX *ctx, int shutdown)
}
-static bool create_smb_context (char *domain, char *username, SMBCCTX **pctx)
+bool create_smb_context (SMBCCTX **pctx)
{
*pctx = smbc_new_context();
@@ -256,7 +256,7 @@ static bool get_context (void)
if ((NULL == password) && !password_read (&password))
break;
- if (!create_smb_context (domain, username, &ctx))
+ if (!create_smb_context (&ctx))
{
clear_and_free (password);
password = NULL;
@@ -279,26 +279,6 @@ static bool get_context (void)
}
-bool renew_smb_context (void)
-{
- SMBCCTX *newctx;
-
- DEBUG (fputs ("renew_smb_context()\n", stderr));
-
- if (!create_smb_context (domain, username, &newctx))
- {
- fputs ("Failed to create new SMB context.\n", stderr);
- return false;
- }
-
- if (NULL != ctx)
- destroy_smb_context (ctx, 0);
-
- ctx = newctx;
- return true;
-}
-
-
int main (int argc, char **argv)
{
const char *conffile, *mountid;
(DIR) diff --git a/usmb.h b/usmb.h
@@ -24,7 +24,8 @@
char * make_url (const char *path) MUSTCHECK;
- bool renew_smb_context (void);
+ bool create_smb_context (SMBCCTX **pctx) MUSTCHECK;
+ void destroy_smb_context (SMBCCTX *ctx, int shutdown);
/* fuse_file_info uses a uint64_t for a "File handle" */
static inline uint64_t smbcfile_to_fd (SMBCFILE *file)
(DIR) diff --git a/usmb_dir.c b/usmb_dir.c
@@ -53,9 +53,6 @@ int usmb_rmdir (const char *dirname)
int ret = smbc_getFunctionRmdir (ctx) (ctx, url) ? -errno : 0;
free (url);
- if (0 == ret)
- (void)renew_smb_context();
-
return ret;
}
@@ -78,44 +75,77 @@ int usmb_opendir (const char *dirname, struct fuse_file_info *fi)
}
-int usmb_readdir (const char *path UNUSED, void *h, fuse_fill_dir_t filler,
- off_t offset UNUSED, struct fuse_file_info *fi)
+int usmb_readdir (const char *path, void *h, fuse_fill_dir_t filler,
+ off_t offset UNUSED, struct fuse_file_info *fi UNUSED)
{
+ SMBCCTX *ctx = NULL;
+ SMBCFILE *file = NULL;
+ char *url = NULL;
struct smbc_dirent *dirent;
- errno = 0;
- SMBCFILE *file = fd_to_smbcfile (fi->fh);
+ int ret = 0;
- DEBUG (fprintf (stderr, "readdir (%s, %p)\n", path, (void *)file));
- smbc_getFunctionLseekdir (ctx) (ctx, file, 0);
+ DEBUG (fprintf (stderr, "readdir (%s)\n", path));
- while (NULL != (dirent = smbc_getFunctionReaddir (ctx) (ctx, file)))
- {
- struct stat stbuf;
+ if (!create_smb_context (&ctx))
+ return -errno;
- switch (dirent->smbc_type)
+ do
+ {
+ url = make_url (path);
+ if (NULL == url)
{
- case SMBC_DIR:
- stbuf.st_mode = DT_DIR << 12;
- break;
+ ret = -ENOMEM;
+ break;
+ }
- case SMBC_FILE:
- stbuf.st_mode = DT_REG << 12;
- break;
+ file = smbc_getFunctionOpendir (ctx) (ctx, url);
+ if (NULL == file)
+ {
+ ret = -errno;
+ break;
+ }
- case SMBC_LINK:
- stbuf.st_mode = DT_LNK << 12;
- break;
+ smbc_getFunctionLseekdir (ctx) (ctx, file, 0);
- default:
+ while (NULL != (dirent = smbc_getFunctionReaddir (ctx) (ctx, file)))
+ {
+ struct stat stbuf;
+
+ switch (dirent->smbc_type)
+ {
+ case SMBC_DIR:
+ stbuf.st_mode = DT_DIR << 12;
+ break;
+
+ case SMBC_FILE:
+ stbuf.st_mode = DT_REG << 12;
+ break;
+
+ case SMBC_LINK:
+ stbuf.st_mode = DT_LNK << 12;
+ break;
+
+ default:
+ break;
+ }
+
+ DEBUG (fprintf (stderr, " %s\n", dirent->name));
+ if (1 == filler (h, dirent->name, &stbuf, 0)) /* if error */
+ {
+ ret = -1;
break;
+ }
}
+ } while (false /*CONSTCOND*/);
+
+ if (NULL != file)
+ (void)smbc_getFunctionClosedir (ctx) (ctx, file);
- DEBUG (fprintf (stderr, " %s\n", dirent->name));
- if (1 == filler (h, dirent->name, &stbuf, 0)) /* if error */
- return -1;
- }
+ if (NULL != url)
+ free (url);
- return -errno;
+ destroy_smb_context (ctx, 0);
+ return ret;
}