summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorDerrell Lipman <derrell.lipman@unwireduniverse.com>2008-02-26 21:42:26 -0500
committerDerrell Lipman <derrell.lipman@unwireduniverse.com>2008-02-26 21:42:26 -0500
commitc58e7427bf7200ad413c259f429f020b98d723ec (patch)
treeeda1b3064dcd1c25c2d7fc229a79a72173458f3d /source3/libsmb
parentd85c517b45b8feb8469f7073d770e7fedc818259 (diff)
downloadsamba-c58e7427bf7200ad413c259f429f020b98d723ec.tar.gz
samba-c58e7427bf7200ad413c259f429f020b98d723ec.tar.bz2
samba-c58e7427bf7200ad413c259f429f020b98d723ec.zip
add a function to truncate a file to a specified size
(This used to be commit 7e5752812d6d9e3bcf9a545cbdcf3afe2175dbc4)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clifile.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 10c35a30cc..12c427a6fa 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -889,6 +889,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
****************************************************************************/