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
)
239 struct smb_filename
*smb_fname
= NULL
;
244 if (argc
< 3 || argc
> 5) {
245 printf("Usage: open <filename> <flags> <mode>\n");
246 printf(" flags: O = O_RDONLY\n");
247 printf(" R = O_RDWR\n");
248 printf(" W = O_WRONLY\n");
249 printf(" C = O_CREAT\n");
250 printf(" E = O_EXCL\n");
251 printf(" T = O_TRUNC\n");
252 printf(" A = O_APPEND\n");
253 printf(" N = O_NONBLOCK/O_NDELAY\n");
255 printf(" S = O_SYNC\n");
258 printf(" F = O_NOFOLLOW\n");
260 printf(" mode: see open.2\n");
261 printf(" mode is ignored if C flag not present\n");
262 printf(" mode defaults to 00400\n");
304 printf("open: error=-1 (invalid flag!)\n");
305 return NT_STATUS_UNSUCCESSFUL
;
309 if ((flags
& O_CREAT
) && argc
== 4) {
310 if (sscanf(argv
[3], "%ho", (unsigned short *)&mode
) == 0) {
311 printf("open: error=-1 (invalid mode!)\n");
312 return NT_STATUS_UNSUCCESSFUL
;
316 fsp
= SMB_MALLOC_P(struct files_struct
);
318 return NT_STATUS_NO_MEMORY
;
320 fsp
->fh
= SMB_MALLOC_P(struct fd_handle
);
321 if (fsp
->fh
== NULL
) {
322 SAFE_FREE(fsp
->fsp_name
);
324 return NT_STATUS_NO_MEMORY
;
326 fsp
->conn
= vfs
->conn
;
328 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
,
330 if (!NT_STATUS_IS_OK(status
)) {
335 fsp
->fsp_name
= smb_fname
;
337 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, smb_fname
, fsp
, flags
, mode
);
338 if (fsp
->fh
->fd
== -1) {
339 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
342 TALLOC_FREE(smb_fname
);
343 return NT_STATUS_UNSUCCESSFUL
;
346 vfs
->files
[fsp
->fh
->fd
] = fsp
;
347 printf("open: fd=%d\n", fsp
->fh
->fd
);
352 static NTSTATUS
cmd_pathfunc(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
357 printf("Usage: %s <path>\n", argv
[0]);
361 if (strcmp("rmdir", argv
[0]) == 0 ) {
362 ret
= SMB_VFS_RMDIR(vfs
->conn
, argv
[1]);
363 } else if (strcmp("unlink", argv
[0]) == 0 ) {
364 struct smb_filename
*smb_fname
= NULL
;
367 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1],
369 if (!NT_STATUS_IS_OK(status
)) {
373 ret
= SMB_VFS_UNLINK(vfs
->conn
, smb_fname
);
374 TALLOC_FREE(smb_fname
);
375 } else if (strcmp("chdir", argv
[0]) == 0 ) {
376 ret
= SMB_VFS_CHDIR(vfs
->conn
, argv
[1]);
378 printf("%s: error=%d (invalid function name!)\n", argv
[0], errno
);
379 return NT_STATUS_UNSUCCESSFUL
;
383 printf("%s: error=%d (%s)\n", argv
[0], errno
, strerror(errno
));
384 return NT_STATUS_UNSUCCESSFUL
;
387 printf("%s: ok\n", argv
[0]);
392 static NTSTATUS
cmd_close(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
397 printf("Usage: close <fd>\n");
402 if (vfs
->files
[fd
] == NULL
) {
403 printf("close: error=-1 (invalid file descriptor)\n");
407 ret
= SMB_VFS_CLOSE(vfs
->files
[fd
]);
409 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
411 printf("close: ok\n");
413 TALLOC_FREE(vfs
->files
[fd
]->fsp_name
);
414 SAFE_FREE(vfs
->files
[fd
]->fh
);
415 SAFE_FREE(vfs
->files
[fd
]);
416 vfs
->files
[fd
] = NULL
;
421 static NTSTATUS
cmd_read(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
427 printf("Usage: read <fd> <size>\n");
431 /* do some error checking on these */
433 size
= atoi(argv
[2]);
434 vfs
->data
= TALLOC_ARRAY(mem_ctx
, char, size
);
435 if (vfs
->data
== NULL
) {
436 printf("read: error=-1 (not enough memory)");
437 return NT_STATUS_UNSUCCESSFUL
;
439 vfs
->data_size
= size
;
441 rsize
= SMB_VFS_READ(vfs
->files
[fd
], vfs
->data
, size
);
443 printf("read: error=%d (%s)\n", errno
, strerror(errno
));
444 return NT_STATUS_UNSUCCESSFUL
;
447 printf("read: ok\n");
452 static NTSTATUS
cmd_write(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
457 printf("Usage: write <fd> <size>\n");
461 /* some error checking should go here */
463 size
= atoi(argv
[2]);
464 if (vfs
->data
== NULL
) {
465 printf("write: error=-1 (buffer empty, please populate it before writing)");
466 return NT_STATUS_UNSUCCESSFUL
;
469 if (vfs
->data_size
< size
) {
470 printf("write: error=-1 (buffer too small, please put some more data in)");
471 return NT_STATUS_UNSUCCESSFUL
;
474 wsize
= SMB_VFS_WRITE(vfs
->files
[fd
], vfs
->data
, size
);
477 printf("write: error=%d (%s)\n", errno
, strerror(errno
));
478 return NT_STATUS_UNSUCCESSFUL
;
481 printf("write: ok\n");
486 static NTSTATUS
cmd_lseek(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
488 int fd
, offset
, whence
;
492 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
497 offset
= atoi(argv
[2]);
498 whence
= atoi(argv
[3]);
500 case 1: whence
= SEEK_SET
; break;
501 case 2: whence
= SEEK_CUR
; break;
502 default: whence
= SEEK_END
;
505 pos
= SMB_VFS_LSEEK(vfs
->files
[fd
], offset
, whence
);
506 if (pos
== (SMB_OFF_T
)-1) {
507 printf("lseek: error=%d (%s)\n", errno
, strerror(errno
));
508 return NT_STATUS_UNSUCCESSFUL
;
511 printf("lseek: ok\n");
516 static NTSTATUS
cmd_rename(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
519 struct smb_filename
*smb_fname_src
= NULL
;
520 struct smb_filename
*smb_fname_dst
= NULL
;
524 printf("Usage: rename <old> <new>\n");
528 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
,
530 if (!NT_STATUS_IS_OK(status
)) {
534 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[2], NULL
,
536 if (!NT_STATUS_IS_OK(status
)) {
537 TALLOC_FREE(smb_fname_src
);
541 ret
= SMB_VFS_RENAME(vfs
->conn
, smb_fname_src
, smb_fname_dst
);
542 TALLOC_FREE(smb_fname_src
);
543 TALLOC_FREE(smb_fname_dst
);
545 printf("rename: error=%d (%s)\n", errno
, strerror(errno
));
546 return NT_STATUS_UNSUCCESSFUL
;
549 printf("rename: ok\n");
554 static NTSTATUS
cmd_fsync(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
558 printf("Usage: fsync <fd>\n");
563 ret
= SMB_VFS_FSYNC(vfs
->files
[fd
]);
565 printf("fsync: error=%d (%s)\n", errno
, strerror(errno
));
566 return NT_STATUS_UNSUCCESSFUL
;
569 printf("fsync: ok\n");
574 static NTSTATUS
cmd_stat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
579 struct passwd
*pwd
= NULL
;
580 struct group
*grp
= NULL
;
581 struct smb_filename
*smb_fname
= NULL
;
587 printf("Usage: stat <fname>\n");
591 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
,
593 if (!NT_STATUS_IS_OK(status
)) {
597 ret
= SMB_VFS_STAT(vfs
->conn
, smb_fname
);
599 printf("stat: error=%d (%s)\n", errno
, strerror(errno
));
600 TALLOC_FREE(smb_fname
);
601 return NT_STATUS_UNSUCCESSFUL
;
604 TALLOC_FREE(smb_fname
);
606 pwd
= sys_getpwuid(st
.st_ex_uid
);
607 if (pwd
!= NULL
) user
= pwd
->pw_name
;
608 else user
= null_string
;
609 grp
= sys_getgrgid(st
.st_ex_gid
);
610 if (grp
!= NULL
) group
= grp
->gr_name
;
611 else group
= null_string
;
613 printf("stat: ok\n");
614 printf(" File: %s", argv
[1]);
615 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
616 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
617 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
618 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
619 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
620 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
621 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
622 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
623 #ifdef HAVE_STAT_ST_BLOCKS
624 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
626 #ifdef HAVE_STAT_ST_BLKSIZE
627 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
629 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
630 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
631 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
632 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
633 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
634 (unsigned long)st
.st_ex_gid
, group
);
635 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
636 printf(" Access: %s", ctime(&tmp_time
));
637 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
638 printf(" Modify: %s", ctime(&tmp_time
));
639 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
640 printf(" Change: %s", ctime(&tmp_time
));
646 static NTSTATUS
cmd_fstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
651 struct passwd
*pwd
= NULL
;
652 struct group
*grp
= NULL
;
657 printf("Usage: fstat <fd>\n");
662 if (fd
< 0 || fd
>= 1024) {
663 printf("fstat: error=%d (file descriptor out of range)\n", EBADF
);
667 if (vfs
->files
[fd
] == NULL
) {
668 printf("fstat: error=%d (invalid file descriptor)\n", EBADF
);
672 if (SMB_VFS_FSTAT(vfs
->files
[fd
], &st
) == -1) {
673 printf("fstat: error=%d (%s)\n", errno
, strerror(errno
));
674 return NT_STATUS_UNSUCCESSFUL
;
677 pwd
= sys_getpwuid(st
.st_ex_uid
);
678 if (pwd
!= NULL
) user
= pwd
->pw_name
;
679 else user
= null_string
;
680 grp
= sys_getgrgid(st
.st_ex_gid
);
681 if (grp
!= NULL
) group
= grp
->gr_name
;
682 else group
= null_string
;
684 printf("fstat: ok\n");
685 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
686 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
687 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
688 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
689 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
690 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
691 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
692 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
693 #ifdef HAVE_STAT_ST_BLOCKS
694 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
696 #ifdef HAVE_STAT_ST_BLKSIZE
697 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
699 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
700 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
701 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
702 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
703 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
704 (unsigned long)st
.st_ex_gid
, group
);
705 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
706 printf(" Access: %s", ctime(&tmp_time
));
707 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
708 printf(" Modify: %s", ctime(&tmp_time
));
709 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
710 printf(" Change: %s", ctime(&tmp_time
));
716 static NTSTATUS
cmd_lstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
720 struct passwd
*pwd
= NULL
;
721 struct group
*grp
= NULL
;
722 struct smb_filename
*smb_fname
= NULL
;
728 printf("Usage: lstat <path>\n");
732 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
,
734 if (!NT_STATUS_IS_OK(status
)) {
738 if (SMB_VFS_LSTAT(vfs
->conn
, smb_fname
) == -1) {
739 printf("lstat: error=%d (%s)\n", errno
, strerror(errno
));
740 TALLOC_FREE(smb_fname
);
741 return NT_STATUS_UNSUCCESSFUL
;
744 TALLOC_FREE(smb_fname
);
746 pwd
= sys_getpwuid(st
.st_ex_uid
);
747 if (pwd
!= NULL
) user
= pwd
->pw_name
;
748 else user
= null_string
;
749 grp
= sys_getgrgid(st
.st_ex_gid
);
750 if (grp
!= NULL
) group
= grp
->gr_name
;
751 else group
= null_string
;
753 printf("lstat: ok\n");
754 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
755 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
756 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
757 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
758 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
759 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
760 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
761 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
762 #ifdef HAVE_STAT_ST_BLOCKS
763 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
765 #ifdef HAVE_STAT_ST_BLKSIZE
766 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
768 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
769 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
770 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
771 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
772 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
773 (unsigned long)st
.st_ex_gid
, group
);
774 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
775 printf(" Access: %s", ctime(&tmp_time
));
776 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
777 printf(" Modify: %s", ctime(&tmp_time
));
778 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
779 printf(" Change: %s", ctime(&tmp_time
));
785 static NTSTATUS
cmd_chmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
789 printf("Usage: chmod <path> <mode>\n");
793 mode
= atoi(argv
[2]);
794 if (SMB_VFS_CHMOD(vfs
->conn
, argv
[1], mode
) == -1) {
795 printf("chmod: error=%d (%s)\n", errno
, strerror(errno
));
796 return NT_STATUS_UNSUCCESSFUL
;
799 printf("chmod: ok\n");
804 static NTSTATUS
cmd_fchmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
809 printf("Usage: fchmod <fd> <mode>\n");
814 mode
= atoi(argv
[2]);
815 if (fd
< 0 || fd
>= 1024) {
816 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF
);
819 if (vfs
->files
[fd
] == NULL
) {
820 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF
);
824 if (SMB_VFS_FCHMOD(vfs
->files
[fd
], mode
) == -1) {
825 printf("fchmod: error=%d (%s)\n", errno
, strerror(errno
));
826 return NT_STATUS_UNSUCCESSFUL
;
829 printf("fchmod: ok\n");
834 static NTSTATUS
cmd_chown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
839 printf("Usage: chown <path> <uid> <gid>\n");
845 if (SMB_VFS_CHOWN(vfs
->conn
, argv
[1], uid
, gid
) == -1) {
846 printf("chown: error=%d (%s)\n", errno
, strerror(errno
));
847 return NT_STATUS_UNSUCCESSFUL
;
850 printf("chown: ok\n");
855 static NTSTATUS
cmd_fchown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
861 printf("Usage: fchown <fd> <uid> <gid>\n");
868 if (fd
< 0 || fd
>= 1024) {
869 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF
);
872 if (vfs
->files
[fd
] == NULL
) {
873 printf("fchown: error=%d (invalid file descriptor)\n", EBADF
);
876 if (SMB_VFS_FCHOWN(vfs
->files
[fd
], uid
, gid
) == -1) {
877 printf("fchown error=%d (%s)\n", errno
, strerror(errno
));
878 return NT_STATUS_UNSUCCESSFUL
;
881 printf("fchown: ok\n");
886 static NTSTATUS
cmd_getwd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
889 if (SMB_VFS_GETWD(vfs
->conn
, buf
) == NULL
) {
890 printf("getwd: error=%d (%s)\n", errno
, strerror(errno
));
891 return NT_STATUS_UNSUCCESSFUL
;
894 printf("getwd: %s\n", buf
);
898 static NTSTATUS
cmd_utime(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
900 struct smb_file_time ft
;
901 struct smb_filename
*smb_fname
= NULL
;
905 printf("Usage: utime <path> <access> <modify>\n");
911 ft
.atime
= convert_time_t_to_timespec(atoi(argv
[2]));
912 ft
.mtime
= convert_time_t_to_timespec(atoi(argv
[3]));
914 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1],
916 if (!NT_STATUS_IS_OK(status
)) {
920 if (SMB_VFS_NTIMES(vfs
->conn
, smb_fname
, &ft
) != 0) {
921 printf("utime: error=%d (%s)\n", errno
, strerror(errno
));
922 TALLOC_FREE(smb_fname
);
923 return NT_STATUS_UNSUCCESSFUL
;
926 TALLOC_FREE(smb_fname
);
927 printf("utime: ok\n");
931 static NTSTATUS
cmd_ftruncate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
936 printf("Usage: ftruncate <fd> <length>\n");
942 if (fd
< 0 || fd
>= 1024) {
943 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF
);
946 if (vfs
->files
[fd
] == NULL
) {
947 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF
);
951 if (SMB_VFS_FTRUNCATE(vfs
->files
[fd
], off
) == -1) {
952 printf("ftruncate: error=%d (%s)\n", errno
, strerror(errno
));
953 return NT_STATUS_UNSUCCESSFUL
;
956 printf("ftruncate: ok\n");
960 static NTSTATUS
cmd_lock(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
970 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
971 printf(" ops: G = F_GETLK\n");
972 printf(" S = F_SETLK\n");
973 printf(" W = F_SETLKW\n");
974 printf(" type: R = F_RDLCK\n");
975 printf(" W = F_WRLCK\n");
976 printf(" U = F_UNLCK\n");
980 if (sscanf(argv
[1], "%d", &fd
) == 0) {
981 printf("lock: error=-1 (error parsing fd)\n");
982 return NT_STATUS_UNSUCCESSFUL
;
997 printf("lock: error=-1 (invalid op flag!)\n");
998 return NT_STATUS_UNSUCCESSFUL
;
1001 if (sscanf(argv
[3], "%ld", &offset
) == 0) {
1002 printf("lock: error=-1 (error parsing fd)\n");
1003 return NT_STATUS_UNSUCCESSFUL
;
1006 if (sscanf(argv
[4], "%ld", &count
) == 0) {
1007 printf("lock: error=-1 (error parsing fd)\n");
1008 return NT_STATUS_UNSUCCESSFUL
;
1025 printf("lock: error=-1 (invalid type flag!)\n");
1026 return NT_STATUS_UNSUCCESSFUL
;
1031 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd
, op
, offset
, count
, type
);
1033 if (SMB_VFS_LOCK(vfs
->files
[fd
], op
, offset
, count
, type
) == False
) {
1034 printf("lock: error=%d (%s)\n", errno
, strerror(errno
));
1035 return NT_STATUS_UNSUCCESSFUL
;
1038 printf("lock: ok\n");
1039 return NT_STATUS_OK
;
1042 static NTSTATUS
cmd_symlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1045 printf("Usage: symlink <path> <link>\n");
1046 return NT_STATUS_OK
;
1049 if (SMB_VFS_SYMLINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1050 printf("symlink: error=%d (%s)\n", errno
, strerror(errno
));
1051 return NT_STATUS_UNSUCCESSFUL
;
1054 printf("symlink: ok\n");
1055 return NT_STATUS_OK
;
1059 static NTSTATUS
cmd_readlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1061 char buffer
[PATH_MAX
];
1065 printf("Usage: readlink <path>\n");
1066 return NT_STATUS_OK
;
1069 if ((size
= SMB_VFS_READLINK(vfs
->conn
, argv
[1], buffer
, PATH_MAX
)) == -1) {
1070 printf("readlink: error=%d (%s)\n", errno
, strerror(errno
));
1071 return NT_STATUS_UNSUCCESSFUL
;
1074 buffer
[size
] = '\0';
1075 printf("readlink: %s\n", buffer
);
1076 return NT_STATUS_OK
;
1080 static NTSTATUS
cmd_link(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1083 printf("Usage: link <path> <link>\n");
1084 return NT_STATUS_OK
;
1087 if (SMB_VFS_LINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1088 printf("link: error=%d (%s)\n", errno
, strerror(errno
));
1089 return NT_STATUS_UNSUCCESSFUL
;
1092 printf("link: ok\n");
1093 return NT_STATUS_OK
;
1096 static NTSTATUS
cmd_mknod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1099 unsigned int dev_val
;
1103 printf("Usage: mknod <path> <mode> <dev>\n");
1104 printf(" mode is octal\n");
1105 printf(" dev is hex\n");
1106 return NT_STATUS_OK
;
1109 if (sscanf(argv
[2], "%ho", (unsigned short *)&mode
) == 0) {
1110 printf("open: error=-1 (invalid mode!)\n");
1111 return NT_STATUS_UNSUCCESSFUL
;
1114 if (sscanf(argv
[3], "%x", &dev_val
) == 0) {
1115 printf("open: error=-1 (invalid dev!)\n");
1116 return NT_STATUS_UNSUCCESSFUL
;
1118 dev
= (SMB_DEV_T
)dev_val
;
1120 if (SMB_VFS_MKNOD(vfs
->conn
, argv
[1], mode
, dev
) == -1) {
1121 printf("mknod: error=%d (%s)\n", errno
, strerror(errno
));
1122 return NT_STATUS_UNSUCCESSFUL
;
1125 printf("mknod: ok\n");
1126 return NT_STATUS_OK
;
1129 static NTSTATUS
cmd_realpath(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1132 printf("Usage: realpath <path>\n");
1133 return NT_STATUS_OK
;
1136 if (SMB_VFS_REALPATH(vfs
->conn
, argv
[1]) == NULL
) {
1137 printf("realpath: error=%d (%s)\n", errno
, strerror(errno
));
1138 return NT_STATUS_UNSUCCESSFUL
;
1141 printf("realpath: ok\n");
1142 return NT_STATUS_OK
;
1145 struct cmd_set vfs_commands
[] = {
1149 { "load", cmd_load_module
, "Load a module", "load <module.so>" },
1150 { "populate", cmd_populate
, "Populate a data buffer", "populate <char> <size>" },
1151 { "showdata", cmd_show_data
, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1152 { "connect", cmd_connect
, "VFS connect()", "connect" },
1153 { "disconnect", cmd_disconnect
, "VFS disconnect()", "disconnect" },
1154 { "disk_free", cmd_disk_free
, "VFS disk_free()", "disk_free <path>" },
1155 { "opendir", cmd_opendir
, "VFS opendir()", "opendir <fname>" },
1156 { "readdir", cmd_readdir
, "VFS readdir()", "readdir" },
1157 { "mkdir", cmd_mkdir
, "VFS mkdir()", "mkdir <path>" },
1158 { "rmdir", cmd_pathfunc
, "VFS rmdir()", "rmdir <path>" },
1159 { "closedir", cmd_closedir
, "VFS closedir()", "closedir" },
1160 { "open", cmd_open
, "VFS open()", "open <fname>" },
1161 { "close", cmd_close
, "VFS close()", "close <fd>" },
1162 { "read", cmd_read
, "VFS read()", "read <fd> <size>" },
1163 { "write", cmd_write
, "VFS write()", "write <fd> <size>" },
1164 { "lseek", cmd_lseek
, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1165 { "rename", cmd_rename
, "VFS rename()", "rename <old> <new>" },
1166 { "fsync", cmd_fsync
, "VFS fsync()", "fsync <fd>" },
1167 { "stat", cmd_stat
, "VFS stat()", "stat <fname>" },
1168 { "fstat", cmd_fstat
, "VFS fstat()", "fstat <fd>" },
1169 { "lstat", cmd_lstat
, "VFS lstat()", "lstat <fname>" },
1170 { "unlink", cmd_pathfunc
, "VFS unlink()", "unlink <fname>" },
1171 { "chmod", cmd_chmod
, "VFS chmod()", "chmod <path> <mode>" },
1172 { "fchmod", cmd_fchmod
, "VFS fchmod()", "fchmod <fd> <mode>" },
1173 { "chown", cmd_chown
, "VFS chown()", "chown <path> <uid> <gid>" },
1174 { "fchown", cmd_fchown
, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1175 { "chdir", cmd_pathfunc
, "VFS chdir()", "chdir <path>" },
1176 { "getwd", cmd_getwd
, "VFS getwd()", "getwd" },
1177 { "utime", cmd_utime
, "VFS utime()", "utime <path> <access> <modify>" },
1178 { "ftruncate", cmd_ftruncate
, "VFS ftruncate()", "ftruncate <fd> <length>" },
1179 { "lock", cmd_lock
, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1180 { "symlink", cmd_symlink
, "VFS symlink()", "symlink <old> <new>" },
1181 { "readlink", cmd_readlink
, "VFS readlink()", "readlink <path>" },
1182 { "link", cmd_link
, "VFS link()", "link <oldpath> <newpath>" },
1183 { "mknod", cmd_mknod
, "VFS mknod()", "mknod <path> <mode> <dev>" },
1184 { "realpath", cmd_realpath
, "VFS realpath()", "realpath <path>" },