space

package
v0.60.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package space answers "how much room is there?" for every surface a client asks it through: SFTP's statvfs@openssh.com, NFS FSSTAT, FTP AVBL, WebDAV's RFC 4331 quota properties, and `filex mount` (the manager API's action=space).

Why one answer

Each of those used to make up its own number: the account's quota when it had one, a round figure when it did not, and the figure was different on every surface (SFTP and the Linux mount said 1 PiB, NFS 32 TiB, FTP 1 TiB, the Windows mount 4 TiB half full, /dav nothing). A local storage on a RAID volume showed up in Windows Explorer as a 1 PB drive with nothing used (issue #116).

What the answer is

  • A path inside a storage: what the storage itself reports for it (storage.SpaceOf: the disk, the share, the server), capped by the account's quota when it has one.
  • The virtual root, the folder that lists the storages: the storages the caller can see, added up, a disk two of them share counted once. A client that maps the whole server as a drive asks about the root.
  • Nothing measurable (an object store, a driver that cannot say, a backend that did not answer) and no quota: Known is false and the surface answers with OrStandIn, large and finite, because zero makes WinSCP and Explorer report a full disk and refuse to copy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Figures

type Figures struct {
	Total uint64 `json:"total"`
	Used  uint64 `json:"used"`
	// Free is what the caller could still write.
	Free uint64 `json:"free"`
	// Known is false when nothing could be measured and no quota applies.
	Known bool `json:"known"`
}

Figures is the room at one location, in bytes.

func (Figures) Blocks

func (f Figures) Blocks(bs uint64) (blocks, bfree, bavail uint64)

Blocks counts f in blocks of bs bytes the way statvfs and statfs do: blocks is the size, bfree what is not in use (df's Used column is blocks-bfree) and bavail what can still be written.

func (Figures) OrStandIn

func (f Figures) OrStandIn() Figures

OrStandIn returns f, or, when f is unknown, a large disk with nothing used.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service answers for storages and for the virtual root. One per server, so every surface shares the cache.

func Ensure

func Ensure(s *Service, resolve func(int64) (storage.Driver, error), q *quota.Service) *Service

Ensure returns s, or a service of its own over resolve and q when s is nil: a protocol server whose wiring line was lost still answers with real figures, only without the shared cache.

func New

func New(resolve func(int64) (storage.Driver, error), q *quota.Service) *Service

New builds a service over the live driver resolver and the quota service (nil: no account has a quota).

func (*Service) Root

func (s *Service) Root(ctx context.Context, sts []*model.Storage) Figures

Root is the room at the virtual root over sts, the storages the caller can see: every storage's figures added up, a Volume two of them share counted once. Storages that cannot say are left out of the sum rather than guessed. For the account signed in on ctx.

func (*Service) Storage

func (s *Service) Storage(ctx context.Context, st *model.Storage, rel string) Figures

Storage is the room at rel inside st, for the account signed in on ctx.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL