display_sec: Move to common libcli/security directory.
[ira/wip.git] / source4 / libcli / clifile.c
index 3acd215f3ea9a910a14a5a0631a64742d25071cb..2cf174060b7bf33d06d4f660524cb1427ef2bb15 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -31,7 +30,7 @@
 
 static NTSTATUS smbcli_link_internal(struct smbcli_tree *tree, 
                                  const char *fname_src, 
-                                 const char *fname_dst, BOOL hard_link)
+                                 const char *fname_dst, bool hard_link)
 {
        union smb_setfileinfo parms;
        NTSTATUS status;
@@ -85,7 +84,7 @@ uint32_t unix_perms_to_wire(mode_t perms)
 NTSTATUS smbcli_unix_symlink(struct smbcli_tree *tree, const char *fname_src, 
                          const char *fname_dst)
 {
-       return smbcli_link_internal(tree, fname_src, fname_dst, False);
+       return smbcli_link_internal(tree, fname_src, fname_dst, false);
 }
 
 /****************************************************************************
@@ -94,7 +93,7 @@ NTSTATUS smbcli_unix_symlink(struct smbcli_tree *tree, const char *fname_src,
 NTSTATUS smbcli_unix_hardlink(struct smbcli_tree *tree, const char *fname_src, 
                           const char *fname_dst)
 {
-       return smbcli_link_internal(tree, fname_src, fname_dst, True);
+       return smbcli_link_internal(tree, fname_src, fname_dst, true);
 }
 
 
@@ -207,7 +206,8 @@ NTSTATUS smbcli_rmdir(struct smbcli_tree *tree, const char *dname)
 /****************************************************************************
  Set or clear the delete on close flag.
 ****************************************************************************/
-NTSTATUS smbcli_nt_delete_on_close(struct smbcli_tree *tree, int fnum, BOOL flag)
+NTSTATUS smbcli_nt_delete_on_close(struct smbcli_tree *tree, int fnum, 
+                                  bool flag)
 {
        union smb_setfileinfo parms;
        NTSTATUS status;
@@ -576,16 +576,13 @@ NTSTATUS smbcli_setatr(struct smbcli_tree *tree, const char *fname, uint16_t mod
                    time_t t)
 {
        union smb_setfileinfo parms;
-       NTSTATUS status;
 
        parms.setattr.level = RAW_SFILEINFO_SETATTR;
        parms.setattr.in.file.path = fname;
        parms.setattr.in.attrib = mode;
        parms.setattr.in.write_time = t;
        
-       status = smb_raw_setpathinfo(tree, &parms);
-
-       return status;
+       return smb_raw_setpathinfo(tree, &parms);
 }
 
 /****************************************************************************
@@ -596,7 +593,6 @@ NTSTATUS smbcli_fsetatr(struct smbcli_tree *tree, int fnum, uint16_t mode,
                        NTTIME write_time, NTTIME change_time)
 {
        union smb_setfileinfo parms;
-       NTSTATUS status;
 
        parms.basic_info.level = RAW_SFILEINFO_BASIC_INFO;
        parms.basic_info.in.file.fnum = fnum;
@@ -606,9 +602,22 @@ NTSTATUS smbcli_fsetatr(struct smbcli_tree *tree, int fnum, uint16_t mode,
        parms.basic_info.in.write_time = write_time;
        parms.basic_info.in.change_time = change_time;
        
-       status = smb_raw_setfileinfo(tree, &parms);
+       return smb_raw_setfileinfo(tree, &parms);
+}
 
-       return status;
+
+/****************************************************************************
+ truncate a file to a given size
+****************************************************************************/
+NTSTATUS smbcli_ftruncate(struct smbcli_tree *tree, int fnum, uint64_t size)
+{
+       union smb_setfileinfo parms;
+
+       parms.end_of_file_info.level = RAW_SFILEINFO_END_OF_FILE_INFO;
+       parms.end_of_file_info.in.file.fnum = fnum;
+       parms.end_of_file_info.in.size = size;
+       
+       return smb_raw_setfileinfo(tree, &parms);
 }
 
 
@@ -641,7 +650,8 @@ NTSTATUS smbcli_chkpath(struct smbcli_tree *tree, const char *path)
 /****************************************************************************
  Query disk space.
 ****************************************************************************/
-NTSTATUS smbcli_dskattr(struct smbcli_tree *tree, int *bsize, int *total, int *avail)
+NTSTATUS smbcli_dskattr(struct smbcli_tree *tree, uint32_t *bsize, 
+                       uint64_t *total, uint64_t *avail)
 {
        union smb_fsinfo fsinfo_parms;
        TALLOC_CTX *mem_ctx;
@@ -649,12 +659,12 @@ NTSTATUS smbcli_dskattr(struct smbcli_tree *tree, int *bsize, int *total, int *a
 
        mem_ctx = talloc_init("smbcli_dskattr");
 
-       fsinfo_parms.dskattr.level = RAW_QFS_DSKATTR;
+       fsinfo_parms.dskattr.level = RAW_QFS_SIZE_INFO;
        status = smb_raw_fsinfo(tree, mem_ctx, &fsinfo_parms);
        if (NT_STATUS_IS_OK(status)) {
-               *bsize = fsinfo_parms.dskattr.out.block_size;
-               *total = fsinfo_parms.dskattr.out.units_total;
-               *avail = fsinfo_parms.dskattr.out.units_free;
+               *bsize = fsinfo_parms.size_info.out.bytes_per_sector * fsinfo_parms.size_info.out.sectors_per_unit;
+               *total = fsinfo_parms.size_info.out.total_alloc_units;
+               *avail = fsinfo_parms.size_info.out.avail_alloc_units;
        }
 
        talloc_free(mem_ctx);