Completed initial implementation. - susmb - mounting of SMB/CIFS shares via FUSE
HTML git clone git://git.codemadness.org/susmb
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit b1b3acf51f3aff93c15bfa514b64adee8adb6381
DIR parent 5f2b4da911cafeff284a07cb31b8bdca77e84ac8
HTML Author: geoff <devnull@localhost>
Date: Sat, 6 May 2006 23:12:19 +0000
Completed initial implementation.
Diffstat:
M Makefile | 3 ++-
M usmb.c | 16 +++++++++-------
M usmb_file.c | 78 ++++++++++++++++++++++++++++++-
M usmb_file.h | 6 ++++++
4 files changed, 94 insertions(+), 9 deletions(-)
---
DIR diff --git a/Makefile b/Makefile
@@ -1,7 +1,8 @@
SAMBA = /opt/samba
CC = gcc
CFLAGS = -Wall -W -std=c99 -pedantic -O $(shell pkg-config --cflags fuse) \
- -I$(SAMBA)/include -D_BSD_SOURCE -DFUSE_USE_VERSION=25 # -DDEBUG
+ -I$(SAMBA)/include -D_BSD_SOURCE -DFUSE_USE_VERSION=25 \
+ -DHAVE_UTIME_H # -DDEBUG
LDLIBS = $(shell pkg-config --libs-only-l fuse) -lsmbclient
LDFLAGS = $(shell pkg-config --libs-only-L fuse) -L$(SAMBA)/lib
DIR diff --git a/usmb.c b/usmb.c
@@ -118,6 +118,8 @@ static inline void do_strncpy (char *to, const char *from, int tolen)
static void auth_fn (const char *srv, const char *shr, char *wg, int wglen,
char *un, int unlen, char *pw, int pwlen)
{
+ (void)srv;
+ (void)shr;
DEBUG (fprintf (stderr, "Authenticating for \\\\%s\\%s\n", srv, shr));
do_strncpy (wg, "WORKGROUP", wglen);
@@ -138,21 +140,21 @@ static void usmb_destroy (void *unused)
}
+// probably won't (can't ?) implement these.
#define usmb_readlink NULL
#define usmb_mknod NULL
-#define usmb_unlink NULL
#define usmb_symlink NULL
-#define usmb_rename NULL
#define usmb_chmod NULL
#define usmb_chown NULL
-#define usmb_truncate NULL
-#define usmb_utime NULL
-#define usmb_statfs NULL
#define usmb_flush NULL
-#define usmb_release NULL
#define usmb_fsync NULL
+
+// fuse.h says "Just a placeholder, don't set".
+#define usmb_statfs NULL
+
#define usmb_access NULL
-#define usmb_create NULL
+
+// no easy way of implementing these.
#define usmb_ftruncate NULL
DIR diff --git a/usmb_file.c b/usmb_file.c
@@ -29,6 +29,18 @@ int usmb_fgetattr (const char *filename, struct stat *st,
}
+int usmb_unlink (const char *filename)
+{
+ char *url = make_url (filename);
+ if (NULL == url)
+ return -ENOMEM;
+
+ int ret = (smbc_unlink (url) < 0) ? -errno : 0;
+ free (url);
+ return ret;
+}
+
+
int usmb_open (const char *filename, struct fuse_file_info *fi)
{
char *url = make_url (filename);
@@ -37,7 +49,7 @@ int usmb_open (const char *filename, struct fuse_file_info *fi)
DEBUG (fprintf (stderr, "open (%s)\n", url));
- int fd = smbc_open (url, 0, 0);
+ int fd = smbc_open (url, fi->flags, 0);
int ret = (fd < 0) ? -errno : 0;
fi->fh = fd;
@@ -76,3 +88,67 @@ int usmb_write (const char *filename, const char *buff, size_t len, off_t off,
return smbc_write (fi->fh, (char *)buff, len) ? -errno : 0;
}
+
+int usmb_create (const char *filename, mode_t mode, struct fuse_file_info *fi)
+{
+ char *url = make_url (filename);
+ if (NULL == url)
+ return -ENOMEM;
+
+ int fd = smbc_creat (url, mode);
+ int ret = (fd < 0) ? -errno : 0;
+ fi->fh = fd;
+
+ free (url);
+ return ret;
+}
+
+
+int usmb_rename (const char *from, const char *to)
+{
+ char *fromurl = make_url (from);
+ if (NULL == fromurl)
+ return -ENOMEM;
+
+ char *tourl = make_url (to);
+ if (NULL == tourl)
+ {
+ free (fromurl);
+ return -ENOMEM;
+ }
+
+ int ret = (smbc_rename (fromurl, tourl) < 0) ? -errno : 0;
+ free (tourl);
+ free (fromurl);
+ return ret;
+}
+
+
+int usmb_utime (const char *filename, struct utimbuf *utb)
+{
+ char *url = make_url (filename);
+ if (NULL == url)
+ return -ENOMEM;
+
+ int ret = (smbc_utime (url, utb) < 0) ? -errno : 0;
+ free (url);
+ return ret;
+}
+
+
+int usmb_truncate (const char *filename, off_t newsize)
+{
+ // FIXME: TODO: currently ignores newsize
+ (void)newsize;
+
+ char *url = make_url (filename);
+ if (NULL == url)
+ return -ENOMEM;
+
+ int fd = smbc_open (url, O_WRONLY | O_TRUNC, 0);
+ if (fd < 0)
+ return -errno;
+
+ smbc_close (fd);
+ return 0;
+}
DIR diff --git a/usmb_file.h b/usmb_file.h
@@ -8,11 +8,17 @@
int usmb_getattr (const char *filename, struct stat *st);
int usmb_fgetattr (const char *filename, struct stat *st,
struct fuse_file_info *fi);
+ int usmb_unlink (const char *filename);
int usmb_open (const char *filename, struct fuse_file_info *fi);
int usmb_release (const char *filename, struct fuse_file_info *fi);
int usmb_read (const char *filename, char *buff, size_t len, off_t off,
struct fuse_file_info *fi);
int usmb_write (const char *filename, const char *buff, size_t len, off_t off,
struct fuse_file_info *fi);
+ int usmb_create (const char *filename, mode_t mode,
+ struct fuse_file_info *fi);
+ int usmb_rename (const char *from, const char *to);
+ int usmb_utime (const char *filename, struct utimbuf *utb);
+ int usmb_truncate (const char *filename, off_t newsize);
#endif