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
)
145 SMB_STRUCT_DIRENT
*dent
= NULL
;
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
, &st
);
154 printf("readdir: NULL\n");
158 printf("readdir: %s\n", dent
->d_name
);
159 if (VALID_STAT(st
)) {
160 printf(" stat available");
161 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
162 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
163 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
164 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
165 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
166 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
167 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
168 printf(" Size: %10u", (unsigned int)st
.st_size
);
169 #ifdef HAVE_STAT_ST_BLOCKS
170 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
172 #ifdef HAVE_STAT_ST_BLKSIZE
173 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
175 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
176 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
177 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
178 printf(" Access: %05o", (st
.st_mode
) & 007777);
179 printf(" Uid: %5lu Gid: %5lu\n",
180 (unsigned long)st
.st_uid
,
181 (unsigned long)st
.st_gid
);
182 printf(" Access: %s", ctime(&(st
.st_atime
)));
183 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
184 printf(" Change: %s", ctime(&(st
.st_ctime
)));
191 static NTSTATUS
cmd_mkdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
194 printf("Usage: mkdir <path>\n");
198 if (SMB_VFS_MKDIR(vfs
->conn
, argv
[1], 00755) == -1) {
199 printf("mkdir error=%d (%s)\n", errno
, strerror(errno
));
200 return NT_STATUS_UNSUCCESSFUL
;
203 printf("mkdir: ok\n");
208 static NTSTATUS
cmd_closedir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
212 if (vfs
->currentdir
== NULL
) {
213 printf("closedir: failure (no directory open)\n");
214 return NT_STATUS_UNSUCCESSFUL
;
217 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
219 printf("closedir failure: %s\n", strerror(errno
));
220 return NT_STATUS_UNSUCCESSFUL
;
223 printf("closedir: ok\n");
224 vfs
->currentdir
= NULL
;
229 static NTSTATUS
cmd_open(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
238 if (argc
< 3 || argc
> 5) {
239 printf("Usage: open <filename> <flags> <mode>\n");
240 printf(" flags: O = O_RDONLY\n");
241 printf(" R = O_RDWR\n");
242 printf(" W = O_WRONLY\n");
243 printf(" C = O_CREAT\n");
244 printf(" E = O_EXCL\n");
245 printf(" T = O_TRUNC\n");
246 printf(" A = O_APPEND\n");
247 printf(" N = O_NONBLOCK/O_NDELAY\n");
249 printf(" S = O_SYNC\n");
252 printf(" F = O_NOFOLLOW\n");
254 printf(" mode: see open.2\n");
255 printf(" mode is ignored if C flag not present\n");
256 printf(" mode defaults to 00400\n");
298 printf("open: error=-1 (invalid flag!)\n");
299 return NT_STATUS_UNSUCCESSFUL
;
303 if ((flags
& O_CREAT
) && argc
== 4) {
304 if (sscanf(argv
[3], "%ho", (unsigned short *)&mode
) == 0) {
305 printf("open: error=-1 (invalid mode!)\n");
306 return NT_STATUS_UNSUCCESSFUL
;
310 fsp
= SMB_MALLOC_P(struct files_struct
);
312 return NT_STATUS_NO_MEMORY
;
314 fsp
->fsp_name
= SMB_STRDUP(argv
[1]);
315 if (fsp
->fsp_name
== NULL
) {
317 return NT_STATUS_NO_MEMORY
;
319 fsp
->fh
= SMB_MALLOC_P(struct fd_handle
);
320 if (fsp
->fh
== NULL
) {
321 SAFE_FREE(fsp
->fsp_name
);
323 return NT_STATUS_NO_MEMORY
;
325 fsp
->conn
= vfs
->conn
;
327 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, argv
[1], fsp
, flags
, mode
);
328 if (fsp
->fh
->fd
== -1) {
329 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
331 SAFE_FREE(fsp
->fsp_name
);
333 return NT_STATUS_UNSUCCESSFUL
;
336 vfs
->files
[fsp
->fh
->fd
] = fsp
;
337 printf("open: fd=%d\n", fsp
->fh
->fd
);
342 static NTSTATUS
cmd_pathfunc(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
347 printf("Usage: %s <path>\n", argv
[0]);
351 if (strcmp("rmdir", argv
[0]) == 0 ) {
352 ret
= SMB_VFS_RMDIR(vfs
->conn
, argv
[1]);
353 } else if (strcmp("unlink", argv
[0]) == 0 ) {
354 ret
= SMB_VFS_UNLINK(vfs
->conn
, argv
[1]);
355 } else if (strcmp("chdir", argv
[0]) == 0 ) {
356 ret
= SMB_VFS_CHDIR(vfs
->conn
, argv
[1]);
358 printf("%s: error=%d (invalid function name!)\n", argv
[0], errno
);
359 return NT_STATUS_UNSUCCESSFUL
;
363 printf("%s: error=%d (%s)\n", argv
[0], errno
, strerror(errno
));
364 return NT_STATUS_UNSUCCESSFUL
;
367 printf("%s: ok\n", argv
[0]);
372 static NTSTATUS
cmd_close(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
377 printf("Usage: close <fd>\n");
382 if (vfs
->files
[fd
] == NULL
) {
383 printf("close: error=-1 (invalid file descriptor)\n");
387 ret
= SMB_VFS_CLOSE(vfs
->files
[fd
]);
389 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
391 printf("close: ok\n");
393 SAFE_FREE(vfs
->files
[fd
]->fsp_name
);
394 SAFE_FREE(vfs
->files
[fd
]->fh
);
395 SAFE_FREE(vfs
->files
[fd
]);
396 vfs
->files
[fd
] = NULL
;
401 static NTSTATUS
cmd_read(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
407 printf("Usage: read <fd> <size>\n");
411 /* do some error checking on these */
413 size
= atoi(argv
[2]);
414 vfs
->data
= TALLOC_ARRAY(mem_ctx
, char, size
);
415 if (vfs
->data
== NULL
) {
416 printf("read: error=-1 (not enough memory)");
417 return NT_STATUS_UNSUCCESSFUL
;
419 vfs
->data_size
= size
;
421 rsize
= SMB_VFS_READ(vfs
->files
[fd
], vfs
->data
, size
);
423 printf("read: error=%d (%s)\n", errno
, strerror(errno
));
424 return NT_STATUS_UNSUCCESSFUL
;
427 printf("read: ok\n");
432 static NTSTATUS
cmd_write(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
437 printf("Usage: write <fd> <size>\n");
441 /* some error checking should go here */
443 size
= atoi(argv
[2]);
444 if (vfs
->data
== NULL
) {
445 printf("write: error=-1 (buffer empty, please populate it before writing)");
446 return NT_STATUS_UNSUCCESSFUL
;
449 if (vfs
->data_size
< size
) {
450 printf("write: error=-1 (buffer too small, please put some more data in)");
451 return NT_STATUS_UNSUCCESSFUL
;
454 wsize
= SMB_VFS_WRITE(vfs
->files
[fd
], vfs
->data
, size
);
457 printf("write: error=%d (%s)\n", errno
, strerror(errno
));
458 return NT_STATUS_UNSUCCESSFUL
;
461 printf("write: ok\n");
466 static NTSTATUS
cmd_lseek(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
468 int fd
, offset
, whence
;
472 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
477 offset
= atoi(argv
[2]);
478 whence
= atoi(argv
[3]);
480 case 1: whence
= SEEK_SET
; break;
481 case 2: whence
= SEEK_CUR
; break;
482 default: whence
= SEEK_END
;
485 pos
= SMB_VFS_LSEEK(vfs
->files
[fd
], offset
, whence
);
486 if (pos
== (SMB_OFF_T
)-1) {
487 printf("lseek: error=%d (%s)\n", errno
, strerror(errno
));
488 return NT_STATUS_UNSUCCESSFUL
;
491 printf("lseek: ok\n");
496 static NTSTATUS
cmd_rename(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
500 printf("Usage: rename <old> <new>\n");
504 ret
= SMB_VFS_RENAME(vfs
->conn
, argv
[1], argv
[2]);
506 printf("rename: error=%d (%s)\n", errno
, strerror(errno
));
507 return NT_STATUS_UNSUCCESSFUL
;
510 printf("rename: ok\n");
515 static NTSTATUS
cmd_fsync(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
519 printf("Usage: fsync <fd>\n");
524 ret
= SMB_VFS_FSYNC(vfs
->files
[fd
]);
526 printf("fsync: error=%d (%s)\n", errno
, strerror(errno
));
527 return NT_STATUS_UNSUCCESSFUL
;
530 printf("fsync: ok\n");
535 static NTSTATUS
cmd_stat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
540 struct passwd
*pwd
= NULL
;
541 struct group
*grp
= NULL
;
545 printf("Usage: stat <fname>\n");
549 ret
= SMB_VFS_STAT(vfs
->conn
, argv
[1], &st
);
551 printf("stat: error=%d (%s)\n", errno
, strerror(errno
));
552 return NT_STATUS_UNSUCCESSFUL
;
555 pwd
= sys_getpwuid(st
.st_uid
);
556 if (pwd
!= NULL
) user
= pwd
->pw_name
;
557 else user
= null_string
;
558 grp
= sys_getgrgid(st
.st_gid
);
559 if (grp
!= NULL
) group
= grp
->gr_name
;
560 else group
= null_string
;
562 printf("stat: ok\n");
563 printf(" File: %s", argv
[1]);
564 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
565 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
566 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
567 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
568 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
569 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
570 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
571 printf(" Size: %10u", (unsigned int)st
.st_size
);
572 #ifdef HAVE_STAT_ST_BLOCKS
573 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
575 #ifdef HAVE_STAT_ST_BLKSIZE
576 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
578 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
579 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
580 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
581 printf(" Access: %05o", (st
.st_mode
) & 007777);
582 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
583 (unsigned long)st
.st_gid
, group
);
584 printf(" Access: %s", ctime(&(st
.st_atime
)));
585 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
586 printf(" Change: %s", ctime(&(st
.st_ctime
)));
592 static NTSTATUS
cmd_fstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
597 struct passwd
*pwd
= NULL
;
598 struct group
*grp
= NULL
;
602 printf("Usage: fstat <fd>\n");
607 if (fd
< 0 || fd
>= 1024) {
608 printf("fstat: error=%d (file descriptor out of range)\n", EBADF
);
612 if (vfs
->files
[fd
] == NULL
) {
613 printf("fstat: error=%d (invalid file descriptor)\n", EBADF
);
617 if (SMB_VFS_FSTAT(vfs
->files
[fd
], &st
) == -1) {
618 printf("fstat: error=%d (%s)\n", errno
, strerror(errno
));
619 return NT_STATUS_UNSUCCESSFUL
;
622 pwd
= sys_getpwuid(st
.st_uid
);
623 if (pwd
!= NULL
) user
= pwd
->pw_name
;
624 else user
= null_string
;
625 grp
= sys_getgrgid(st
.st_gid
);
626 if (grp
!= NULL
) group
= grp
->gr_name
;
627 else group
= null_string
;
629 printf("fstat: ok\n");
630 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
631 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
632 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
633 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
634 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
635 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
636 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
637 printf(" Size: %10u", (unsigned int)st
.st_size
);
638 #ifdef HAVE_STAT_ST_BLOCKS
639 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
641 #ifdef HAVE_STAT_ST_BLKSIZE
642 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
644 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
645 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
646 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
647 printf(" Access: %05o", (st
.st_mode
) & 007777);
648 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
649 (unsigned long)st
.st_gid
, group
);
650 printf(" Access: %s", ctime(&(st
.st_atime
)));
651 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
652 printf(" Change: %s", ctime(&(st
.st_ctime
)));
658 static NTSTATUS
cmd_lstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
662 struct passwd
*pwd
= NULL
;
663 struct group
*grp
= NULL
;
667 printf("Usage: lstat <path>\n");
671 if (SMB_VFS_LSTAT(vfs
->conn
, argv
[1], &st
) == -1) {
672 printf("lstat: error=%d (%s)\n", errno
, strerror(errno
));
673 return NT_STATUS_UNSUCCESSFUL
;
676 pwd
= sys_getpwuid(st
.st_uid
);
677 if (pwd
!= NULL
) user
= pwd
->pw_name
;
678 else user
= null_string
;
679 grp
= sys_getgrgid(st
.st_gid
);
680 if (grp
!= NULL
) group
= grp
->gr_name
;
681 else group
= null_string
;
683 printf("lstat: ok\n");
684 if (S_ISREG(st
.st_mode
)) printf(" Regular File\n");
685 else if (S_ISDIR(st
.st_mode
)) printf(" Directory\n");
686 else if (S_ISCHR(st
.st_mode
)) printf(" Character Device\n");
687 else if (S_ISBLK(st
.st_mode
)) printf(" Block Device\n");
688 else if (S_ISFIFO(st
.st_mode
)) printf(" Fifo\n");
689 else if (S_ISLNK(st
.st_mode
)) printf(" Symbolic Link\n");
690 else if (S_ISSOCK(st
.st_mode
)) printf(" Socket\n");
691 printf(" Size: %10u", (unsigned int)st
.st_size
);
692 #ifdef HAVE_STAT_ST_BLOCKS
693 printf(" Blocks: %9u", (unsigned int)st
.st_blocks
);
695 #ifdef HAVE_STAT_ST_BLKSIZE
696 printf(" IO Block: %u\n", (unsigned int)st
.st_blksize
);
698 printf(" Device: 0x%10x", (unsigned int)st
.st_dev
);
699 printf(" Inode: %10u", (unsigned int)st
.st_ino
);
700 printf(" Links: %10u\n", (unsigned int)st
.st_nlink
);
701 printf(" Access: %05o", (st
.st_mode
) & 007777);
702 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_uid
, user
,
703 (unsigned long)st
.st_gid
, group
);
704 printf(" Access: %s", ctime(&(st
.st_atime
)));
705 printf(" Modify: %s", ctime(&(st
.st_mtime
)));
706 printf(" Change: %s", ctime(&(st
.st_ctime
)));
712 static NTSTATUS
cmd_chmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
716 printf("Usage: chmod <path> <mode>\n");
720 mode
= atoi(argv
[2]);
721 if (SMB_VFS_CHMOD(vfs
->conn
, argv
[1], mode
) == -1) {
722 printf("chmod: error=%d (%s)\n", errno
, strerror(errno
));
723 return NT_STATUS_UNSUCCESSFUL
;
726 printf("chmod: ok\n");
731 static NTSTATUS
cmd_fchmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
736 printf("Usage: fchmod <fd> <mode>\n");
741 mode
= atoi(argv
[2]);
742 if (fd
< 0 || fd
>= 1024) {
743 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF
);
746 if (vfs
->files
[fd
] == NULL
) {
747 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF
);
751 if (SMB_VFS_FCHMOD(vfs
->files
[fd
], mode
) == -1) {
752 printf("fchmod: error=%d (%s)\n", errno
, strerror(errno
));
753 return NT_STATUS_UNSUCCESSFUL
;
756 printf("fchmod: ok\n");
761 static NTSTATUS
cmd_chown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
766 printf("Usage: chown <path> <uid> <gid>\n");
772 if (SMB_VFS_CHOWN(vfs
->conn
, argv
[1], uid
, gid
) == -1) {
773 printf("chown: error=%d (%s)\n", errno
, strerror(errno
));
774 return NT_STATUS_UNSUCCESSFUL
;
777 printf("chown: ok\n");
782 static NTSTATUS
cmd_fchown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
788 printf("Usage: fchown <fd> <uid> <gid>\n");
795 if (fd
< 0 || fd
>= 1024) {
796 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF
);
799 if (vfs
->files
[fd
] == NULL
) {
800 printf("fchown: error=%d (invalid file descriptor)\n", EBADF
);
803 if (SMB_VFS_FCHOWN(vfs
->files
[fd
], uid
, gid
) == -1) {
804 printf("fchown error=%d (%s)\n", errno
, strerror(errno
));
805 return NT_STATUS_UNSUCCESSFUL
;
808 printf("fchown: ok\n");
813 static NTSTATUS
cmd_getwd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
816 if (SMB_VFS_GETWD(vfs
->conn
, buf
) == NULL
) {
817 printf("getwd: error=%d (%s)\n", errno
, strerror(errno
));
818 return NT_STATUS_UNSUCCESSFUL
;
821 printf("getwd: %s\n", buf
);
825 static NTSTATUS
cmd_utime(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
827 struct smb_file_time ft
;
829 printf("Usage: utime <path> <access> <modify>\n");
835 ft
.atime
= convert_time_t_to_timespec(atoi(argv
[2]));
836 ft
.mtime
= convert_time_t_to_timespec(atoi(argv
[3]));
837 if (SMB_VFS_NTIMES(vfs
->conn
, argv
[1], &ft
) != 0) {
838 printf("utime: error=%d (%s)\n", errno
, strerror(errno
));
839 return NT_STATUS_UNSUCCESSFUL
;
842 printf("utime: ok\n");
846 static NTSTATUS
cmd_ftruncate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
851 printf("Usage: ftruncate <fd> <length>\n");
857 if (fd
< 0 || fd
>= 1024) {
858 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF
);
861 if (vfs
->files
[fd
] == NULL
) {
862 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF
);
866 if (SMB_VFS_FTRUNCATE(vfs
->files
[fd
], off
) == -1) {
867 printf("ftruncate: error=%d (%s)\n", errno
, strerror(errno
));
868 return NT_STATUS_UNSUCCESSFUL
;
871 printf("ftruncate: ok\n");
875 static NTSTATUS
cmd_lock(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
885 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
886 printf(" ops: G = F_GETLK\n");
887 printf(" S = F_SETLK\n");
888 printf(" W = F_SETLKW\n");
889 printf(" type: R = F_RDLCK\n");
890 printf(" W = F_WRLCK\n");
891 printf(" U = F_UNLCK\n");
895 if (sscanf(argv
[1], "%d", &fd
) == 0) {
896 printf("lock: error=-1 (error parsing fd)\n");
897 return NT_STATUS_UNSUCCESSFUL
;
912 printf("lock: error=-1 (invalid op flag!)\n");
913 return NT_STATUS_UNSUCCESSFUL
;
916 if (sscanf(argv
[3], "%ld", &offset
) == 0) {
917 printf("lock: error=-1 (error parsing fd)\n");
918 return NT_STATUS_UNSUCCESSFUL
;
921 if (sscanf(argv
[4], "%ld", &count
) == 0) {
922 printf("lock: error=-1 (error parsing fd)\n");
923 return NT_STATUS_UNSUCCESSFUL
;
940 printf("lock: error=-1 (invalid type flag!)\n");
941 return NT_STATUS_UNSUCCESSFUL
;
946 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd
, op
, offset
, count
, type
);
948 if (SMB_VFS_LOCK(vfs
->files
[fd
], op
, offset
, count
, type
) == False
) {
949 printf("lock: error=%d (%s)\n", errno
, strerror(errno
));
950 return NT_STATUS_UNSUCCESSFUL
;
953 printf("lock: ok\n");
957 static NTSTATUS
cmd_symlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
960 printf("Usage: symlink <path> <link>\n");
964 if (SMB_VFS_SYMLINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
965 printf("symlink: error=%d (%s)\n", errno
, strerror(errno
));
966 return NT_STATUS_UNSUCCESSFUL
;
969 printf("symlink: ok\n");
974 static NTSTATUS
cmd_readlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
976 char buffer
[PATH_MAX
];
980 printf("Usage: readlink <path>\n");
984 if ((size
= SMB_VFS_READLINK(vfs
->conn
, argv
[1], buffer
, PATH_MAX
)) == -1) {
985 printf("readlink: error=%d (%s)\n", errno
, strerror(errno
));
986 return NT_STATUS_UNSUCCESSFUL
;
990 printf("readlink: %s\n", buffer
);
995 static NTSTATUS
cmd_link(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
998 printf("Usage: link <path> <link>\n");
1002 if (SMB_VFS_LINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1003 printf("link: error=%d (%s)\n", errno
, strerror(errno
));
1004 return NT_STATUS_UNSUCCESSFUL
;
1007 printf("link: ok\n");
1008 return NT_STATUS_OK
;
1011 static NTSTATUS
cmd_mknod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1014 unsigned int dev_val
;
1018 printf("Usage: mknod <path> <mode> <dev>\n");
1019 printf(" mode is octal\n");
1020 printf(" dev is hex\n");
1021 return NT_STATUS_OK
;
1024 if (sscanf(argv
[2], "%ho", (unsigned short *)&mode
) == 0) {
1025 printf("open: error=-1 (invalid mode!)\n");
1026 return NT_STATUS_UNSUCCESSFUL
;
1029 if (sscanf(argv
[3], "%x", &dev_val
) == 0) {
1030 printf("open: error=-1 (invalid dev!)\n");
1031 return NT_STATUS_UNSUCCESSFUL
;
1033 dev
= (SMB_DEV_T
)dev_val
;
1035 if (SMB_VFS_MKNOD(vfs
->conn
, argv
[1], mode
, dev
) == -1) {
1036 printf("mknod: error=%d (%s)\n", errno
, strerror(errno
));
1037 return NT_STATUS_UNSUCCESSFUL
;
1040 printf("mknod: ok\n");
1041 return NT_STATUS_OK
;
1044 static NTSTATUS
cmd_realpath(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1046 char respath
[PATH_MAX
];
1049 printf("Usage: realpath <path>\n");
1050 return NT_STATUS_OK
;
1053 if (SMB_VFS_REALPATH(vfs
->conn
, argv
[1], respath
) == NULL
) {
1054 printf("realpath: error=%d (%s)\n", errno
, strerror(errno
));
1055 return NT_STATUS_UNSUCCESSFUL
;
1058 printf("realpath: ok\n");
1059 return NT_STATUS_OK
;
1062 struct cmd_set vfs_commands
[] = {
1066 { "load", cmd_load_module
, "Load a module", "load <module.so>" },
1067 { "populate", cmd_populate
, "Populate a data buffer", "populate <char> <size>" },
1068 { "showdata", cmd_show_data
, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1069 { "connect", cmd_connect
, "VFS connect()", "connect" },
1070 { "disconnect", cmd_disconnect
, "VFS disconnect()", "disconnect" },
1071 { "disk_free", cmd_disk_free
, "VFS disk_free()", "disk_free <path>" },
1072 { "opendir", cmd_opendir
, "VFS opendir()", "opendir <fname>" },
1073 { "readdir", cmd_readdir
, "VFS readdir()", "readdir" },
1074 { "mkdir", cmd_mkdir
, "VFS mkdir()", "mkdir <path>" },
1075 { "rmdir", cmd_pathfunc
, "VFS rmdir()", "rmdir <path>" },
1076 { "closedir", cmd_closedir
, "VFS closedir()", "closedir" },
1077 { "open", cmd_open
, "VFS open()", "open <fname>" },
1078 { "close", cmd_close
, "VFS close()", "close <fd>" },
1079 { "read", cmd_read
, "VFS read()", "read <fd> <size>" },
1080 { "write", cmd_write
, "VFS write()", "write <fd> <size>" },
1081 { "lseek", cmd_lseek
, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1082 { "rename", cmd_rename
, "VFS rename()", "rename <old> <new>" },
1083 { "fsync", cmd_fsync
, "VFS fsync()", "fsync <fd>" },
1084 { "stat", cmd_stat
, "VFS stat()", "stat <fname>" },
1085 { "fstat", cmd_fstat
, "VFS fstat()", "fstat <fd>" },
1086 { "lstat", cmd_lstat
, "VFS lstat()", "lstat <fname>" },
1087 { "unlink", cmd_pathfunc
, "VFS unlink()", "unlink <fname>" },
1088 { "chmod", cmd_chmod
, "VFS chmod()", "chmod <path> <mode>" },
1089 { "fchmod", cmd_fchmod
, "VFS fchmod()", "fchmod <fd> <mode>" },
1090 { "chown", cmd_chown
, "VFS chown()", "chown <path> <uid> <gid>" },
1091 { "fchown", cmd_fchown
, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1092 { "chdir", cmd_pathfunc
, "VFS chdir()", "chdir <path>" },
1093 { "getwd", cmd_getwd
, "VFS getwd()", "getwd" },
1094 { "utime", cmd_utime
, "VFS utime()", "utime <path> <access> <modify>" },
1095 { "ftruncate", cmd_ftruncate
, "VFS ftruncate()", "ftruncate <fd> <length>" },
1096 { "lock", cmd_lock
, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1097 { "symlink", cmd_symlink
, "VFS symlink()", "symlink <old> <new>" },
1098 { "readlink", cmd_readlink
, "VFS readlink()", "readlink <path>" },
1099 { "link", cmd_link
, "VFS link()", "link <oldpath> <newpath>" },
1100 { "mknod", cmd_mknod
, "VFS mknod()", "mknod <path> <mode> <dev>" },
1101 { "realpath", cmd_realpath
, "VFS realpath()", "realpath <path>" },