From 5a6a62e8596b6f3307e9429f7ccb9ae19b519c73 Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Wed, 6 Jan 2016 00:08:25 +0200 Subject: [PATCH 1/2] smbclient: query disk usage relative to current directory When querying disk usage in the "dir" and "du" commands, use the current directory. This behavior is compatible with Windows command shell "dir" command. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11662 Signed-off-by: Uri Simchoni Reviewed-by: Jeremy Allison (cherry picked from commit 275da6c5c7e7c5dd0581e919912eb82102903a46) --- source3/client/client.c | 2 +- source3/libsmb/cli_smb2_fnum.c | 5 +++-- source3/libsmb/cli_smb2_fnum.h | 1 + source3/libsmb/clifile.c | 5 +++-- source3/libsmb/proto.h | 3 ++- source3/torture/nbio.c | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/source3/client/client.c b/source3/client/client.c index 034b48a..ad56f26 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -312,7 +312,7 @@ static int do_dskattr(void) return 1; } - status = cli_disk_size(targetcli, &bsize, &total, &avail); + status = cli_disk_size(targetcli, targetpath, &bsize, &total, &avail); if (!NT_STATUS_IS_OK(status)) { d_printf("Error in dskattr: %s\n", nt_errstr(status)); return 1; diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c index 816ad13..c9f4060 100644 --- a/source3/libsmb/cli_smb2_fnum.c +++ b/source3/libsmb/cli_smb2_fnum.c @@ -1592,7 +1592,8 @@ NTSTATUS cli_smb2_setattrE(struct cli_state *cli, Synchronous only. ***************************************************************/ -NTSTATUS cli_smb2_dskattr(struct cli_state *cli, uint64_t *bsize, uint64_t *total, uint64_t *avail) +NTSTATUS cli_smb2_dskattr(struct cli_state *cli, const char *path, + uint64_t *bsize, uint64_t *total, uint64_t *avail) { NTSTATUS status; uint16_t fnum = 0xffff; @@ -1619,7 +1620,7 @@ NTSTATUS cli_smb2_dskattr(struct cli_state *cli, uint64_t *bsize, uint64_t *tota /* First open the top level directory. */ status = cli_smb2_create_fnum(cli, - "", + path, 0, /* create_flags */ FILE_READ_ATTRIBUTES, /* desired_access */ FILE_ATTRIBUTE_DIRECTORY, /* file attributes */ diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h index c97bc76..ceb5629 100644 --- a/source3/libsmb/cli_smb2_fnum.h +++ b/source3/libsmb/cli_smb2_fnum.h @@ -117,6 +117,7 @@ NTSTATUS cli_smb2_setattrE(struct cli_state *cli, time_t access_time, time_t write_time); NTSTATUS cli_smb2_dskattr(struct cli_state *cli, + const char *path, uint64_t *bsize, uint64_t *total, uint64_t *avail); diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 9e1975b..364376b 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -4199,7 +4199,8 @@ NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) return status; } -NTSTATUS cli_disk_size(struct cli_state *cli, uint64_t *bsize, uint64_t *total, uint64_t *avail) +NTSTATUS cli_disk_size(struct cli_state *cli, const char *path, uint64_t *bsize, + uint64_t *total, uint64_t *avail) { uint64_t sectors_per_block; uint64_t bytes_per_sector; @@ -4207,7 +4208,7 @@ NTSTATUS cli_disk_size(struct cli_state *cli, uint64_t *bsize, uint64_t *total, NTSTATUS status; if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { - return cli_smb2_dskattr(cli, bsize, total, avail); + return cli_smb2_dskattr(cli, path, bsize, total, avail); } /* diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index 5ebcf5f..c32bba7 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -513,7 +513,8 @@ struct tevent_req *cli_dskattr_send(TALLOC_CTX *mem_ctx, NTSTATUS cli_dskattr_recv(struct tevent_req *req, int *bsize, int *total, int *avail); NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail); -NTSTATUS cli_disk_size(struct cli_state *cli, uint64_t *bsize, uint64_t *total, uint64_t *avail); +NTSTATUS cli_disk_size(struct cli_state *cli, const char *path, uint64_t *bsize, + uint64_t *total, uint64_t *avail); struct tevent_req *cli_ctemp_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct cli_state *cli, diff --git a/source3/torture/nbio.c b/source3/torture/nbio.c index 6373a10..6c87f9a 100644 --- a/source3/torture/nbio.c +++ b/source3/torture/nbio.c @@ -287,7 +287,7 @@ void nb_qfsinfo(int level) { uint64_t bsize, total, avail; /* this is not the right call - we need cli_qfsinfo() */ - cli_disk_size(c, &bsize, &total, &avail); + cli_disk_size(c, "", &bsize, &total, &avail); } static NTSTATUS find_fn(const char *mnt, struct file_info *finfo, const char *name, -- 2.4.3 From c5477540145ecdf0391dfc6f0b24599081169404 Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Wed, 6 Jan 2016 00:12:36 +0200 Subject: [PATCH 2/2] selftest: more dfree command and smbclient disk usage tests Add tests that cover disk usage printing by smbclient, as well as passing directory info to the "dfree command" script. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11662 Signed-off-by: Uri Simchoni Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Wed Jan 6 03:58:59 CET 2016 on sn-devel-144 (cherry picked from commit 3e1b26bd6d0998c3af3d77f94eaac469434389be) --- selftest/target/Samba3.pm | 2 ++ source3/script/tests/test_dfree_command.sh | 17 ++++++++++++----- testprogs/blackbox/dfree.sh | 8 +++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm index 931667e..926f555 100755 --- a/selftest/target/Samba3.pm +++ b/selftest/target/Samba3.pm @@ -590,6 +590,8 @@ sub setup_fileserver($$) my $dfree_share_dir="$share_dir/dfree"; push(@dirs, $dfree_share_dir); + push(@dirs, "$dfree_share_dir/subdir1"); + push(@dirs, "$dfree_share_dir/subdir2"); my $fileserver_options = " [lowercase] diff --git a/source3/script/tests/test_dfree_command.sh b/source3/script/tests/test_dfree_command.sh index c9c3aa6..a60a52d 100755 --- a/source3/script/tests/test_dfree_command.sh +++ b/source3/script/tests/test_dfree_command.sh @@ -1,6 +1,7 @@ #!/bin/sh # -# Blackbox test for 'dfree command' +# Blackbox test for 'dfree command' and smbclient "l" +# command disk free printout. # if [ $# -lt 6 ]; then @@ -26,15 +27,16 @@ test_smbclient_dfree() { name="$1" share="$2" cmd="$3" + expected="$4" shift shift + shift subunit_start_test "$name" output=$($VALGRIND $smbclient //$SERVER/$share -c "$cmd" $@ 2>&1) status=$? if [ x$status = x0 ]; then - echo "$output" | grep "2000 blocks of size 1024. 20 blocks available" >/dev/null - status=$? - if [ x$status = x0 ]; then + received=$(echo "$output" | awk '/blocks of size/ {print $1, $5, $6}') + if [ "$expected" = "$received" ]; then subunit_pass_test "$name" else echo "$output" | subunit_fail_test "$name" @@ -46,6 +48,11 @@ test_smbclient_dfree() { } -test_smbclient_dfree "Test dfree command" dfree "l" -U$USERNAME%$PASSWORD || failed=`expr $failed + 1` +test_smbclient_dfree "Test dfree command share root SMB3" dfree "l" "2000 1024. 20" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1` +test_smbclient_dfree "Test dfree command share root NT1" dfree "l" "2000 1024. 20" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=NT1 || failed=`expr $failed + 1` +test_smbclient_dfree "Test dfree command subdir1 SMB3" dfree "cd subdir1; l" "8000 1024. 80" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1` +test_smbclient_dfree "Test dfree command subdir2 SMB3" dfree "cd subdir2; l" "32000 1024. 320" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1` +#SMB1 queries disk usage stat on the share's root, regardless of working directory +test_smbclient_dfree "Test dfree command subdir1 NT1" dfree "cd subdir1; l" "2000 1024. 20" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=NT1 || failed=`expr $failed + 1` exit $failed diff --git a/testprogs/blackbox/dfree.sh b/testprogs/blackbox/dfree.sh index 2da3cbd..64845cd 100755 --- a/testprogs/blackbox/dfree.sh +++ b/testprogs/blackbox/dfree.sh @@ -1,2 +1,8 @@ #!/bin/sh -echo "1000 10 2048" +if [ "$1" = "." ] ; then + echo "1000 10 2048" +elif [ "$1" = "subdir1" ] ; then + echo "2000 20 4096" +else + echo "4000 40 8192" +fi -- 2.4.3