|
Lines 21-26
Link Here
|
| 21 |
#include <sys/stat.h> |
21 |
#include <sys/stat.h> |
| 22 |
#include <sys/socket.h> |
22 |
#include <sys/socket.h> |
| 23 |
#include <sys/param.h> |
23 |
#include <sys/param.h> |
|
|
24 |
#include <sys/statvfs.h> |
| 24 |
|
25 |
|
| 25 |
#include <ctype.h> |
26 |
#include <ctype.h> |
| 26 |
#include <errno.h> |
27 |
#include <errno.h> |
|
Lines 32-37
Link Here
|
| 32 |
#include <stdio.h> |
33 |
#include <stdio.h> |
| 33 |
#include <string.h> |
34 |
#include <string.h> |
| 34 |
#include <unistd.h> |
35 |
#include <unistd.h> |
|
|
36 |
#include <util.h> |
| 35 |
#include <stdarg.h> |
37 |
#include <stdarg.h> |
| 36 |
|
38 |
|
| 37 |
#include "xmalloc.h" |
39 |
#include "xmalloc.h" |
|
Lines 92-97
int remote_glob(struct sftp_conn *, cons
Link Here
|
| 92 |
#define I_CHGRP 2 |
94 |
#define I_CHGRP 2 |
| 93 |
#define I_CHMOD 3 |
95 |
#define I_CHMOD 3 |
| 94 |
#define I_CHOWN 4 |
96 |
#define I_CHOWN 4 |
|
|
97 |
#define I_DF 24 |
| 95 |
#define I_GET 5 |
98 |
#define I_GET 5 |
| 96 |
#define I_HELP 6 |
99 |
#define I_HELP 6 |
| 97 |
#define I_LCHDIR 7 |
100 |
#define I_LCHDIR 7 |
|
Lines 124-129
static const struct CMD cmds[] = {
Link Here
|
| 124 |
{ "chgrp", I_CHGRP }, |
127 |
{ "chgrp", I_CHGRP }, |
| 125 |
{ "chmod", I_CHMOD }, |
128 |
{ "chmod", I_CHMOD }, |
| 126 |
{ "chown", I_CHOWN }, |
129 |
{ "chown", I_CHOWN }, |
|
|
130 |
{ "df", I_DF }, |
| 127 |
{ "dir", I_LS }, |
131 |
{ "dir", I_LS }, |
| 128 |
{ "exit", I_QUIT }, |
132 |
{ "exit", I_QUIT }, |
| 129 |
{ "get", I_GET }, |
133 |
{ "get", I_GET }, |
|
Lines 188-193
help(void)
Link Here
|
| 188 |
printf("chgrp grp path Change group of file 'path' to 'grp'\n"); |
192 |
printf("chgrp grp path Change group of file 'path' to 'grp'\n"); |
| 189 |
printf("chmod mode path Change permissions of file 'path' to 'mode'\n"); |
193 |
printf("chmod mode path Change permissions of file 'path' to 'mode'\n"); |
| 190 |
printf("chown own path Change owner of file 'path' to 'own'\n"); |
194 |
printf("chown own path Change owner of file 'path' to 'own'\n"); |
|
|
195 |
printf("df [path] Display statistics for current directory or\n"); |
| 196 |
printf(" filesystem containing 'path'\n"); |
| 191 |
printf("help Display this help text\n"); |
197 |
printf("help Display this help text\n"); |
| 192 |
printf("get remote-path [local-path] Download file\n"); |
198 |
printf("get remote-path [local-path] Download file\n"); |
| 193 |
printf("lls [ls-options [path]] Display local directory listing\n"); |
199 |
printf("lls [ls-options [path]] Display local directory listing\n"); |
|
Lines 410-415
parse_ls_flags(char **argv, int argc, in
Link Here
|
| 410 |
} |
416 |
} |
| 411 |
|
417 |
|
| 412 |
static int |
418 |
static int |
|
|
419 |
parse_df_flags(const char *cmd, char **argv, int argc, int *hflag, int *iflag) |
| 420 |
{ |
| 421 |
extern int optind, optreset, opterr; |
| 422 |
int ch; |
| 423 |
|
| 424 |
optind = optreset = 1; |
| 425 |
opterr = 0; |
| 426 |
|
| 427 |
*hflag = *iflag = 0; |
| 428 |
while ((ch = getopt(argc, argv, "hi")) != -1) { |
| 429 |
switch (ch) { |
| 430 |
case 'h': |
| 431 |
*hflag = 1; |
| 432 |
break; |
| 433 |
case 'i': |
| 434 |
*iflag = 1; |
| 435 |
break; |
| 436 |
default: |
| 437 |
error("%s: Invalid flag -%c", cmd, ch); |
| 438 |
return -1; |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
return optind; |
| 443 |
} |
| 444 |
|
| 445 |
static int |
| 413 |
is_dir(char *path) |
446 |
is_dir(char *path) |
| 414 |
{ |
447 |
{ |
| 415 |
struct stat sb; |
448 |
struct stat sb; |
|
Lines 785-790
do_globbed_ls(struct sftp_conn *conn, ch
Link Here
|
| 785 |
return (0); |
818 |
return (0); |
| 786 |
} |
819 |
} |
| 787 |
|
820 |
|
|
|
821 |
static int |
| 822 |
do_df(struct sftp_conn *conn, char *path, int hflag, int iflag) |
| 823 |
{ |
| 824 |
struct statvfs st; |
| 825 |
char s_used[FMT_SCALED_STRSIZE]; |
| 826 |
char s_avail[FMT_SCALED_STRSIZE]; |
| 827 |
char s_root[FMT_SCALED_STRSIZE]; |
| 828 |
char s_total[FMT_SCALED_STRSIZE]; |
| 829 |
|
| 830 |
if (do_statvfs(conn, path, &st, 1) == -1) |
| 831 |
return -1; |
| 832 |
if (iflag) { |
| 833 |
printf(" Inodes Used Avail " |
| 834 |
"(root) %%Capacity\n"); |
| 835 |
printf("%11llu %11llu %11llu %11llu %3llu%%\n", |
| 836 |
(unsigned long long)st.f_files, |
| 837 |
(unsigned long long)(st.f_files - st.f_ffree), |
| 838 |
(unsigned long long)st.f_favail, |
| 839 |
(unsigned long long)st.f_ffree, |
| 840 |
(unsigned long long)(100 * (st.f_files - st.f_ffree) / |
| 841 |
st.f_files)); |
| 842 |
} else if (hflag) { |
| 843 |
strlcpy(s_used, "error", sizeof(s_used)); |
| 844 |
strlcpy(s_avail, "error", sizeof(s_avail)); |
| 845 |
strlcpy(s_root, "error", sizeof(s_root)); |
| 846 |
strlcpy(s_total, "error", sizeof(s_total)); |
| 847 |
fmt_scaled((st.f_blocks - st.f_bfree) * st.f_bsize, s_used); |
| 848 |
fmt_scaled(st.f_bavail * st.f_bsize, s_avail); |
| 849 |
fmt_scaled(st.f_bfree * st.f_bsize, s_root); |
| 850 |
fmt_scaled(st.f_blocks * st.f_bsize, s_total); |
| 851 |
printf(" Size Used Avail (root) %%Capacity\n"); |
| 852 |
printf("%7sB %7sB %7sB %7sB %3llu%%\n", |
| 853 |
s_total, s_used, s_avail, s_root, |
| 854 |
(unsigned long long)(100 * (st.f_blocks - st.f_bfree) / |
| 855 |
st.f_blocks)); |
| 856 |
} else { |
| 857 |
printf(" Size Used Avail " |
| 858 |
"(root) %%Capacity\n"); |
| 859 |
printf("%12llu %12llu %12llu %12llu %3llu%%\n", |
| 860 |
(unsigned long long)(st.f_bsize * st.f_blocks / 1024), |
| 861 |
(unsigned long long)(st.f_bsize * |
| 862 |
(st.f_blocks - st.f_bfree) / 1024), |
| 863 |
(unsigned long long)(st.f_bsize * st.f_bavail / 1024), |
| 864 |
(unsigned long long)(st.f_bsize * st.f_bfree / 1024), |
| 865 |
(unsigned long long)(100 * (st.f_blocks - st.f_bfree) / |
| 866 |
st.f_blocks)); |
| 867 |
} |
| 868 |
return 0; |
| 869 |
} |
| 870 |
|
| 788 |
/* |
871 |
/* |
| 789 |
* Undo escaping of glob sequences in place. Used to undo extra escaping |
872 |
* Undo escaping of glob sequences in place. Used to undo extra escaping |
| 790 |
* applied in makeargv() when the string is destined for a function that |
873 |
* applied in makeargv() when the string is destined for a function that |
|
Lines 960-966
makeargv(const char *arg, int *argcp)
Link Here
|
| 960 |
} |
1043 |
} |
| 961 |
|
1044 |
|
| 962 |
static int |
1045 |
static int |
| 963 |
parse_args(const char **cpp, int *pflag, int *lflag, int *iflag, |
1046 |
parse_args(const char **cpp, int *pflag, int *lflag, int *iflag, int *hflag, |
| 964 |
unsigned long *n_arg, char **path1, char **path2) |
1047 |
unsigned long *n_arg, char **path1, char **path2) |
| 965 |
{ |
1048 |
{ |
| 966 |
const char *cmd, *cp = *cpp; |
1049 |
const char *cmd, *cp = *cpp; |
|
Lines 1004-1010
parse_args(const char **cpp, int *pflag,
Link Here
|
| 1004 |
} |
1087 |
} |
| 1005 |
|
1088 |
|
| 1006 |
/* Get arguments and parse flags */ |
1089 |
/* Get arguments and parse flags */ |
| 1007 |
*lflag = *pflag = *n_arg = 0; |
1090 |
*lflag = *pflag = *hflag = *n_arg = 0; |
| 1008 |
*path1 = *path2 = NULL; |
1091 |
*path1 = *path2 = NULL; |
| 1009 |
optidx = 1; |
1092 |
optidx = 1; |
| 1010 |
switch (cmdnum) { |
1093 |
switch (cmdnum) { |
|
Lines 1056-1061
parse_args(const char **cpp, int *pflag,
Link Here
|
| 1056 |
if (cmdnum != I_RM) |
1139 |
if (cmdnum != I_RM) |
| 1057 |
undo_glob_escape(*path1); |
1140 |
undo_glob_escape(*path1); |
| 1058 |
break; |
1141 |
break; |
|
|
1142 |
case I_DF: |
| 1143 |
if ((optidx = parse_df_flags(cmd, argv, argc, hflag, |
| 1144 |
iflag)) == -1) |
| 1145 |
return -1; |
| 1146 |
/* Default to current directory if no path specified */ |
| 1147 |
if (argc - optidx < 1) |
| 1148 |
*path1 = NULL; |
| 1149 |
else { |
| 1150 |
*path1 = xstrdup(argv[optidx]); |
| 1151 |
undo_glob_escape(*path1); |
| 1152 |
} |
| 1153 |
break; |
| 1059 |
case I_LS: |
1154 |
case I_LS: |
| 1060 |
if ((optidx = parse_ls_flags(argv, argc, lflag)) == -1) |
1155 |
if ((optidx = parse_ls_flags(argv, argc, lflag)) == -1) |
| 1061 |
return(-1); |
1156 |
return(-1); |
|
Lines 1118-1124
parse_dispatch_command(struct sftp_conn
Link Here
|
| 1118 |
int err_abort) |
1213 |
int err_abort) |
| 1119 |
{ |
1214 |
{ |
| 1120 |
char *path1, *path2, *tmp; |
1215 |
char *path1, *path2, *tmp; |
| 1121 |
int pflag, lflag, iflag, cmdnum, i; |
1216 |
int pflag, lflag, iflag, hflag, cmdnum, i; |
| 1122 |
unsigned long n_arg; |
1217 |
unsigned long n_arg; |
| 1123 |
Attrib a, *aa; |
1218 |
Attrib a, *aa; |
| 1124 |
char path_buf[MAXPATHLEN]; |
1219 |
char path_buf[MAXPATHLEN]; |
|
Lines 1126-1132
parse_dispatch_command(struct sftp_conn
Link Here
|
| 1126 |
glob_t g; |
1221 |
glob_t g; |
| 1127 |
|
1222 |
|
| 1128 |
path1 = path2 = NULL; |
1223 |
path1 = path2 = NULL; |
| 1129 |
cmdnum = parse_args(&cmd, &pflag, &lflag, &iflag, &n_arg, |
1224 |
cmdnum = parse_args(&cmd, &pflag, &lflag, &iflag, &hflag, &n_arg, |
| 1130 |
&path1, &path2); |
1225 |
&path1, &path2); |
| 1131 |
|
1226 |
|
| 1132 |
if (iflag != 0) |
1227 |
if (iflag != 0) |
|
Lines 1219-1224
parse_dispatch_command(struct sftp_conn
Link Here
|
| 1219 |
|
1314 |
|
| 1220 |
path1 = make_absolute(path1, *pwd); |
1315 |
path1 = make_absolute(path1, *pwd); |
| 1221 |
err = do_globbed_ls(conn, path1, tmp, lflag); |
1316 |
err = do_globbed_ls(conn, path1, tmp, lflag); |
|
|
1317 |
break; |
| 1318 |
case I_DF: |
| 1319 |
/* Default to current directory if no path specified */ |
| 1320 |
if (path1 == NULL) |
| 1321 |
path1 = xstrdup(*pwd); |
| 1322 |
path1 = make_absolute(path1, *pwd); |
| 1323 |
err = do_df(conn, path1, hflag, iflag); |
| 1222 |
break; |
1324 |
break; |
| 1223 |
case I_LCHDIR: |
1325 |
case I_LCHDIR: |
| 1224 |
if (chdir(path1) == -1) { |
1326 |
if (chdir(path1) == -1) { |