susmb

mounting of SMB/CIFS shares via FUSE
git clone git://git.codemadness.org/susmb
Log | Files | Refs | README | LICENSE

commit bd6bdba3c118872e3062daf7fd260d330745af8f
parent db77d112648c00a8456b39c1a5faa0ac061d14f7
Author: geoff <devnull@localhost>
Date:   Thu, 18 May 2006 20:13:31 +0000

Fixed failed assertion when parsing multiple credentials entries.
Worked around bug? in Windows server behaviour exhibited by md5sum: a
read of 32768 bytes works, then a read of 65536 bytes returns 0 bytes.
Samba doesn't do this. Implemented the same fix for usmb_write, although
I have not checked whether corresponding behaviour exists.

Diffstat:
Msax.c | 4++++
Musmb_file.c | 52+++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/sax.c b/sax.c @@ -566,6 +566,10 @@ static void end_creds (struct sax_parser *sp) g_string_free (sp->strs.credentials.username, TRUE); g_string_free (sp->strs.credentials.password, TRUE); + sp->strs.credentials.domain = NULL; + sp->strs.credentials.username = NULL; + sp->strs.credentials.password = NULL; + if (ERROR == sp->state) xfree (sp->strs.credentials.id); } diff --git a/usmb_file.c b/usmb_file.c @@ -94,13 +94,35 @@ int usmb_read (const char *filename, char *buff, size_t len, off_t off, (void)filename; (void)off; - DEBUG (fprintf (stderr, "read (%p, %u)\n", buff, len)); + DEBUG (fprintf (stderr, "read (%p, %u, %lld) ", buff, len, off)); if (smbc_lseek (fi->fh, off, SEEK_SET) < 0) + { + fprintf (stderr, "- seek failed: %d\n", -errno); return -errno; + } - int bytes = smbc_read (fi->fh, buff, len); - return (bytes < 0) ? -errno : bytes; + size_t got = 0; + int bytes = 0; + + // seems that reads of > 32768 bytes don't work with real Windows servers + while (got < len) + { + bytes = smbc_read (fi->fh, buff, (len > 32768) ? 32768 : len); + + if (bytes < 0) + break; + + got += bytes; + buff += bytes; + + // avoids infinite loops + if (0 == bytes) + break; + } + + DEBUG (fprintf (stderr, " = %d\n", (bytes < 0) ? -errno : (int)got)); + return (bytes < 0) ? -errno : (int)got; } @@ -115,8 +137,28 @@ int usmb_write (const char *filename, const char *buff, size_t len, off_t off, if (smbc_lseek (fi->fh, off, SEEK_SET) < 0) return -errno; - int bytes = smbc_write (fi->fh, (char *)buff, len); - return (bytes < 0) ? -errno : bytes; + size_t written = 0; + int bytes = 0; + + // No idea whether Windows servers don't like > 32768 byte writes + // (cf. usmb_read), but taking no chances... + while (written < len) + { + bytes = smbc_write (fi->fh, (char *)buff, (len > 32768) ? 32768 : len); + + if (bytes < 0) + break; + + written += bytes; + buff += bytes; + + // avoids infinite loops + if (0 == bytes) + break; + } + + DEBUG (fprintf (stderr, " = %d\n", (bytes < 0) ? -errno : (int)written)); + return (bytes < 0) ? -errno : (int)written; }