add a function to truncate a file to a specified size
authorDerrell Lipman <derrell.lipman@unwireduniverse.com>
Wed, 27 Feb 2008 02:42:26 +0000 (21:42 -0500)
committerDerrell Lipman <derrell.lipman@unwireduniverse.com>
Wed, 27 Feb 2008 02:42:26 +0000 (21:42 -0500)
(This used to be commit 7e5752812d6d9e3bcf9a545cbdcf3afe2175dbc4)

source3/libsmb/clifile.c

index 10c35a30cc84c990ed6044c0065e0f907c7cfee2..12c427a6fa655b2013e8cfbfeac6e28c212fa0b0 100644 (file)
@@ -888,6 +888,55 @@ bool cli_close(struct cli_state *cli, int fnum)
 }
 
 
+/****************************************************************************
+ Truncate a file to a specified size
+****************************************************************************/
+
+bool cli_ftruncate(struct cli_state *cli, int fnum, uint64_t size)
+{
+       unsigned int param_len = 6;
+       unsigned int data_len = 8;
+       uint16 setup = TRANSACT2_SETFILEINFO;
+       char param[6];
+       unsigned char data[8];
+       char *rparam=NULL, *rdata=NULL;
+       int saved_timeout = cli->timeout;
+
+       SSVAL(param,0,fnum);
+       SSVAL(param,2,SMB_SET_FILE_END_OF_FILE_INFO);
+       SSVAL(param,4,0);
+
+        SBVAL(data, 0, size);
+
+       if (!cli_send_trans(cli, SMBtrans2,
+                            NULL,                    /* name */
+                            -1, 0,                   /* fid, flags */
+                            &setup, 1, 0,            /* setup, length, max */
+                            param, param_len, 2,     /* param, length, max */
+                            (char *)&data,  data_len,/* data, length, ... */
+                            cli->max_xmit)) {        /* ... max */
+               cli->timeout = saved_timeout;
+               return False;
+       }
+
+       if (!cli_receive_trans(cli, SMBtrans2,
+                               &rparam, &param_len,
+                               &rdata, &data_len)) {
+               cli->timeout = saved_timeout;
+               SAFE_FREE(rdata);
+               SAFE_FREE(rparam);
+               return False;
+       }
+
+       cli->timeout = saved_timeout;
+
+       SAFE_FREE(rdata);
+       SAFE_FREE(rparam);
+
+       return True;
+}
+
+
 /****************************************************************************
  send a lock with a specified locktype
  this is used for testing LOCKING_ANDX_CANCEL_LOCK