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 3 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, see <http://www.gnu.org/licenses/>.
25 static const char *null_string
= "";
27 static NTSTATUS
cmd_load_module(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
32 printf("Usage: load <modules>\n");
36 for (i
=argc
-1;i
>0;i
--) {
37 if (!vfs_init_custom(vfs
->conn
, argv
[i
])) {
38 DEBUG(0, ("load: (vfs_init_custom failed for %s)\n", argv
[i
]));
39 return NT_STATUS_UNSUCCESSFUL
;
46 static NTSTATUS
cmd_populate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
51 printf("Usage: populate <char> <size>\n");
56 vfs
->data
= TALLOC_ARRAY(mem_ctx
, char, size
);
57 if (vfs
->data
== NULL
) {
58 printf("populate: error=-1 (not enough memory)");
59 return NT_STATUS_UNSUCCESSFUL
;
61 memset(vfs
->data
, c
, size
);
62 vfs
->data_size
= size
;
66 static NTSTATUS
cmd_show_data(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
70 if (argc
!= 1 && argc
!= 3) {
71 printf("Usage: showdata [<offset> <len>]\n");
74 if (vfs
->data
== NULL
|| vfs
->data_size
== 0) {
75 printf("show_data: error=-1 (buffer empty)\n");
76 return NT_STATUS_UNSUCCESSFUL
;
80 offset
= atoi(argv
[1]);
86 if ((offset
+ len
) > vfs
->data_size
) {
87 printf("show_data: error=-1 (not enough data in buffer)\n");
88 return NT_STATUS_UNSUCCESSFUL
;
90 dump_data(0, (uint8
*)(vfs
->data
) + offset
, len
);
94 static NTSTATUS
cmd_connect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
96 SMB_VFS_CONNECT(vfs
->conn
, lp_servicename(SNUM(vfs
->conn
)), "vfstest");
100 static NTSTATUS
cmd_disconnect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
102 SMB_VFS_DISCONNECT(vfs
->conn
);
106 static NTSTATUS
cmd_disk_free(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
108 uint64_t diskfree
, bsize
, dfree
, dsize
;
110 printf("Usage: disk_free <path>\n");
114 diskfree
= SMB_VFS_DISK_FREE(vfs
->conn
, argv
[1], False
, &bsize
, &dfree
, &dsize
);
115 printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n",
116 (unsigned long)diskfree
,
117 (unsigned long)bsize
,
118 (unsigned long)dfree
,
119 (unsigned long)dsize
);
124 static NTSTATUS
cmd_opendir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
127 printf("Usage: opendir <fname>\n");
131 vfs
->currentdir
= SMB_VFS_OPENDIR(vfs
->conn
, argv
[1], NULL
, 0);
132 if (vfs
->currentdir
== NULL
) {
133 printf("opendir error=%d (%s)\n", errno
, strerror(errno
));
134 return NT_STATUS_UNSUCCESSFUL
;
137 printf("opendir: ok\n");
142 static NTSTATUS
cmd_readdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
144 SMB_STRUCT_DIRENT
*dent
;
146 if (vfs
->currentdir
== NULL
) {
147 printf("readdir: error=-1 (no open directory)\n");
148 return NT_STATUS_UNSUCCESSFUL
;
151 dent
= SMB_VFS_READDIR(vfs
->conn
, vfs
->currentdir
);
153 printf("readdir: NULL\n");
157 printf("readdir: %s\n", dent
->d_name
);
162 static NTSTATUS
cmd_mkdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
165 printf("Usage: mkdir <path>\n");
169 if (SMB_VFS_MKDIR(vfs
->conn
, argv
[1], 00755) == -1) {
170 printf("mkdir error=%d (%s)\n", errno
, strerror(errno
));
171 return NT_STATUS_UNSUCCESSFUL
;
174 printf("mkdir: ok\n");
179 static NTSTATUS
cmd_closedir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
183 if (vfs
->currentdir
== NULL
) {
184 printf("closedir: failure (no directory open)\n");
185 return NT_STATUS_UNSUCCESSFUL
;
188 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
190 printf("closedir failure: %s\n", strerror(errno
));
191 return NT_STATUS_UNSUCCESSFUL
;
194 printf("closedir: ok\n");
195 vfs
->currentdir
= NULL
;
200 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], "%ho", (unsigned short *)&mode
) == 0) {
276 printf("open: error=-1 (invalid mode!)\n");
277 return NT_STATUS_UNSUCCESSFUL
;
281 fsp
= SMB_MALLOC_P(struct files_struct
);
283 return NT_STATUS_NO_MEMORY
;
285 fsp
->fsp_name
= SMB_STRDUP(argv
[1]);
286 if (fsp
->fsp_name
== NULL
) {
288 return NT_STATUS_NO_MEMORY
;
290 fsp
->fh
= SMB_MALLOC_P(struct fd_handle
);
291 if (fsp
->fh
== NULL
) {
292 SAFE_FREE(fsp
->fsp_name
);
294 return NT_STATUS_NO_MEMORY
;
296 fsp
->conn
= vfs
->conn
;
298 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, argv
[1], fsp
, flags
, mode
);
299 if (fsp
->fh
->fd
== -1) {
300 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
302 SAFE_FREE(fsp
->fsp_name
);
304 return NT_STATUS_UNSUCCESSFUL
;
307 vfs
->files
[fsp
->fh
->fd
] = fsp
;
308 printf("open: fd=%d\n", fsp
->fh
->fd
);
313 static NTSTATUS
cmd_pathfunc(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
318 printf("Usage: %s <path>\n", argv
[0]);
322 if (strcmp("rmdir", argv
[0]) == 0 ) {
323 ret
= SMB_VFS_RMDIR(vfs
->conn
, argv
[1]);
324 } else if (strcmp("unlink", argv
[0]) == 0 ) {
325 ret
= SMB_VFS_UNLINK(vfs
->conn
, argv
[1]);
326 } else if (strcmp("chdir", argv
[0]) == 0 ) {
327 ret
= SMB_VFS_CHDIR(vfs
->conn
, argv
[1]);
329 printf("%s: error=%d (invalid function name!)\n", argv
[0], errno
);
330 return NT_STATUS_UNSUCCESSFUL
;
334 printf("%s: error=%d (%s)\n", argv
[0], errno
, strerror(errno
));
335 return NT_STATUS_UNSUCCESSFUL
;
338 printf("%s: ok\n", argv
[0]);
343 static NTSTATUS
cmd_close(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
348 printf("Usage: close <fd>\n");
353 if (vfs
->files
[fd
] == NULL
) {
354 printf("close: error=-1 (invalid file descriptor)\n");
358 ret
= SMB_VFS_CLOSE(vfs
->files
[fd
]);
360 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
362 printf("close: ok\n");
364 SAFE_FREE(vfs
->files
[fd
]->fsp_name
);
365 SAFE_FREE(vfs
->files
[fd
]->fh
);
366 SAFE_FREE(vfs
->files
[fd
]);
367 vfs
->files
[fd
] = NULL
;
372 static NTSTATUS
cmd_read(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
378 printf("Usage: read <fd> <size>\n");
382 /* do some error checking on these */
384 size
= atoi(argv
[2]);
385 vfs
->data
= TALLOC_ARRAY(mem_ctx
, char, size
);
386 if (vfs
->data
== NULL
) {
387 printf("read: error=-1 (not enough memory)");
388 return NT_STATUS_UNSUCCESSFUL
;
390 vfs
->data_size
= size
;
392 rsize
= SMB_VFS_READ(vfs
->files
[fd
], vfs
->data
, size
);
394 printf("read: error=%d (%s)\n", errno
, strerror(errno
));
395 return NT_STATUS_UNSUCCESSFUL
;
398 printf("read: ok\n");
403 static NTSTATUS
cmd_write(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
408 printf("Usage: write <fd> <size>\n");
412 /* some error checking should go here */
414 size
= atoi(argv
[2]);
415 if (vfs
->data
== NULL
) {
416 printf("write: error=-1 (buffer empty, please populate it before writing)");
417 return NT_STATUS_UNSUCCESSFUL
;
420 if (vfs
->data_size
< size
) {
421 printf("write: error=-1 (buffer too small, please put some more data in)");
422 return NT_STATUS_UNSUCCESSFUL
;
425 wsize
= SMB_VFS_WRITE(vfs
->files
[fd
], vfs
->data
, size
);
428 printf("write: error=%d (%s)\n", errno
, strerror(errno
));
429 return NT_STATUS_UNSUCCESSFUL
;
432 printf("write: ok\n");
437 static NTSTATUS
cmd_lseek(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
439 int fd
, offset
, whence
;
443 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
448 offset
= atoi(argv
[2]);
449 whence
= atoi(argv
[3]);
451 case 1: whence
= SEEK_SET
; break;
452 case 2: whence
= SEEK_CUR
; break;
453 default: whence
= SEEK_END
;
456 pos
= SMB_VFS_LSEEK(vfs
->files
[fd
], offset
, whence
);
457 if (pos
== (SMB_OFF_T
)-1) {
458 printf("lseek: error=%d (%s)\n", errno
, strerror(errno
));
459 return NT_STATUS_UNSUCCESSFUL
;
462 printf("lseek: ok\n");
467 static NTSTATUS
cmd_rename(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
471 printf("Usage: rename <old> <new>\n");
475 ret
= SMB_VFS_RENAME(vfs
->conn
, argv
[1], argv
[2]);
477 printf("rename: error=%d (%s)\n", errno
, strerror(errno
));
478 return NT_STATUS_UNSUCCESSFUL
;
481 printf("rename: ok\n");
486 static NTSTATUS
cmd_fsync(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
490 printf("Usage: fsync <fd>\n");
495 ret
= SMB_VFS_FSYNC(vfs
->files
[fd
]);
497 printf("fsync: error=%d (%s)\n", errno
, strerror(errno
));
498 return NT_STATUS_UNSUCCESSFUL
;
501 printf("fsync: ok\n");
506 static NTSTATUS
cmd_stat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
511 struct passwd
*pwd
= NULL
;
512 struct group
*grp
= NULL
;
516 printf("Usage: stat <fname>\n");
520 ret
= SMB_VFS_STAT(vfs
->conn
, argv
[1], &st
);
522 printf("stat: error=%d (%s)\n", errno
, strerror(errno
));
523 return NT_STATUS_UNSUCCESSFUL
;
526 pwd
= sys_getpwuid(st
.st_uid
);
527 if (pwd
!= NULL
) user
= pwd
->pw_name
;
528 else user
= null_string
;
529 grp
= sys_getgrgid(st
.st_gid
);
530 if (grp
!= NULL
) group
= grp
->gr_name
;
531 else group
= null_string
;
533 printf("stat: ok\n");
534 printf(" File: %s", argv
[1]);
535 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
536 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
537 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
538 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
539 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
540 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
541 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
542 printf(" Size: %10u", (unsigned int)st
.st_size
);
543 #ifdef HAVE_STAT_ST_BLOCKS
544 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
546 #ifdef HAVE_STAT_ST_BLKSIZE
547 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
549 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
550 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
551 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
552 printf(" Access: %05o", (st
.st_mode
) & 007777);
553 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
554 (unsigned long)st
.st_gid
, group
);
555 printf(" Access: %s", ctime(&(st
.st_atime
)));
556 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
557 printf(" Change: %s", ctime(&(st
.st_ctime
)));
563 static NTSTATUS
cmd_fstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
568 struct passwd
*pwd
= NULL
;
569 struct group
*grp
= NULL
;
573 printf("Usage: fstat <fd>\n");
578 if (fd
< 0 || fd
>= 1024) {
579 printf("fstat: error=%d (file descriptor out of range)\n", EBADF
);
583 if (vfs
->files
[fd
] == NULL
) {
584 printf("fstat: error=%d (invalid file descriptor)\n", EBADF
);
588 if (SMB_VFS_FSTAT(vfs
->files
[fd
], &st
) == -1) {
589 printf("fstat: error=%d (%s)\n", errno
, strerror(errno
));
590 return NT_STATUS_UNSUCCESSFUL
;
593 pwd
= sys_getpwuid(st
.st_uid
);
594 if (pwd
!= NULL
) user
= pwd
->pw_name
;
595 else user
= null_string
;
596 grp
= sys_getgrgid(st
.st_gid
);
597 if (grp
!= NULL
) group
= grp
->gr_name
;
598 else group
= null_string
;
600 printf("fstat: ok\n");
601 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
602 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
603 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
604 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
605 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
606 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
607 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
608 printf(" Size: %10u", (unsigned int)st
.st_size
);
609 #ifdef HAVE_STAT_ST_BLOCKS
610 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
612 #ifdef HAVE_STAT_ST_BLKSIZE
613 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
615 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
616 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
617 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
618 printf(" Access: %05o", (st
.st_mode
) & 007777);
619 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
620 (unsigned long)st
.st_gid
, group
);
621 printf(" Access: %s", ctime(&(st
.st_atime
)));
622 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
623 printf(" Change: %s", ctime(&(st
.st_ctime
)));
629 static NTSTATUS
cmd_lstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
633 struct passwd
*pwd
= NULL
;
634 struct group
*grp
= NULL
;
638 printf("Usage: lstat <path>\n");
642 if (SMB_VFS_LSTAT(vfs
->conn
, argv
[1], &st
) == -1) {
643 printf("lstat: error=%d (%s)\n", errno
, strerror(errno
));
644 return NT_STATUS_UNSUCCESSFUL
;
647 pwd
= sys_getpwuid(st
.st_uid
);
648 if (pwd
!= NULL
) user
= pwd
->pw_name
;
649 else user
= null_string
;
650 grp
= sys_getgrgid(st
.st_gid
);
651 if (grp
!= NULL
) group
= grp
->gr_name
;
652 else group
= null_string
;
654 printf("lstat: ok\n");
655 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
656 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
657 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
658 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
659 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
660 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
661 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
662 printf(" Size: %10u", (unsigned int)st
.st_size
);
663 #ifdef HAVE_STAT_ST_BLOCKS
664 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
666 #ifdef HAVE_STAT_ST_BLKSIZE
667 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
669 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
670 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
671 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
672 printf(" Access: %05o", (st
.st_mode
) & 007777);
673 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
674 (unsigned long)st
.st_gid
, group
);
675 printf(" Access: %s", ctime(&(st
.st_atime
)));
676 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
677 printf(" Change: %s", ctime(&(st
.st_ctime
)));
683 static NTSTATUS
cmd_chmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
687 printf("Usage: chmod <path> <mode>\n");
691 mode
= atoi(argv
[2]);
692 if (SMB_VFS_CHMOD(vfs
->conn
, argv
[1], mode
) == -1) {
693 printf("chmod: error=%d (%s)\n", errno
, strerror(errno
));
694 return NT_STATUS_UNSUCCESSFUL
;
697 printf("chmod: ok\n");
702 static NTSTATUS
cmd_fchmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
707 printf("Usage: fchmod <fd> <mode>\n");
712 mode
= atoi(argv
[2]);
713 if (fd
< 0 || fd
>= 1024) {
714 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF
);
717 if (vfs
->files
[fd
] == NULL
) {
718 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF
);
722 if (SMB_VFS_FCHMOD(vfs
->files
[fd
], mode
) == -1) {
723 printf("fchmod: error=%d (%s)\n", errno
, strerror(errno
));
724 return NT_STATUS_UNSUCCESSFUL
;
727 printf("fchmod: ok\n");
732 static NTSTATUS
cmd_chown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
737 printf("Usage: chown <path> <uid> <gid>\n");
743 if (SMB_VFS_CHOWN(vfs
->conn
, argv
[1], uid
, gid
) == -1) {
744 printf("chown: error=%d (%s)\n", errno
, strerror(errno
));
745 return NT_STATUS_UNSUCCESSFUL
;
748 printf("chown: ok\n");
753 static NTSTATUS
cmd_fchown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
759 printf("Usage: fchown <fd> <uid> <gid>\n");
766 if (fd
< 0 || fd
>= 1024) {
767 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF
);
770 if (vfs
->files
[fd
] == NULL
) {
771 printf("fchown: error=%d (invalid file descriptor)\n", EBADF
);
774 if (SMB_VFS_FCHOWN(vfs
->files
[fd
], uid
, gid
) == -1) {
775 printf("fchown error=%d (%s)\n", errno
, strerror(errno
));
776 return NT_STATUS_UNSUCCESSFUL
;
779 printf("fchown: ok\n");
784 static NTSTATUS
cmd_getwd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
787 if (SMB_VFS_GETWD(vfs
->conn
, buf
) == NULL
) {
788 printf("getwd: error=%d (%s)\n", errno
, strerror(errno
));
789 return NT_STATUS_UNSUCCESSFUL
;
792 printf("getwd: %s\n", buf
);
796 static NTSTATUS
cmd_utime(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
798 struct timespec ts
[2];
800 printf("Usage: utime <path> <access> <modify>\n");
803 ts
[0] = convert_time_t_to_timespec(atoi(argv
[2]));
804 ts
[1] = convert_time_t_to_timespec(atoi(argv
[3]));
805 if (SMB_VFS_NTIMES(vfs
->conn
, argv
[1], ts
) != 0) {
806 printf("utime: error=%d (%s)\n", errno
, strerror(errno
));
807 return NT_STATUS_UNSUCCESSFUL
;
810 printf("utime: ok\n");
814 static NTSTATUS
cmd_ftruncate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
819 printf("Usage: ftruncate <fd> <length>\n");
825 if (fd
< 0 || fd
>= 1024) {
826 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF
);
829 if (vfs
->files
[fd
] == NULL
) {
830 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF
);
834 if (SMB_VFS_FTRUNCATE(vfs
->files
[fd
], off
) == -1) {
835 printf("ftruncate: error=%d (%s)\n", errno
, strerror(errno
));
836 return NT_STATUS_UNSUCCESSFUL
;
839 printf("ftruncate: ok\n");
843 static NTSTATUS
cmd_lock(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
853 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
854 printf(" ops: G = F_GETLK\n");
855 printf(" S = F_SETLK\n");
856 printf(" W = F_SETLKW\n");
857 printf(" type: R = F_RDLCK\n");
858 printf(" W = F_WRLCK\n");
859 printf(" U = F_UNLCK\n");
863 if (sscanf(argv
[1], "%d", &fd
) == 0) {
864 printf("lock: error=-1 (error parsing fd)\n");
865 return NT_STATUS_UNSUCCESSFUL
;
880 printf("lock: error=-1 (invalid op flag!)\n");
881 return NT_STATUS_UNSUCCESSFUL
;
884 if (sscanf(argv
[3], "%ld", &offset
) == 0) {
885 printf("lock: error=-1 (error parsing fd)\n");
886 return NT_STATUS_UNSUCCESSFUL
;
889 if (sscanf(argv
[4], "%ld", &count
) == 0) {
890 printf("lock: error=-1 (error parsing fd)\n");
891 return NT_STATUS_UNSUCCESSFUL
;
908 printf("lock: error=-1 (invalid type flag!)\n");
909 return NT_STATUS_UNSUCCESSFUL
;
914 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd
, op
, offset
, count
, type
);
916 if (SMB_VFS_LOCK(vfs
->files
[fd
], op
, offset
, count
, type
) == False
) {
917 printf("lock: error=%d (%s)\n", errno
, strerror(errno
));
918 return NT_STATUS_UNSUCCESSFUL
;
921 printf("lock: ok\n");
925 static NTSTATUS
cmd_symlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
928 printf("Usage: symlink <path> <link>\n");
932 if (SMB_VFS_SYMLINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
933 printf("symlink: error=%d (%s)\n", errno
, strerror(errno
));
934 return NT_STATUS_UNSUCCESSFUL
;
937 printf("symlink: ok\n");
942 static NTSTATUS
cmd_readlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
944 char buffer
[PATH_MAX
];
948 printf("Usage: readlink <path>\n");
952 if ((size
= SMB_VFS_READLINK(vfs
->conn
, argv
[1], buffer
, PATH_MAX
)) == -1) {
953 printf("readlink: error=%d (%s)\n", errno
, strerror(errno
));
954 return NT_STATUS_UNSUCCESSFUL
;
958 printf("readlink: %s\n", buffer
);
963 static NTSTATUS
cmd_link(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
966 printf("Usage: link <path> <link>\n");
970 if (SMB_VFS_LINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
971 printf("link: error=%d (%s)\n", errno
, strerror(errno
));
972 return NT_STATUS_UNSUCCESSFUL
;
975 printf("link: ok\n");
979 static NTSTATUS
cmd_mknod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
982 unsigned int dev_val
;
986 printf("Usage: mknod <path> <mode> <dev>\n");
987 printf(" mode is octal\n");
988 printf(" dev is hex\n");
992 if (sscanf(argv
[2], "%ho", (unsigned short *)&mode
) == 0) {
993 printf("open: error=-1 (invalid mode!)\n");
994 return NT_STATUS_UNSUCCESSFUL
;
997 if (sscanf(argv
[3], "%x", &dev_val
) == 0) {
998 printf("open: error=-1 (invalid dev!)\n");
999 return NT_STATUS_UNSUCCESSFUL
;
1001 dev
= (SMB_DEV_T
)dev_val
;
1003 if (SMB_VFS_MKNOD(vfs
->conn
, argv
[1], mode
, dev
) == -1) {
1004 printf("mknod: error=%d (%s)\n", errno
, strerror(errno
));
1005 return NT_STATUS_UNSUCCESSFUL
;
1008 printf("mknod: ok\n");
1009 return NT_STATUS_OK
;
1012 static NTSTATUS
cmd_realpath(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1014 char respath
[PATH_MAX
];
1017 printf("Usage: realpath <path>\n");
1018 return NT_STATUS_OK
;
1021 if (SMB_VFS_REALPATH(vfs
->conn
, argv
[1], respath
) == NULL
) {
1022 printf("realpath: error=%d (%s)\n", errno
, strerror(errno
));
1023 return NT_STATUS_UNSUCCESSFUL
;
1026 printf("realpath: ok\n");
1027 return NT_STATUS_OK
;
1030 struct cmd_set vfs_commands
[] = {
1034 { "load", cmd_load_module
, "Load a module", "load <module.so>" },
1035 { "populate", cmd_populate
, "Populate a data buffer", "populate <char> <size>" },
1036 { "showdata", cmd_show_data
, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1037 { "connect", cmd_connect
, "VFS connect()", "connect" },
1038 { "disconnect", cmd_disconnect
, "VFS disconnect()", "disconnect" },
1039 { "disk_free", cmd_disk_free
, "VFS disk_free()", "disk_free <path>" },
1040 { "opendir", cmd_opendir
, "VFS opendir()", "opendir <fname>" },
1041 { "readdir", cmd_readdir
, "VFS readdir()", "readdir" },
1042 { "mkdir", cmd_mkdir
, "VFS mkdir()", "mkdir <path>" },
1043 { "rmdir", cmd_pathfunc
, "VFS rmdir()", "rmdir <path>" },
1044 { "closedir", cmd_closedir
, "VFS closedir()", "closedir" },
1045 { "open", cmd_open
, "VFS open()", "open <fname>" },
1046 { "close", cmd_close
, "VFS close()", "close <fd>" },
1047 { "read", cmd_read
, "VFS read()", "read <fd> <size>" },
1048 { "write", cmd_write
, "VFS write()", "write <fd> <size>" },
1049 { "lseek", cmd_lseek
, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1050 { "rename", cmd_rename
, "VFS rename()", "rename <old> <new>" },
1051 { "fsync", cmd_fsync
, "VFS fsync()", "fsync <fd>" },
1052 { "stat", cmd_stat
, "VFS stat()", "stat <fname>" },
1053 { "fstat", cmd_fstat
, "VFS fstat()", "fstat <fd>" },
1054 { "lstat", cmd_lstat
, "VFS lstat()", "lstat <fname>" },
1055 { "unlink", cmd_pathfunc
, "VFS unlink()", "unlink <fname>" },
1056 { "chmod", cmd_chmod
, "VFS chmod()", "chmod <path> <mode>" },
1057 { "fchmod", cmd_fchmod
, "VFS fchmod()", "fchmod <fd> <mode>" },
1058 { "chown", cmd_chown
, "VFS chown()", "chown <path> <uid> <gid>" },
1059 { "fchown", cmd_fchown
, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1060 { "chdir", cmd_pathfunc
, "VFS chdir()", "chdir <path>" },
1061 { "getwd", cmd_getwd
, "VFS getwd()", "getwd" },
1062 { "utime", cmd_utime
, "VFS utime()", "utime <path> <access> <modify>" },
1063 { "ftruncate", cmd_ftruncate
, "VFS ftruncate()", "ftruncate <fd> <length>" },
1064 { "lock", cmd_lock
, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1065 { "symlink", cmd_symlink
, "VFS symlink()", "symlink <old> <new>" },
1066 { "readlink", cmd_readlink
, "VFS readlink()", "readlink <path>" },
1067 { "link", cmd_link
, "VFS link()", "link <oldpath> <newpath>" },
1068 { "mknod", cmd_mknod
, "VFS mknod()", "mknod <path> <mode> <dev>" },
1069 { "realpath", cmd_realpath
, "VFS realpath()", "realpath <path>" },