Statfs returns into about the filing system if known The values will be -1 if they aren't known This information is cached for the DirCacheTime interval
()
| 657 | // |
| 658 | // This information is cached for the DirCacheTime interval |
| 659 | func (vfs *VFS) Statfs() (total, used, free int64) { |
| 660 | // defer log.Trace("/", "")("total=%d, used=%d, free=%d", &total, &used, &free) |
| 661 | vfs.usageMu.Lock() |
| 662 | defer vfs.usageMu.Unlock() |
| 663 | total, used, free = -1, -1, -1 |
| 664 | doAbout := vfs.f.Features().About |
| 665 | if (doAbout != nil || vfs.Opt.UsedIsSize) && (vfs.usageTime.IsZero() || time.Since(vfs.usageTime) >= time.Duration(vfs.Opt.DirCacheTime)) { |
| 666 | var err error |
| 667 | ctx := vfs.ctx |
| 668 | if doAbout == nil { |
| 669 | vfs.usage = &fs.Usage{} |
| 670 | } else { |
| 671 | vfs.usage, err = doAbout(ctx) |
| 672 | } |
| 673 | if vfs.Opt.UsedIsSize { |
| 674 | var usedBySizeAlgorithm int64 |
| 675 | // Algorithm from `rclone size` |
| 676 | err = walk.ListR(ctx, vfs.f, "", true, -1, walk.ListObjects, func(entries fs.DirEntries) error { |
| 677 | entries.ForObject(func(o fs.Object) { |
| 678 | usedBySizeAlgorithm += o.Size() |
| 679 | }) |
| 680 | return nil |
| 681 | }) |
| 682 | vfs.usage.Used = &usedBySizeAlgorithm |
| 683 | // if we read a Total size then we should calculate Free from it |
| 684 | if vfs.usage.Total != nil { |
| 685 | vfs.usage.Free = nil |
| 686 | } |
| 687 | } |
| 688 | vfs.usageTime = time.Now() |
| 689 | if err != nil { |
| 690 | fs.Errorf(vfs.f, "Statfs failed: %v", err) |
| 691 | return |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | if u := vfs.usage; u != nil { |
| 696 | if u.Total != nil { |
| 697 | total = *u.Total |
| 698 | } |
| 699 | if u.Free != nil { |
| 700 | free = *u.Free |
| 701 | } |
| 702 | if u.Used != nil { |
| 703 | used = *u.Used |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | if int64(vfs.Opt.DiskSpaceTotalSize) >= 0 { |
| 708 | total = int64(vfs.Opt.DiskSpaceTotalSize) |
| 709 | } |
| 710 | |
| 711 | total, used, free = fillInMissingSizes(total, used, free, unknownFreeBytes) |
| 712 | return |
| 713 | } |
| 714 | |
| 715 | // Remove removes the named file or (empty) directory. |
| 716 | func (vfs *VFS) Remove(name string) error { |