Remove redundant parameter fd from SMB_VFS_LSEEK().
[ira/wip.git] / source / torture / cmd_vfs.c
index f74fcedcf49f3a6065cd10319b25cc847c6b205c..e595ac9f8b6d345fa52871c20b1b5926a78ec75b 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"
@@ -54,7 +53,7 @@ static NTSTATUS cmd_populate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int arg
        }
        c = argv[1][0];
        size = atoi(argv[2]);
-       vfs->data = (char *)talloc(mem_ctx, size);
+       vfs->data = TALLOC_ARRAY(mem_ctx, char, size);
        if (vfs->data == NULL) {
                printf("populate: error=-1 (not enough memory)");
                return NT_STATUS_UNSUCCESSFUL;
@@ -88,13 +87,13 @@ static NTSTATUS cmd_show_data(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
                printf("show_data: error=-1 (not enough data in buffer)\n");
                return NT_STATUS_UNSUCCESSFUL;
        }
-       dump_data(0, (char *)(vfs->data) + offset, len);
+       dump_data(0, (uint8 *)(vfs->data) + offset, len);
        return NT_STATUS_OK;
 }
 
 static NTSTATUS cmd_connect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       SMB_VFS_CONNECT(vfs->conn, lp_servicename(vfs->conn->service), "vfstest");
+       SMB_VFS_CONNECT(vfs->conn, lp_servicename(SNUM(vfs->conn)), "vfstest");
        return NT_STATUS_OK;
 }
 
@@ -129,7 +128,7 @@ static NTSTATUS cmd_opendir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc
                return NT_STATUS_OK;
        }
 
-       vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, argv[1]);
+       vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, argv[1], NULL, 0);
        if (vfs->currentdir == NULL) {
                printf("opendir error=%d (%s)\n", errno, strerror(errno));
                return NT_STATUS_UNSUCCESSFUL;
@@ -142,7 +141,7 @@ static NTSTATUS cmd_opendir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc
 
 static NTSTATUS cmd_readdir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       struct dirent *dent;
+       SMB_STRUCT_DIRENT *dent;
 
        if (vfs->currentdir == NULL) {
                printf("readdir: error=-1 (no open directory)\n");
@@ -200,9 +199,10 @@ static NTSTATUS cmd_closedir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int arg
 
 static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       int flags, fd;
+       int flags;
        mode_t mode;
        const char *flagstr;
+       files_struct *fsp;
 
        mode = 00400;
 
@@ -278,17 +278,21 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
                }
        }
 
-       fd = SMB_VFS_OPEN(vfs->conn, argv[1], flags, mode);
-       if (fd == -1) {
+       fsp = SMB_MALLOC_P(struct files_struct);
+       fsp->fsp_name = SMB_STRDUP(argv[1]);
+       fsp->fh = SMB_MALLOC_P(struct fd_handle);
+       fsp->conn = vfs->conn;
+
+       fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, argv[1], fsp, flags, mode);
+       if (fsp->fh->fd == -1) {
                printf("open: error=%d (%s)\n", errno, strerror(errno));
+               SAFE_FREE(fsp->fh);
+               SAFE_FREE(fsp);
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       vfs->files[fd] = (struct files_struct *)malloc(sizeof(struct files_struct));
-       vfs->files[fd]->fsp_name = strdup(argv[1]);
-       vfs->files[fd]->fd = fd;
-       vfs->files[fd]->conn = vfs->conn;
-       printf("open: fd=%d\n", fd);
+       vfs->files[fsp->fh->fd] = fsp;
+       printf("open: fd=%d\n", fsp->fh->fd);
        return NT_STATUS_OK;
 }
 
@@ -345,6 +349,7 @@ static NTSTATUS cmd_close(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                printf("close: ok\n");
 
        SAFE_FREE(vfs->files[fd]->fsp_name);
+       SAFE_FREE(vfs->files[fd]->fh);
        SAFE_FREE(vfs->files[fd]);
        vfs->files[fd] = NULL;
        return NT_STATUS_OK;
@@ -364,7 +369,7 @@ static NTSTATUS cmd_read(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
        /* do some error checking on these */
        fd = atoi(argv[1]);
        size = atoi(argv[2]);
-       vfs->data = (char *)talloc(mem_ctx, size);
+       vfs->data = TALLOC_ARRAY(mem_ctx, char, size);
        if (vfs->data == NULL) {
                printf("read: error=-1 (not enough memory)");
                return NT_STATUS_UNSUCCESSFUL;
@@ -435,7 +440,7 @@ static NTSTATUS cmd_lseek(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                default:        whence = SEEK_END;
        }
 
-       pos = SMB_VFS_LSEEK(vfs->files[fd], fd, offset, whence);
+       pos = SMB_VFS_LSEEK(vfs->files[fd], offset, whence);
        if (pos == (SMB_OFF_T)-1) {
                printf("lseek: error=%d (%s)\n", errno, strerror(errno));
                return NT_STATUS_UNSUCCESSFUL;
@@ -490,8 +495,8 @@ static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
        int ret;
        const char *user;
        const char *group;
-       struct passwd *pwd;
-       struct group *grp;
+       struct passwd *pwd = NULL;
+       struct group *grp = NULL;
        SMB_STRUCT_STAT st;
 
        if (argc != 2) {
@@ -522,18 +527,22 @@ static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
        else if (S_ISLNK(st.st_mode)) printf("  Symbolic Link\n");
        else if (S_ISSOCK(st.st_mode)) printf("  Socket\n");
        printf("  Size: %10u", (unsigned int)st.st_size);
+#ifdef HAVE_STAT_ST_BLOCKS
        printf(" Blocks: %9u", (unsigned int)st.st_blocks);
+#endif
+#ifdef HAVE_STAT_ST_BLKSIZE
        printf(" IO Block: %u\n", (unsigned int)st.st_blksize);
+#endif
        printf("  Device: 0x%10x", (unsigned int)st.st_dev);
        printf(" Inode: %10u", (unsigned int)st.st_ino);
        printf(" Links: %10u\n", (unsigned int)st.st_nlink);
        printf("  Access: %05o", (st.st_mode) & 007777);
-       printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group);
+       printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user, 
+              (unsigned long)st.st_gid, group);
        printf("  Access: %s", ctime(&(st.st_atime)));
        printf("  Modify: %s", ctime(&(st.st_mtime)));
        printf("  Change: %s", ctime(&(st.st_ctime)));
-       SAFE_FREE(pwd);
-       SAFE_FREE(grp);
+
        return NT_STATUS_OK;
 }
 
@@ -543,8 +552,8 @@ static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        int fd;
        const char *user;
        const char *group;
-       struct passwd *pwd;
-       struct group *grp;
+       struct passwd *pwd = NULL;
+       struct group *grp = NULL;
        SMB_STRUCT_STAT st;
 
        if (argc != 2) {
@@ -584,18 +593,22 @@ static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        else if (S_ISLNK(st.st_mode)) printf("  Symbolic Link\n");
        else if (S_ISSOCK(st.st_mode)) printf("  Socket\n");
        printf("  Size: %10u", (unsigned int)st.st_size);
+#ifdef HAVE_STAT_ST_BLOCKS
        printf(" Blocks: %9u", (unsigned int)st.st_blocks);
+#endif
+#ifdef HAVE_STAT_ST_BLKSIZE
        printf(" IO Block: %u\n", (unsigned int)st.st_blksize);
+#endif
        printf("  Device: 0x%10x", (unsigned int)st.st_dev);
        printf(" Inode: %10u", (unsigned int)st.st_ino);
        printf(" Links: %10u\n", (unsigned int)st.st_nlink);
        printf("  Access: %05o", (st.st_mode) & 007777);
-       printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group);
+       printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user, 
+              (unsigned long)st.st_gid, group);
        printf("  Access: %s", ctime(&(st.st_atime)));
        printf("  Modify: %s", ctime(&(st.st_mtime)));
        printf("  Change: %s", ctime(&(st.st_ctime)));
-       SAFE_FREE(pwd);
-       SAFE_FREE(grp);
+
        return NT_STATUS_OK;
 }
 
@@ -604,8 +617,8 @@ static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 {
        const char *user;
        const char *group;
-       struct passwd *pwd;
-       struct group *grp;
+       struct passwd *pwd = NULL;
+       struct group *grp = NULL;
        SMB_STRUCT_STAT st;
 
        if (argc != 2) {
@@ -634,18 +647,22 @@ static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        else if (S_ISLNK(st.st_mode)) printf("  Symbolic Link\n");
        else if (S_ISSOCK(st.st_mode)) printf("  Socket\n");
        printf("  Size: %10u", (unsigned int)st.st_size);
+#ifdef HAVE_STAT_ST_BLOCKS
        printf(" Blocks: %9u", (unsigned int)st.st_blocks);
+#endif
+#ifdef HAVE_STAT_ST_BLKSIZE
        printf(" IO Block: %u\n", (unsigned int)st.st_blksize);
+#endif
        printf("  Device: 0x%10x", (unsigned int)st.st_dev);
        printf(" Inode: %10u", (unsigned int)st.st_ino);
        printf(" Links: %10u\n", (unsigned int)st.st_nlink);
        printf("  Access: %05o", (st.st_mode) & 007777);
-       printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group);
+       printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user, 
+              (unsigned long)st.st_gid, group);
        printf("  Access: %s", ctime(&(st.st_atime)));
        printf("  Modify: %s", ctime(&(st.st_mtime)));
        printf("  Change: %s", ctime(&(st.st_ctime)));
-       SAFE_FREE(pwd);
-       SAFE_FREE(grp);
+       
        return NT_STATUS_OK;
 }
 
@@ -765,14 +782,14 @@ static NTSTATUS cmd_getwd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 
 static NTSTATUS cmd_utime(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       struct utimbuf times;
+       struct timespec ts[2];
        if (argc != 4) {
                printf("Usage: utime <path> <access> <modify>\n");
                return NT_STATUS_OK;
        }
-       times.actime = atoi(argv[2]);
-       times.modtime = atoi(argv[3]);
-       if (SMB_VFS_UTIME(vfs->conn, argv[1], &times) != 0) {
+       ts[0] = convert_time_t_to_timespec(atoi(argv[2]));
+       ts[1] = convert_time_t_to_timespec(atoi(argv[3]));
+       if (SMB_VFS_NTIMES(vfs->conn, argv[1], ts) != 0) {
                printf("utime: error=%d (%s)\n", errno, strerror(errno));
                return NT_STATUS_UNSUCCESSFUL;
        }
@@ -812,7 +829,7 @@ static NTSTATUS cmd_ftruncate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
 
 static NTSTATUS cmd_lock(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       BOOL ret;
+       bool ret;
        int fd;
        int op;
        long offset;