2 Unix SMB/CIFS implementation.
5 Copyright (C) Simo Sorce 2002
6 Copyright (C) Eric Lorimer 2002
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 static const char *null_string
= "";
28 static NTSTATUS
cmd_load_module(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
33 printf("Usage: load <modules>\n");
37 for (i
=argc
-1;i
>0;i
--) {
38 if (!vfs_init_custom(vfs
->conn
, argv
[i
])) {
39 DEBUG(0, ("load: (vfs_init_custom failed for %s)\n", argv
[i
]));
40 return NT_STATUS_UNSUCCESSFUL
;
47 static NTSTATUS
cmd_populate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
52 printf("Usage: populate <char> <size>\n");
57 vfs
->data
= (char *)talloc(mem_ctx
, size
);
58 if (vfs
->data
== NULL
) {
59 printf("populate: error=-1 (not enough memory)");
60 return NT_STATUS_UNSUCCESSFUL
;
62 memset(vfs
->data
, c
, size
);
63 vfs
->data_size
= size
;
67 static NTSTATUS
cmd_show_data(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
71 if (argc
!= 1 && argc
!= 3) {
72 printf("Usage: showdata [<offset> <len>]\n");
75 if (vfs
->data
== NULL
|| vfs
->data_size
== 0) {
76 printf("show_data: error=-1 (buffer empty)\n");
77 return NT_STATUS_UNSUCCESSFUL
;
81 offset
= atoi(argv
[1]);
87 if ((offset
+ len
) > vfs
->data_size
) {
88 printf("show_data: error=-1 (not enough data in buffer)\n");
89 return NT_STATUS_UNSUCCESSFUL
;
91 dump_data(0, (char *)(vfs
->data
) + offset
, len
);
95 static NTSTATUS
cmd_connect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
97 SMB_VFS_CONNECT(vfs
->conn
, lp_servicename(vfs
->conn
->service
), "vfstest");
101 static NTSTATUS
cmd_disconnect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
103 SMB_VFS_DISCONNECT(vfs
->conn
);
107 static NTSTATUS
cmd_disk_free(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
109 SMB_BIG_UINT diskfree
, bsize
, dfree
, dsize
;
111 printf("Usage: disk_free <path>\n");
115 diskfree
= SMB_VFS_DISK_FREE(vfs
->conn
, argv
[1], False
, &bsize
, &dfree
, &dsize
);
116 printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n",
117 (unsigned long)diskfree
,
118 (unsigned long)bsize
,
119 (unsigned long)dfree
,
120 (unsigned long)dsize
);
125 static NTSTATUS
cmd_opendir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
128 printf("Usage: opendir <fname>\n");
132 vfs
->currentdir
= SMB_VFS_OPENDIR(vfs
->conn
, argv
[1]);
133 if (vfs
->currentdir
== NULL
) {
134 printf("opendir error=%d (%s)\n", errno
, strerror(errno
));
135 return NT_STATUS_UNSUCCESSFUL
;
138 printf("opendir: ok\n");
143 static NTSTATUS
cmd_readdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
147 if (vfs
->currentdir
== NULL
) {
148 printf("readdir: error=-1 (no open directory)\n");
149 return NT_STATUS_UNSUCCESSFUL
;
152 dent
= SMB_VFS_READDIR(vfs
->conn
, vfs
->currentdir
);
154 printf("readdir: NULL\n");
158 printf("readdir: %s\n", dent
->d_name
);
163 static NTSTATUS
cmd_mkdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
166 printf("Usage: mkdir <path>\n");
170 if (SMB_VFS_MKDIR(vfs
->conn
, argv
[1], 00755) == -1) {
171 printf("mkdir error=%d (%s)\n", errno
, strerror(errno
));
172 return NT_STATUS_UNSUCCESSFUL
;
175 printf("mkdir: ok\n");
180 static NTSTATUS
cmd_closedir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
184 if (vfs
->currentdir
== NULL
) {
185 printf("closedir: failure (no directory open)\n");
186 return NT_STATUS_UNSUCCESSFUL
;
189 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
191 printf("closedir failure: %s\n", strerror(errno
));
192 return NT_STATUS_UNSUCCESSFUL
;
195 printf("closedir: ok\n");
196 vfs
->currentdir
= NULL
;
201 static NTSTATUS
cmd_open(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
209 if (argc
< 3 || argc
> 5) {
210 printf("Usage: open <filename> <flags> <mode>\n");
211 printf(" flags: O = O_RDONLY\n");
212 printf(" R = O_RDWR\n");
213 printf(" W = O_WRONLY\n");
214 printf(" C = O_CREAT\n");
215 printf(" E = O_EXCL\n");
216 printf(" T = O_TRUNC\n");
217 printf(" A = O_APPEND\n");
218 printf(" N = O_NONBLOCK/O_NDELAY\n");
220 printf(" S = O_SYNC\n");
223 printf(" F = O_NOFOLLOW\n");
225 printf(" mode: see open.2\n");
226 printf(" mode is ignored if C flag not present\n");
227 printf(" mode defaults to 00400\n");
269 printf("open: error=-1 (invalid flag!)\n");
270 return NT_STATUS_UNSUCCESSFUL
;
274 if ((flags
& O_CREAT
) && argc
== 4) {
275 if (sscanf(argv
[3], "%o", &mode
) == 0) {
276 printf("open: error=-1 (invalid mode!)\n");
277 return NT_STATUS_UNSUCCESSFUL
;
281 fd
= SMB_VFS_OPEN(vfs
->conn
, argv
[1], flags
, mode
);
283 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
284 return NT_STATUS_UNSUCCESSFUL
;
287 vfs
->files
[fd
] = (struct files_struct
*)malloc(sizeof(struct files_struct
));
288 vfs
->files
[fd
]->fsp_name
= strdup(argv
[1]);
289 vfs
->files
[fd
]->fd
= fd
;
290 vfs
->files
[fd
]->conn
= vfs
->conn
;
291 printf("open: fd=%d\n", fd
);
296 static NTSTATUS
cmd_pathfunc(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
301 printf("Usage: %s <path>\n", argv
[0]);
305 if (strcmp("rmdir", argv
[0]) == 0 ) {
306 ret
= SMB_VFS_RMDIR(vfs
->conn
, argv
[1]);
307 } else if (strcmp("unlink", argv
[0]) == 0 ) {
308 ret
= SMB_VFS_UNLINK(vfs
->conn
, argv
[1]);
309 } else if (strcmp("chdir", argv
[0]) == 0 ) {
310 ret
= SMB_VFS_CHDIR(vfs
->conn
, argv
[1]);
312 printf("%s: error=%d (invalid function name!)\n", argv
[0], errno
);
313 return NT_STATUS_UNSUCCESSFUL
;
317 printf("%s: error=%d (%s)\n", argv
[0], errno
, strerror(errno
));
318 return NT_STATUS_UNSUCCESSFUL
;
321 printf("%s: ok\n", argv
[0]);
326 static NTSTATUS
cmd_close(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
331 printf("Usage: close <fd>\n");
336 if (vfs
->files
[fd
] == NULL
) {
337 printf("close: error=-1 (invalid file descriptor)\n");
341 ret
= SMB_VFS_CLOSE(vfs
->files
[fd
], fd
);
343 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
345 printf("close: ok\n");
347 SAFE_FREE(vfs
->files
[fd
]->fsp_name
);
348 SAFE_FREE(vfs
->files
[fd
]);
349 vfs
->files
[fd
] = NULL
;
354 static NTSTATUS
cmd_read(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
360 printf("Usage: read <fd> <size>\n");
364 /* do some error checking on these */
366 size
= atoi(argv
[2]);
367 vfs
->data
= (char *)talloc(mem_ctx
, size
);
368 if (vfs
->data
== NULL
) {
369 printf("read: error=-1 (not enough memory)");
370 return NT_STATUS_UNSUCCESSFUL
;
372 vfs
->data_size
= size
;
374 rsize
= SMB_VFS_READ(vfs
->files
[fd
], fd
, vfs
->data
, size
);
376 printf("read: error=%d (%s)\n", errno
, strerror(errno
));
377 return NT_STATUS_UNSUCCESSFUL
;
380 printf("read: ok\n");
385 static NTSTATUS
cmd_write(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
390 printf("Usage: write <fd> <size>\n");
394 /* some error checking should go here */
396 size
= atoi(argv
[2]);
397 if (vfs
->data
== NULL
) {
398 printf("write: error=-1 (buffer empty, please populate it before writing)");
399 return NT_STATUS_UNSUCCESSFUL
;
402 if (vfs
->data_size
< size
) {
403 printf("write: error=-1 (buffer too small, please put some more data in)");
404 return NT_STATUS_UNSUCCESSFUL
;
407 wsize
= SMB_VFS_WRITE(vfs
->files
[fd
], fd
, vfs
->data
, size
);
410 printf("write: error=%d (%s)\n", errno
, strerror(errno
));
411 return NT_STATUS_UNSUCCESSFUL
;
414 printf("write: ok\n");
419 static NTSTATUS
cmd_lseek(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
421 int fd
, offset
, whence
;
425 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
430 offset
= atoi(argv
[2]);
431 whence
= atoi(argv
[3]);
433 case 1: whence
= SEEK_SET
; break;
434 case 2: whence
= SEEK_CUR
; break;
435 default: whence
= SEEK_END
;
438 pos
= SMB_VFS_LSEEK(vfs
->files
[fd
], fd
, offset
, whence
);
439 if (pos
== (SMB_OFF_T
)-1) {
440 printf("lseek: error=%d (%s)\n", errno
, strerror(errno
));
441 return NT_STATUS_UNSUCCESSFUL
;
444 printf("lseek: ok\n");
449 static NTSTATUS
cmd_rename(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
453 printf("Usage: rename <old> <new>\n");
457 ret
= SMB_VFS_RENAME(vfs
->conn
, argv
[1], argv
[2]);
459 printf("rename: error=%d (%s)\n", errno
, strerror(errno
));
460 return NT_STATUS_UNSUCCESSFUL
;
463 printf("rename: ok\n");
468 static NTSTATUS
cmd_fsync(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
472 printf("Usage: fsync <fd>\n");
477 ret
= SMB_VFS_FSYNC(vfs
->files
[fd
], fd
);
479 printf("fsync: error=%d (%s)\n", errno
, strerror(errno
));
480 return NT_STATUS_UNSUCCESSFUL
;
483 printf("fsync: ok\n");
488 static NTSTATUS
cmd_stat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
493 struct passwd
*pwd
= NULL
;
494 struct group
*grp
= NULL
;
498 printf("Usage: stat <fname>\n");
502 ret
= SMB_VFS_STAT(vfs
->conn
, argv
[1], &st
);
504 printf("stat: error=%d (%s)\n", errno
, strerror(errno
));
505 return NT_STATUS_UNSUCCESSFUL
;
508 pwd
= sys_getpwuid(st
.st_uid
);
509 if (pwd
!= NULL
) user
= pwd
->pw_name
;
510 else user
= null_string
;
511 grp
= sys_getgrgid(st
.st_gid
);
512 if (grp
!= NULL
) group
= grp
->gr_name
;
513 else group
= null_string
;
515 printf("stat: ok\n");
516 printf(" File: %s", argv
[1]);
517 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
518 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
519 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
520 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
521 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
522 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
523 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
524 printf(" Size: %10u", (unsigned int)st
.st_size
);
525 #ifdef HAVE_STAT_ST_BLOCKS
526 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
528 #ifdef HAVE_STAT_ST_BLKSIZE
529 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
531 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
532 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
533 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
534 printf(" Access: %05o", (st
.st_mode
) & 007777);
535 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
536 (unsigned long)st
.st_gid
, group
);
537 printf(" Access: %s", ctime(&(st
.st_atime
)));
538 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
539 printf(" Change: %s", ctime(&(st
.st_ctime
)));
547 static NTSTATUS
cmd_fstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
552 struct passwd
*pwd
= NULL
;
553 struct group
*grp
= NULL
;
557 printf("Usage: fstat <fd>\n");
562 if (fd
< 0 || fd
> 1024) {
563 printf("fstat: error=%d (file descriptor out of range)\n", EBADF
);
567 if (vfs
->files
[fd
] == NULL
) {
568 printf("fstat: error=%d (invalid file descriptor)\n", EBADF
);
572 if (SMB_VFS_FSTAT(vfs
->files
[fd
], fd
, &st
) == -1) {
573 printf("fstat: error=%d (%s)\n", errno
, strerror(errno
));
574 return NT_STATUS_UNSUCCESSFUL
;
577 pwd
= sys_getpwuid(st
.st_uid
);
578 if (pwd
!= NULL
) user
= pwd
->pw_name
;
579 else user
= null_string
;
580 grp
= sys_getgrgid(st
.st_gid
);
581 if (grp
!= NULL
) group
= grp
->gr_name
;
582 else group
= null_string
;
584 printf("fstat: ok\n");
585 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
586 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
587 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
588 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
589 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
590 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
591 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
592 printf(" Size: %10u", (unsigned int)st
.st_size
);
593 #ifdef HAVE_STAT_ST_BLOCKS
594 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
596 #ifdef HAVE_STAT_ST_BLKSIZE
597 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
599 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
600 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
601 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
602 printf(" Access: %05o", (st
.st_mode
) & 007777);
603 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
604 (unsigned long)st
.st_gid
, group
);
605 printf(" Access: %s", ctime(&(st
.st_atime
)));
606 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
607 printf(" Change: %s", ctime(&(st
.st_ctime
)));
615 static NTSTATUS
cmd_lstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
619 struct passwd
*pwd
= NULL
;
620 struct group
*grp
= NULL
;
624 printf("Usage: lstat <path>\n");
628 if (SMB_VFS_LSTAT(vfs
->conn
, argv
[1], &st
) == -1) {
629 printf("lstat: error=%d (%s)\n", errno
, strerror(errno
));
630 return NT_STATUS_UNSUCCESSFUL
;
633 pwd
= sys_getpwuid(st
.st_uid
);
634 if (pwd
!= NULL
) user
= pwd
->pw_name
;
635 else user
= null_string
;
636 grp
= sys_getgrgid(st
.st_gid
);
637 if (grp
!= NULL
) group
= grp
->gr_name
;
638 else group
= null_string
;
640 printf("lstat: ok\n");
641 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
642 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
643 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
644 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
645 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
646 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
647 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
648 printf(" Size: %10u", (unsigned int)st
.st_size
);
649 #ifdef HAVE_STAT_ST_BLOCKS
650 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
652 #ifdef HAVE_STAT_ST_BLKSIZE
653 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
655 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
656 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
657 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
658 printf(" Access: %05o", (st
.st_mode
) & 007777);
659 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
660 (unsigned long)st
.st_gid
, group
);
661 printf(" Access: %s", ctime(&(st
.st_atime
)));
662 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
663 printf(" Change: %s", ctime(&(st
.st_ctime
)));
671 static NTSTATUS
cmd_chmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
675 printf("Usage: chmod <path> <mode>\n");
679 mode
= atoi(argv
[2]);
680 if (SMB_VFS_CHMOD(vfs
->conn
, argv
[1], mode
) == -1) {
681 printf("chmod: error=%d (%s)\n", errno
, strerror(errno
));
682 return NT_STATUS_UNSUCCESSFUL
;
685 printf("chmod: ok\n");
690 static NTSTATUS
cmd_fchmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
695 printf("Usage: fchmod <fd> <mode>\n");
700 mode
= atoi(argv
[2]);
701 if (fd
< 0 || fd
> 1024) {
702 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF
);
705 if (vfs
->files
[fd
] == NULL
) {
706 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF
);
710 if (SMB_VFS_FCHMOD(vfs
->files
[fd
], fd
, mode
) == -1) {
711 printf("fchmod: error=%d (%s)\n", errno
, strerror(errno
));
712 return NT_STATUS_UNSUCCESSFUL
;
715 printf("fchmod: ok\n");
720 static NTSTATUS
cmd_chown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
725 printf("Usage: chown <path> <uid> <gid>\n");
731 if (SMB_VFS_CHOWN(vfs
->conn
, argv
[1], uid
, gid
) == -1) {
732 printf("chown: error=%d (%s)\n", errno
, strerror(errno
));
733 return NT_STATUS_UNSUCCESSFUL
;
736 printf("chown: ok\n");
741 static NTSTATUS
cmd_fchown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
747 printf("Usage: fchown <fd> <uid> <gid>\n");
754 if (fd
< 0 || fd
> 1024) {
755 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF
);
758 if (vfs
->files
[fd
] == NULL
) {
759 printf("fchown: error=%d (invalid file descriptor)\n", EBADF
);
762 if (SMB_VFS_FCHOWN(vfs
->files
[fd
], fd
, uid
, gid
) == -1) {
763 printf("fchown error=%d (%s)\n", errno
, strerror(errno
));
764 return NT_STATUS_UNSUCCESSFUL
;
767 printf("fchown: ok\n");
772 static NTSTATUS
cmd_getwd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
775 if (SMB_VFS_GETWD(vfs
->conn
, buf
) == NULL
) {
776 printf("getwd: error=%d (%s)\n", errno
, strerror(errno
));
777 return NT_STATUS_UNSUCCESSFUL
;
780 printf("getwd: %s\n", buf
);
784 static NTSTATUS
cmd_utime(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
786 struct utimbuf times
;
788 printf("Usage: utime <path> <access> <modify>\n");
791 times
.actime
= atoi(argv
[2]);
792 times
.modtime
= atoi(argv
[3]);
793 if (SMB_VFS_UTIME(vfs
->conn
, argv
[1], ×
) != 0) {
794 printf("utime: error=%d (%s)\n", errno
, strerror(errno
));
795 return NT_STATUS_UNSUCCESSFUL
;
798 printf("utime: ok\n");
802 static NTSTATUS
cmd_ftruncate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
807 printf("Usage: ftruncate <fd> <length>\n");
813 if (fd
< 0 || fd
> 1024) {
814 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF
);
817 if (vfs
->files
[fd
] == NULL
) {
818 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF
);
822 if (SMB_VFS_FTRUNCATE(vfs
->files
[fd
], fd
, off
) == -1) {
823 printf("ftruncate: error=%d (%s)\n", errno
, strerror(errno
));
824 return NT_STATUS_UNSUCCESSFUL
;
827 printf("ftruncate: ok\n");
831 static NTSTATUS
cmd_lock(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
842 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
843 printf(" ops: G = F_GETLK\n");
844 printf(" S = F_SETLK\n");
845 printf(" W = F_SETLKW\n");
846 printf(" type: R = F_RDLCK\n");
847 printf(" W = F_WRLCK\n");
848 printf(" U = F_UNLCK\n");
852 if (sscanf(argv
[1], "%d", &fd
) == 0) {
853 printf("lock: error=-1 (error parsing fd)\n");
854 return NT_STATUS_UNSUCCESSFUL
;
869 printf("lock: error=-1 (invalid op flag!)\n");
870 return NT_STATUS_UNSUCCESSFUL
;
873 if (sscanf(argv
[3], "%ld", &offset
) == 0) {
874 printf("lock: error=-1 (error parsing fd)\n");
875 return NT_STATUS_UNSUCCESSFUL
;
878 if (sscanf(argv
[4], "%ld", &count
) == 0) {
879 printf("lock: error=-1 (error parsing fd)\n");
880 return NT_STATUS_UNSUCCESSFUL
;
897 printf("lock: error=-1 (invalid type flag!)\n");
898 return NT_STATUS_UNSUCCESSFUL
;
903 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd
, op
, offset
, count
, type
);
905 if ((ret
= SMB_VFS_LOCK(vfs
->files
[fd
], fd
, op
, offset
, count
, type
)) == False
) {
906 printf("lock: error=%d (%s)\n", errno
, strerror(errno
));
907 return NT_STATUS_UNSUCCESSFUL
;
910 printf("lock: ok\n");
914 static NTSTATUS
cmd_symlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
917 printf("Usage: symlink <path> <link>\n");
921 if (SMB_VFS_SYMLINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
922 printf("symlink: error=%d (%s)\n", errno
, strerror(errno
));
923 return NT_STATUS_UNSUCCESSFUL
;
926 printf("symlink: ok\n");
931 static NTSTATUS
cmd_readlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
933 char buffer
[PATH_MAX
];
937 printf("Usage: readlink <path>\n");
941 if ((size
= SMB_VFS_READLINK(vfs
->conn
, argv
[1], buffer
, PATH_MAX
)) == -1) {
942 printf("readlink: error=%d (%s)\n", errno
, strerror(errno
));
943 return NT_STATUS_UNSUCCESSFUL
;
947 printf("readlink: %s\n", buffer
);
952 static NTSTATUS
cmd_link(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
955 printf("Usage: link <path> <link>\n");
959 if (SMB_VFS_LINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
960 printf("link: error=%d (%s)\n", errno
, strerror(errno
));
961 return NT_STATUS_UNSUCCESSFUL
;
964 printf("link: ok\n");
968 static NTSTATUS
cmd_mknod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
971 unsigned int dev_val
;
975 printf("Usage: mknod <path> <mode> <dev>\n");
976 printf(" mode is octal\n");
977 printf(" dev is hex\n");
981 if (sscanf(argv
[2], "%o", &mode
) == 0) {
982 printf("open: error=-1 (invalid mode!)\n");
983 return NT_STATUS_UNSUCCESSFUL
;
986 if (sscanf(argv
[3], "%x", &dev_val
) == 0) {
987 printf("open: error=-1 (invalid dev!)\n");
988 return NT_STATUS_UNSUCCESSFUL
;
990 dev
= (SMB_DEV_T
)dev_val
;
992 if (SMB_VFS_MKNOD(vfs
->conn
, argv
[1], mode
, dev
) == -1) {
993 printf("mknod: error=%d (%s)\n", errno
, strerror(errno
));
994 return NT_STATUS_UNSUCCESSFUL
;
997 printf("mknod: ok\n");
1001 static NTSTATUS
cmd_realpath(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1003 char respath
[PATH_MAX
];
1006 printf("Usage: realpath <path>\n");
1007 return NT_STATUS_OK
;
1010 if (SMB_VFS_REALPATH(vfs
->conn
, argv
[1], respath
) == NULL
) {
1011 printf("realpath: error=%d (%s)\n", errno
, strerror(errno
));
1012 return NT_STATUS_UNSUCCESSFUL
;
1015 printf("realpath: ok\n");
1016 return NT_STATUS_OK
;
1019 struct cmd_set vfs_commands
[] = {
1023 { "load", cmd_load_module
, "Load a module", "load <module.so>" },
1024 { "populate", cmd_populate
, "Populate a data buffer", "populate <char> <size>" },
1025 { "showdata", cmd_show_data
, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1026 { "connect", cmd_connect
, "VFS connect()", "connect" },
1027 { "disconnect", cmd_disconnect
, "VFS disconnect()", "disconnect" },
1028 { "disk_free", cmd_disk_free
, "VFS disk_free()", "disk_free <path>" },
1029 { "opendir", cmd_opendir
, "VFS opendir()", "opendir <fname>" },
1030 { "readdir", cmd_readdir
, "VFS readdir()", "readdir" },
1031 { "mkdir", cmd_mkdir
, "VFS mkdir()", "mkdir <path>" },
1032 { "rmdir", cmd_pathfunc
, "VFS rmdir()", "rmdir <path>" },
1033 { "closedir", cmd_closedir
, "VFS closedir()", "closedir" },
1034 { "open", cmd_open
, "VFS open()", "open <fname>" },
1035 { "close", cmd_close
, "VFS close()", "close <fd>" },
1036 { "read", cmd_read
, "VFS read()", "read <fd> <size>" },
1037 { "write", cmd_write
, "VFS write()", "write <fd> <size>" },
1038 { "lseek", cmd_lseek
, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1039 { "rename", cmd_rename
, "VFS rename()", "rename <old> <new>" },
1040 { "fsync", cmd_fsync
, "VFS fsync()", "fsync <fd>" },
1041 { "stat", cmd_stat
, "VFS stat()", "stat <fname>" },
1042 { "fstat", cmd_fstat
, "VFS fstat()", "fstat <fd>" },
1043 { "lstat", cmd_lstat
, "VFS lstat()", "lstat <fname>" },
1044 { "unlink", cmd_pathfunc
, "VFS unlink()", "unlink <fname>" },
1045 { "chmod", cmd_chmod
, "VFS chmod()", "chmod <path> <mode>" },
1046 { "fchmod", cmd_fchmod
, "VFS fchmod()", "fchmod <fd> <mode>" },
1047 { "chown", cmd_chown
, "VFS chown()", "chown <path> <uid> <gid>" },
1048 { "fchown", cmd_fchown
, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1049 { "chdir", cmd_pathfunc
, "VFS chdir()", "chdir <path>" },
1050 { "getwd", cmd_getwd
, "VFS getwd()", "getwd" },
1051 { "utime", cmd_utime
, "VFS utime()", "utime <path> <access> <modify>" },
1052 { "ftruncate", cmd_ftruncate
, "VFS ftruncate()", "ftruncate <fd> <length>" },
1053 { "lock", cmd_lock
, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1054 { "symlink", cmd_symlink
, "VFS symlink()", "symlink <old> <new>" },
1055 { "readlink", cmd_readlink
, "VFS readlink()", "readlink <path>" },
1056 { "link", cmd_link
, "VFS link()", "link <oldpath> <newpath>" },
1057 { "mknod", cmd_mknod
, "VFS mknod()", "mknod <path> <mode> <dev>" },
1058 { "realpath", cmd_realpath
, "VFS realpath()", "realpath <path>" },