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
)) {
161 printf(" stat available");
162 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
163 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
164 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
165 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
166 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
167 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
168 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
169 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
170 #ifdef HAVE_STAT_ST_BLOCKS
171 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
173 #ifdef HAVE_STAT_ST_BLKSIZE
174 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
176 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
177 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
178 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
179 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
180 printf(" Uid: %5lu Gid: %5lu\n",
181 (unsigned long)st
.st_ex_uid
,
182 (unsigned long)st
.st_ex_gid
);
183 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
184 printf(" Access: %s", ctime(&tmp_time
));
185 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
186 printf(" Modify: %s", ctime(&tmp_time
));
187 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
188 printf(" Change: %s", ctime(&tmp_time
));
195 static NTSTATUS
cmd_mkdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
198 printf("Usage: mkdir <path>\n");
202 if (SMB_VFS_MKDIR(vfs
->conn
, argv
[1], 00755) == -1) {
203 printf("mkdir error=%d (%s)\n", errno
, strerror(errno
));
204 return NT_STATUS_UNSUCCESSFUL
;
207 printf("mkdir: ok\n");
212 static NTSTATUS
cmd_closedir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
216 if (vfs
->currentdir
== NULL
) {
217 printf("closedir: failure (no directory open)\n");
218 return NT_STATUS_UNSUCCESSFUL
;
221 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
223 printf("closedir failure: %s\n", strerror(errno
));
224 return NT_STATUS_UNSUCCESSFUL
;
227 printf("closedir: ok\n");
228 vfs
->currentdir
= NULL
;
233 static NTSTATUS
cmd_open(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
242 if (argc
< 3 || argc
> 5) {
243 printf("Usage: open <filename> <flags> <mode>\n");
244 printf(" flags: O = O_RDONLY\n");
245 printf(" R = O_RDWR\n");
246 printf(" W = O_WRONLY\n");
247 printf(" C = O_CREAT\n");
248 printf(" E = O_EXCL\n");
249 printf(" T = O_TRUNC\n");
250 printf(" A = O_APPEND\n");
251 printf(" N = O_NONBLOCK/O_NDELAY\n");
253 printf(" S = O_SYNC\n");
256 printf(" F = O_NOFOLLOW\n");
258 printf(" mode: see open.2\n");
259 printf(" mode is ignored if C flag not present\n");
260 printf(" mode defaults to 00400\n");
302 printf("open: error=-1 (invalid flag!)\n");
303 return NT_STATUS_UNSUCCESSFUL
;
307 if ((flags
& O_CREAT
) && argc
== 4) {
308 if (sscanf(argv
[3], "%ho", (unsigned short *)&mode
) == 0) {
309 printf("open: error=-1 (invalid mode!)\n");
310 return NT_STATUS_UNSUCCESSFUL
;
314 fsp
= SMB_MALLOC_P(struct files_struct
);
316 return NT_STATUS_NO_MEMORY
;
318 fsp
->fsp_name
= SMB_STRDUP(argv
[1]);
319 if (fsp
->fsp_name
== NULL
) {
321 return NT_STATUS_NO_MEMORY
;
323 fsp
->fh
= SMB_MALLOC_P(struct fd_handle
);
324 if (fsp
->fh
== NULL
) {
325 SAFE_FREE(fsp
->fsp_name
);
327 return NT_STATUS_NO_MEMORY
;
329 fsp
->conn
= vfs
->conn
;
331 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, argv
[1], fsp
, flags
, mode
);
332 if (fsp
->fh
->fd
== -1) {
333 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
335 SAFE_FREE(fsp
->fsp_name
);
337 return NT_STATUS_UNSUCCESSFUL
;
340 vfs
->files
[fsp
->fh
->fd
] = fsp
;
341 printf("open: fd=%d\n", fsp
->fh
->fd
);
346 static NTSTATUS
cmd_pathfunc(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
351 printf("Usage: %s <path>\n", argv
[0]);
355 if (strcmp("rmdir", argv
[0]) == 0 ) {
356 ret
= SMB_VFS_RMDIR(vfs
->conn
, argv
[1]);
357 } else if (strcmp("unlink", argv
[0]) == 0 ) {
358 ret
= SMB_VFS_UNLINK(vfs
->conn
, argv
[1]);
359 } else if (strcmp("chdir", argv
[0]) == 0 ) {
360 ret
= SMB_VFS_CHDIR(vfs
->conn
, argv
[1]);
362 printf("%s: error=%d (invalid function name!)\n", argv
[0], errno
);
363 return NT_STATUS_UNSUCCESSFUL
;
367 printf("%s: error=%d (%s)\n", argv
[0], errno
, strerror(errno
));
368 return NT_STATUS_UNSUCCESSFUL
;
371 printf("%s: ok\n", argv
[0]);
376 static NTSTATUS
cmd_close(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
381 printf("Usage: close <fd>\n");
386 if (vfs
->files
[fd
] == NULL
) {
387 printf("close: error=-1 (invalid file descriptor)\n");
391 ret
= SMB_VFS_CLOSE(vfs
->files
[fd
]);
393 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
395 printf("close: ok\n");
397 SAFE_FREE(vfs
->files
[fd
]->fsp_name
);
398 SAFE_FREE(vfs
->files
[fd
]->fh
);
399 SAFE_FREE(vfs
->files
[fd
]);
400 vfs
->files
[fd
] = NULL
;
405 static NTSTATUS
cmd_read(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
411 printf("Usage: read <fd> <size>\n");
415 /* do some error checking on these */
417 size
= atoi(argv
[2]);
418 vfs
->data
= TALLOC_ARRAY(mem_ctx
, char, size
);
419 if (vfs
->data
== NULL
) {
420 printf("read: error=-1 (not enough memory)");
421 return NT_STATUS_UNSUCCESSFUL
;
423 vfs
->data_size
= size
;
425 rsize
= SMB_VFS_READ(vfs
->files
[fd
], vfs
->data
, size
);
427 printf("read: error=%d (%s)\n", errno
, strerror(errno
));
428 return NT_STATUS_UNSUCCESSFUL
;
431 printf("read: ok\n");
436 static NTSTATUS
cmd_write(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
441 printf("Usage: write <fd> <size>\n");
445 /* some error checking should go here */
447 size
= atoi(argv
[2]);
448 if (vfs
->data
== NULL
) {
449 printf("write: error=-1 (buffer empty, please populate it before writing)");
450 return NT_STATUS_UNSUCCESSFUL
;
453 if (vfs
->data_size
< size
) {
454 printf("write: error=-1 (buffer too small, please put some more data in)");
455 return NT_STATUS_UNSUCCESSFUL
;
458 wsize
= SMB_VFS_WRITE(vfs
->files
[fd
], vfs
->data
, size
);
461 printf("write: error=%d (%s)\n", errno
, strerror(errno
));
462 return NT_STATUS_UNSUCCESSFUL
;
465 printf("write: ok\n");
470 static NTSTATUS
cmd_lseek(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
472 int fd
, offset
, whence
;
476 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
481 offset
= atoi(argv
[2]);
482 whence
= atoi(argv
[3]);
484 case 1: whence
= SEEK_SET
; break;
485 case 2: whence
= SEEK_CUR
; break;
486 default: whence
= SEEK_END
;
489 pos
= SMB_VFS_LSEEK(vfs
->files
[fd
], offset
, whence
);
490 if (pos
== (SMB_OFF_T
)-1) {
491 printf("lseek: error=%d (%s)\n", errno
, strerror(errno
));
492 return NT_STATUS_UNSUCCESSFUL
;
495 printf("lseek: ok\n");
500 static NTSTATUS
cmd_rename(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
504 printf("Usage: rename <old> <new>\n");
508 ret
= SMB_VFS_RENAME(vfs
->conn
, argv
[1], argv
[2]);
510 printf("rename: error=%d (%s)\n", errno
, strerror(errno
));
511 return NT_STATUS_UNSUCCESSFUL
;
514 printf("rename: ok\n");
519 static NTSTATUS
cmd_fsync(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
523 printf("Usage: fsync <fd>\n");
528 ret
= SMB_VFS_FSYNC(vfs
->files
[fd
]);
530 printf("fsync: error=%d (%s)\n", errno
, strerror(errno
));
531 return NT_STATUS_UNSUCCESSFUL
;
534 printf("fsync: ok\n");
539 static NTSTATUS
cmd_stat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
544 struct passwd
*pwd
= NULL
;
545 struct group
*grp
= NULL
;
550 printf("Usage: stat <fname>\n");
554 ret
= SMB_VFS_STAT(vfs
->conn
, argv
[1], &st
);
556 printf("stat: error=%d (%s)\n", errno
, strerror(errno
));
557 return NT_STATUS_UNSUCCESSFUL
;
560 pwd
= sys_getpwuid(st
.st_ex_uid
);
561 if (pwd
!= NULL
) user
= pwd
->pw_name
;
562 else user
= null_string
;
563 grp
= sys_getgrgid(st
.st_ex_gid
);
564 if (grp
!= NULL
) group
= grp
->gr_name
;
565 else group
= null_string
;
567 printf("stat: ok\n");
568 printf(" File: %s", argv
[1]);
569 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
570 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
571 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
572 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
573 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
574 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
575 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
576 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
577 #ifdef HAVE_STAT_ST_BLOCKS
578 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
580 #ifdef HAVE_STAT_ST_BLKSIZE
581 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
583 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
584 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
585 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
586 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
587 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
588 (unsigned long)st
.st_ex_gid
, group
);
589 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
590 printf(" Access: %s", ctime(&tmp_time
));
591 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
592 printf(" Modify: %s", ctime(&tmp_time
));
593 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
594 printf(" Change: %s", ctime(&tmp_time
));
600 static NTSTATUS
cmd_fstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
605 struct passwd
*pwd
= NULL
;
606 struct group
*grp
= NULL
;
611 printf("Usage: fstat <fd>\n");
616 if (fd
< 0 || fd
>= 1024) {
617 printf("fstat: error=%d (file descriptor out of range)\n", EBADF
);
621 if (vfs
->files
[fd
] == NULL
) {
622 printf("fstat: error=%d (invalid file descriptor)\n", EBADF
);
626 if (SMB_VFS_FSTAT(vfs
->files
[fd
], &st
) == -1) {
627 printf("fstat: error=%d (%s)\n", errno
, strerror(errno
));
628 return NT_STATUS_UNSUCCESSFUL
;
631 pwd
= sys_getpwuid(st
.st_ex_uid
);
632 if (pwd
!= NULL
) user
= pwd
->pw_name
;
633 else user
= null_string
;
634 grp
= sys_getgrgid(st
.st_ex_gid
);
635 if (grp
!= NULL
) group
= grp
->gr_name
;
636 else group
= null_string
;
638 printf("fstat: ok\n");
639 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
640 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
641 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
642 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
643 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
644 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
645 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
646 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
647 #ifdef HAVE_STAT_ST_BLOCKS
648 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
650 #ifdef HAVE_STAT_ST_BLKSIZE
651 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
653 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
654 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
655 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
656 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
657 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
658 (unsigned long)st
.st_ex_gid
, group
);
659 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
660 printf(" Access: %s", ctime(&tmp_time
));
661 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
662 printf(" Modify: %s", ctime(&tmp_time
));
663 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
664 printf(" Change: %s", ctime(&tmp_time
));
670 static NTSTATUS
cmd_lstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
674 struct passwd
*pwd
= NULL
;
675 struct group
*grp
= NULL
;
680 printf("Usage: lstat <path>\n");
684 if (SMB_VFS_LSTAT(vfs
->conn
, argv
[1], &st
) == -1) {
685 printf("lstat: error=%d (%s)\n", errno
, strerror(errno
));
686 return NT_STATUS_UNSUCCESSFUL
;
689 pwd
= sys_getpwuid(st
.st_ex_uid
);
690 if (pwd
!= NULL
) user
= pwd
->pw_name
;
691 else user
= null_string
;
692 grp
= sys_getgrgid(st
.st_ex_gid
);
693 if (grp
!= NULL
) group
= grp
->gr_name
;
694 else group
= null_string
;
696 printf("lstat: ok\n");
697 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
698 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
699 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
700 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
701 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
702 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
703 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
704 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
705 #ifdef HAVE_STAT_ST_BLOCKS
706 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
708 #ifdef HAVE_STAT_ST_BLKSIZE
709 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
711 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
712 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
713 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
714 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
715 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
716 (unsigned long)st
.st_ex_gid
, group
);
717 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
718 printf(" Access: %s", ctime(&tmp_time
));
719 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
720 printf(" Modify: %s", ctime(&tmp_time
));
721 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
722 printf(" Change: %s", ctime(&tmp_time
));
728 static NTSTATUS
cmd_chmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
732 printf("Usage: chmod <path> <mode>\n");
736 mode
= atoi(argv
[2]);
737 if (SMB_VFS_CHMOD(vfs
->conn
, argv
[1], mode
) == -1) {
738 printf("chmod: error=%d (%s)\n", errno
, strerror(errno
));
739 return NT_STATUS_UNSUCCESSFUL
;
742 printf("chmod: ok\n");
747 static NTSTATUS
cmd_fchmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
752 printf("Usage: fchmod <fd> <mode>\n");
757 mode
= atoi(argv
[2]);
758 if (fd
< 0 || fd
>= 1024) {
759 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF
);
762 if (vfs
->files
[fd
] == NULL
) {
763 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF
);
767 if (SMB_VFS_FCHMOD(vfs
->files
[fd
], mode
) == -1) {
768 printf("fchmod: error=%d (%s)\n", errno
, strerror(errno
));
769 return NT_STATUS_UNSUCCESSFUL
;
772 printf("fchmod: ok\n");
777 static NTSTATUS
cmd_chown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
782 printf("Usage: chown <path> <uid> <gid>\n");
788 if (SMB_VFS_CHOWN(vfs
->conn
, argv
[1], uid
, gid
) == -1) {
789 printf("chown: error=%d (%s)\n", errno
, strerror(errno
));
790 return NT_STATUS_UNSUCCESSFUL
;
793 printf("chown: ok\n");
798 static NTSTATUS
cmd_fchown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
804 printf("Usage: fchown <fd> <uid> <gid>\n");
811 if (fd
< 0 || fd
>= 1024) {
812 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF
);
815 if (vfs
->files
[fd
] == NULL
) {
816 printf("fchown: error=%d (invalid file descriptor)\n", EBADF
);
819 if (SMB_VFS_FCHOWN(vfs
->files
[fd
], uid
, gid
) == -1) {
820 printf("fchown error=%d (%s)\n", errno
, strerror(errno
));
821 return NT_STATUS_UNSUCCESSFUL
;
824 printf("fchown: ok\n");
829 static NTSTATUS
cmd_getwd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
832 if (SMB_VFS_GETWD(vfs
->conn
, buf
) == NULL
) {
833 printf("getwd: error=%d (%s)\n", errno
, strerror(errno
));
834 return NT_STATUS_UNSUCCESSFUL
;
837 printf("getwd: %s\n", buf
);
841 static NTSTATUS
cmd_utime(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
843 struct smb_file_time ft
;
845 printf("Usage: utime <path> <access> <modify>\n");
851 ft
.atime
= convert_time_t_to_timespec(atoi(argv
[2]));
852 ft
.mtime
= convert_time_t_to_timespec(atoi(argv
[3]));
853 if (SMB_VFS_NTIMES(vfs
->conn
, argv
[1], &ft
) != 0) {
854 printf("utime: error=%d (%s)\n", errno
, strerror(errno
));
855 return NT_STATUS_UNSUCCESSFUL
;
858 printf("utime: ok\n");
862 static NTSTATUS
cmd_ftruncate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
867 printf("Usage: ftruncate <fd> <length>\n");
873 if (fd
< 0 || fd
>= 1024) {
874 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF
);
877 if (vfs
->files
[fd
] == NULL
) {
878 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF
);
882 if (SMB_VFS_FTRUNCATE(vfs
->files
[fd
], off
) == -1) {
883 printf("ftruncate: error=%d (%s)\n", errno
, strerror(errno
));
884 return NT_STATUS_UNSUCCESSFUL
;
887 printf("ftruncate: ok\n");
891 static NTSTATUS
cmd_lock(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
901 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
902 printf(" ops: G = F_GETLK\n");
903 printf(" S = F_SETLK\n");
904 printf(" W = F_SETLKW\n");
905 printf(" type: R = F_RDLCK\n");
906 printf(" W = F_WRLCK\n");
907 printf(" U = F_UNLCK\n");
911 if (sscanf(argv
[1], "%d", &fd
) == 0) {
912 printf("lock: error=-1 (error parsing fd)\n");
913 return NT_STATUS_UNSUCCESSFUL
;
928 printf("lock: error=-1 (invalid op flag!)\n");
929 return NT_STATUS_UNSUCCESSFUL
;
932 if (sscanf(argv
[3], "%ld", &offset
) == 0) {
933 printf("lock: error=-1 (error parsing fd)\n");
934 return NT_STATUS_UNSUCCESSFUL
;
937 if (sscanf(argv
[4], "%ld", &count
) == 0) {
938 printf("lock: error=-1 (error parsing fd)\n");
939 return NT_STATUS_UNSUCCESSFUL
;
956 printf("lock: error=-1 (invalid type flag!)\n");
957 return NT_STATUS_UNSUCCESSFUL
;
962 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd
, op
, offset
, count
, type
);
964 if (SMB_VFS_LOCK(vfs
->files
[fd
], op
, offset
, count
, type
) == False
) {
965 printf("lock: error=%d (%s)\n", errno
, strerror(errno
));
966 return NT_STATUS_UNSUCCESSFUL
;
969 printf("lock: ok\n");
973 static NTSTATUS
cmd_symlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
976 printf("Usage: symlink <path> <link>\n");
980 if (SMB_VFS_SYMLINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
981 printf("symlink: error=%d (%s)\n", errno
, strerror(errno
));
982 return NT_STATUS_UNSUCCESSFUL
;
985 printf("symlink: ok\n");
990 static NTSTATUS
cmd_readlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
992 char buffer
[PATH_MAX
];
996 printf("Usage: readlink <path>\n");
1000 if ((size
= SMB_VFS_READLINK(vfs
->conn
, argv
[1], buffer
, PATH_MAX
)) == -1) {
1001 printf("readlink: error=%d (%s)\n", errno
, strerror(errno
));
1002 return NT_STATUS_UNSUCCESSFUL
;
1005 buffer
[size
] = '\0';
1006 printf("readlink: %s\n", buffer
);
1007 return NT_STATUS_OK
;
1011 static NTSTATUS
cmd_link(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1014 printf("Usage: link <path> <link>\n");
1015 return NT_STATUS_OK
;
1018 if (SMB_VFS_LINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1019 printf("link: error=%d (%s)\n", errno
, strerror(errno
));
1020 return NT_STATUS_UNSUCCESSFUL
;
1023 printf("link: ok\n");
1024 return NT_STATUS_OK
;
1027 static NTSTATUS
cmd_mknod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1030 unsigned int dev_val
;
1034 printf("Usage: mknod <path> <mode> <dev>\n");
1035 printf(" mode is octal\n");
1036 printf(" dev is hex\n");
1037 return NT_STATUS_OK
;
1040 if (sscanf(argv
[2], "%ho", (unsigned short *)&mode
) == 0) {
1041 printf("open: error=-1 (invalid mode!)\n");
1042 return NT_STATUS_UNSUCCESSFUL
;
1045 if (sscanf(argv
[3], "%x", &dev_val
) == 0) {
1046 printf("open: error=-1 (invalid dev!)\n");
1047 return NT_STATUS_UNSUCCESSFUL
;
1049 dev
= (SMB_DEV_T
)dev_val
;
1051 if (SMB_VFS_MKNOD(vfs
->conn
, argv
[1], mode
, dev
) == -1) {
1052 printf("mknod: error=%d (%s)\n", errno
, strerror(errno
));
1053 return NT_STATUS_UNSUCCESSFUL
;
1056 printf("mknod: ok\n");
1057 return NT_STATUS_OK
;
1060 static NTSTATUS
cmd_realpath(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1062 char respath
[PATH_MAX
];
1065 printf("Usage: realpath <path>\n");
1066 return NT_STATUS_OK
;
1069 if (SMB_VFS_REALPATH(vfs
->conn
, argv
[1], respath
) == NULL
) {
1070 printf("realpath: error=%d (%s)\n", errno
, strerror(errno
));
1071 return NT_STATUS_UNSUCCESSFUL
;
1074 printf("realpath: ok\n");
1075 return NT_STATUS_OK
;
1078 struct cmd_set vfs_commands
[] = {
1082 { "load", cmd_load_module
, "Load a module", "load <module.so>" },
1083 { "populate", cmd_populate
, "Populate a data buffer", "populate <char> <size>" },
1084 { "showdata", cmd_show_data
, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1085 { "connect", cmd_connect
, "VFS connect()", "connect" },
1086 { "disconnect", cmd_disconnect
, "VFS disconnect()", "disconnect" },
1087 { "disk_free", cmd_disk_free
, "VFS disk_free()", "disk_free <path>" },
1088 { "opendir", cmd_opendir
, "VFS opendir()", "opendir <fname>" },
1089 { "readdir", cmd_readdir
, "VFS readdir()", "readdir" },
1090 { "mkdir", cmd_mkdir
, "VFS mkdir()", "mkdir <path>" },
1091 { "rmdir", cmd_pathfunc
, "VFS rmdir()", "rmdir <path>" },
1092 { "closedir", cmd_closedir
, "VFS closedir()", "closedir" },
1093 { "open", cmd_open
, "VFS open()", "open <fname>" },
1094 { "close", cmd_close
, "VFS close()", "close <fd>" },
1095 { "read", cmd_read
, "VFS read()", "read <fd> <size>" },
1096 { "write", cmd_write
, "VFS write()", "write <fd> <size>" },
1097 { "lseek", cmd_lseek
, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1098 { "rename", cmd_rename
, "VFS rename()", "rename <old> <new>" },
1099 { "fsync", cmd_fsync
, "VFS fsync()", "fsync <fd>" },
1100 { "stat", cmd_stat
, "VFS stat()", "stat <fname>" },
1101 { "fstat", cmd_fstat
, "VFS fstat()", "fstat <fd>" },
1102 { "lstat", cmd_lstat
, "VFS lstat()", "lstat <fname>" },
1103 { "unlink", cmd_pathfunc
, "VFS unlink()", "unlink <fname>" },
1104 { "chmod", cmd_chmod
, "VFS chmod()", "chmod <path> <mode>" },
1105 { "fchmod", cmd_fchmod
, "VFS fchmod()", "fchmod <fd> <mode>" },
1106 { "chown", cmd_chown
, "VFS chown()", "chown <path> <uid> <gid>" },
1107 { "fchown", cmd_fchown
, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1108 { "chdir", cmd_pathfunc
, "VFS chdir()", "chdir <path>" },
1109 { "getwd", cmd_getwd
, "VFS getwd()", "getwd" },
1110 { "utime", cmd_utime
, "VFS utime()", "utime <path> <access> <modify>" },
1111 { "ftruncate", cmd_ftruncate
, "VFS ftruncate()", "ftruncate <fd> <length>" },
1112 { "lock", cmd_lock
, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1113 { "symlink", cmd_symlink
, "VFS symlink()", "symlink <old> <new>" },
1114 { "readlink", cmd_readlink
, "VFS readlink()", "readlink <path>" },
1115 { "link", cmd_link
, "VFS link()", "link <oldpath> <newpath>" },
1116 { "mknod", cmd_mknod
, "VFS mknod()", "mknod <path> <mode> <dev>" },
1117 { "realpath", cmd_realpath
, "VFS realpath()", "realpath <path>" },