Skip to content

Commit 2da40ee

Browse files
authored
fix block size reporting in Statfs() (#7)
Resolves #5
1 parent dc181e4 commit 2da40ee

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Installation
1717
Documentation
1818
-------------
1919

20-
http://godoc.org/github.com/cloudsoda/go-smb2
20+
https://pkg.go.dev/github.com/cloudsoda/go-smb2
2121

2222
Examples
2323
--------
@@ -72,7 +72,6 @@ package main
7272

7373
import (
7474
"io"
75-
"io/ioutil"
7675
"net"
7776

7877
"github.com/cloudsoda/go-smb2"
@@ -121,7 +120,7 @@ func main() {
121120
panic(err)
122121
}
123122

124-
bs, err := ioutil.ReadAll(f)
123+
bs, err := io.ReadAll(f)
125124
if err != nil {
126125
panic(err)
127126
}

client.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1419,13 +1419,19 @@ func (f *File) Statfs() (FileFsInfo, error) {
14191419
}
14201420

14211421
type FileFsInfo interface {
1422+
// The number of bytes in a single block on the volume. A block is the smallest allocation unit on the volume.
14221423
BlockSize() uint64
1424+
// Number of sectors in each block.
14231425
FragmentSize() uint64
1426+
// Total number of blocks on the volume that are available to the user.
14241427
TotalBlockCount() uint64
1428+
// Total number of blocks on the volume.
14251429
FreeBlockCount() uint64
1430+
// Total number of free blocks on the volume that are available to the user.
14261431
AvailableBlockCount() uint64
14271432
}
14281433

1434+
// Definitions: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/63768db7-9012-4209-8cca-00781e7322f5
14291435
type fileFsFullSizeInformation struct {
14301436
TotalAllocationUnits int64
14311437
CallerAvailableAllocationUnits int64
@@ -1435,7 +1441,7 @@ type fileFsFullSizeInformation struct {
14351441
}
14361442

14371443
func (fi *fileFsFullSizeInformation) BlockSize() uint64 {
1438-
return uint64(fi.BytesPerSector)
1444+
return uint64(fi.BytesPerSector) * uint64(fi.SectorsPerAllocationUnit)
14391445
}
14401446

14411447
func (fi *fileFsFullSizeInformation) FragmentSize() uint64 {

example_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package smb2_test
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
"net"
87

98
"github.com/cloudsoda/go-smb2"
@@ -53,7 +52,7 @@ func Example() {
5352
panic(err)
5453
}
5554

56-
bs, err := ioutil.ReadAll(f)
55+
bs, err := io.ReadAll(f)
5756
if err != nil {
5857
panic(err)
5958
}

go.mod

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@ go 1.20
44

55
require (
66
github.com/geoffgarside/ber v1.1.0
7-
golang.org/x/crypto v0.8.0
7+
github.com/stretchr/testify v1.8.3
8+
golang.org/x/crypto v0.9.0
9+
)
10+
11+
require (
12+
github.com/davecgh/go-spew v1.1.1 // indirect
13+
github.com/pmezard/go-difflib v1.0.0 // indirect
14+
gopkg.in/yaml.v3 v3.0.1 // indirect
815
)

go.sum

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13
github.com/geoffgarside/ber v1.1.0 h1:qTmFG4jJbwiSzSXoNJeHcOprVzZ8Ulde2Rrrifu5U9w=
24
github.com/geoffgarside/ber v1.1.0/go.mod h1:jVPKeCbj6MvQZhwLYsGwaGI52oUorHoHKNecGT85ZCc=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
8+
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
39
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
410
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
11+
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
12+
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
14+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
15+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
16+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

smb2_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/json"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"net"
1312
"os"
1413
"reflect"
@@ -18,6 +17,7 @@ import (
1817
"time"
1918

2019
"github.com/cloudsoda/go-smb2"
20+
"github.com/stretchr/testify/require"
2121
)
2222

2323
func join(ss ...string) string {
@@ -189,9 +189,8 @@ func TestReaddir(t *testing.T) {
189189
}
190190

191191
fi2, err = d2.Readdir(1)
192-
if err != io.EOF {
193-
t.Error("unexpected error: ", err)
194-
}
192+
require.Equal(t, io.EOF, err)
193+
require.Empty(t, fi2)
195194
}
196195

197196
func TestFile(t *testing.T) {
@@ -355,7 +354,7 @@ func TestSymlink(t *testing.T) {
355354

356355
f, err = fs.Open(testDir + `\linkToTestFile`)
357356
if err == nil { // if it supports follow-symlink
358-
bs, err := ioutil.ReadAll(f)
357+
bs, err := io.ReadAll(f)
359358
if err != nil {
360359
t.Fatal(err)
361360
}
@@ -484,7 +483,7 @@ func TestRename(t *testing.T) {
484483
t.Fatal(err)
485484
}
486485
defer f.Close()
487-
bs, err := ioutil.ReadAll(f)
486+
bs, err := io.ReadAll(f)
488487
if err != nil {
489488
t.Fatal(err)
490489
}

0 commit comments

Comments
 (0)