Implemented truncation to the file's current size (for OpenOffice). Added erroeously omitted make_url() return check in getattr(). Fixed memory leak in getattr(). Version 20080421. - 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 74f8aa75a21a15d0a9bd036ce850b65c210fa7ee
 (DIR) parent 3947905896338d7572fe97a22fe6d53038966cb0
 (HTM) Author: Geoff Johnstone <geoffSHEEP.johnstoneFROG@googlemail.com>
       Date:   Mon, 21 Apr 2008 21:35:58 +0100
       
       Implemented truncation to the file's current size (for OpenOffice).
       Added erroeously omitted make_url() return check in getattr().
       Fixed memory leak in getattr().
       Version 20080421.
       
       Diffstat:
         M usmb.c                              |      14 +++++++-------
         M usmb_file.c                         |      52 ++++++++++++++++++++++---------
         M version.h                           |       2 +-
       
       3 files changed, 46 insertions(+), 22 deletions(-)
       ---
 (DIR) diff --git a/usmb.c b/usmb.c
       @@ -106,15 +106,15 @@ static bool create_smb_context (char *domain, char *username, SMBCCTX **pctx)
        #if 0
        static int usmb_statfs (const char *path, struct statvfs *vfs)
        {
       -        if ((NULL == path) || (NULL == vfs))
       -                return -EINVAL;
       +  if ((NULL == path) || (NULL == vfs))
       +    return -EINVAL;
        
       -        memset (vfs, 0, sizeof (*vfs));
       +  memset (vfs, 0, sizeof (*vfs));
        
       -        vfs->f_bsize = 32768;
       -        vfs->f_blocks = 0x7FFFFFFFl;
       -        vfs->f_bfree = 0x7FFFFFFFl;
       -        vfs->f_bavail = 0x7FFFFFFFl;
       +  vfs->f_bsize = 32768;
       +  vfs->f_blocks = 0x7FFFFFFFl;
       +  vfs->f_bfree = 0x7FFFFFFFl;
       +  vfs->f_bavail = 0x7FFFFFFFl;
        
          return 0;
        }
 (DIR) diff --git a/usmb_file.c b/usmb_file.c
       @@ -31,6 +31,9 @@
        int usmb_getattr (const char *filename, struct stat *st)
        {
          char *url = make_url (filename);
       +  if (NULL == url)
       +    return -ENOMEM;
       +
          DEBUG (fprintf (stderr, "stat (%s)\n", url));
        
          int ret = ctx->stat (ctx, url, st);
       @@ -247,24 +250,45 @@ int usmb_utimes (const char *filename, const struct timespec ts[2])
        #endif
        
        
       -int usmb_truncate (const char *filename, off_t newsize)
       +int usmb_truncate (const char *filename, off_t offset)
        {
       -  DEBUG (fprintf (stderr, "truncate (%s, %llu)\n", filename, newsize));
       -  // FIXME: TODO: handle newsize != 0
       -  if (0 != newsize)
       -    return -ENOSYS;
       +  /* Windows doesn't support truncation so we implement a limited version:
       +   *  0 == offset => create a new file for writing.
       +   *  current size == offset => succeed.
       +   *  else return -ENOSYS.
       +   */
        
       -  char *url = make_url (filename);
       -  if (NULL == url)
       -    return -ENOMEM;
       +  DEBUG (fprintf (stderr, "truncate (%s, %llu)\n", filename, offset));
       +
       +  if (NULL == filename)
       +    return -EINVAL;
       +
       +  if (0 == offset)
       +  {
       +    char *url = make_url (filename);
       +    if (NULL == url)
       +      return -ENOMEM;
          
       -  DEBUG (fprintf (stderr, "truncate (%s)\n", url));
       -  SMBCFILE *file = ctx->open (ctx, url, O_WRONLY | O_TRUNC, 0);
       -  if (NULL == file)
       -    return -errno;
       +    SMBCFILE *file = ctx->open (ctx, url, O_WRONLY | O_TRUNC, 0);
       +    if (NULL == file)
       +    {
       +      free (url);
       +      return -errno;
       +    }
          
       -  ctx->close_fn (ctx, file);
       -  return 0;
       +    ctx->close_fn (ctx, file);
       +    free (url);
       +
       +    return 0;
       +  }
       +
       +  struct stat st;
       +  int ret = usmb_getattr (filename, &st);
       +
       +  if (0 != ret)
       +    return ret;
       +
       +  return (offset == st.st_size) ? 0 : -ENOSYS;
        }
        
        
 (DIR) diff --git a/version.h b/version.h
       @@ -19,7 +19,7 @@
        
          #include <stdio.h>
        
       -  #define USMB_VERSION 0x20080419
       +  #define USMB_VERSION 0x20080421
        
          // a - alpha, b - beta, p - pre-release, s - stable
          #define USMB_VERSION_STATUS 's'