// Return the approximate disk space needed to install the package
170067
func (hdr *RpmHeader) InstalledSize() (int64, error) {
	u, err := hdr.GetUint64Fallback(SIZE, LONGSIZE)
	if err != nil {
		return -1, err
	}
	return int64(u), nil
}
209173
func getDiskLimits(path string) (
	availableBytes, totalBytes, availableFiles, totalFiles uint64, err error) {
	// Notably we are using syscall rather than golang.org/x/sys/unix here.
	// The latter is broken on iOS with go1.11.8 (and likely earlier versions)
	// and always gives us 0 as available storage space. go1.12.3 is known to
	// work fine with sys/unix.
	var stat syscall.Statfs_t
	err = syscall.Statfs(path, &stat)
	if err != nil {
		return 0, 0, 0, 0, errors.WithStack(err)
	}

	// Bavail is the free block count for an unprivileged user.
	availableBytes = uint64(stat.Bavail) * uint64(stat.Bsize)
	totalBytes = uint64(stat.Blocks) * uint64(stat.Bsize)
	// Some filesystems, like btrfs, don't keep track of inodes.
	// (See https://github.com/keybase/client/issues/6206 .) Use
	// the total inode count to detect that case.
	if stat.Files > 0 {
		availableFiles = uint64(stat.Ffree)
		totalFiles = uint64(stat.Files)
	} else {
		availableFiles = math.MaxInt64
		totalFiles = math.MaxInt64
	}
	return availableBytes, totalBytes, availableFiles, totalFiles, nil
}
1130344
func checkDiskFree(diskPath string, neededSpace int64) (err error) {
	// We don't validate disk space or inode utilization on windows.
	// Each windows call to 'GetVolumeInformationW' takes around
	// 3-5seconds. And StatDISK is not supported by Go for solaris
	// and netbsd.
	if contains(ignoreDiskFreeOS, runtime.GOOS) {
		return nil
	}

	var di disk.Info
	di, err = getDiskInfo((diskPath))
	if err != nil {
		return err
	}

	if err = checkDiskMinFree(di); err != nil {
		return err
	}

	// Check if we have enough space to store data
	if neededSpace > int64(float64(di.Free)*0.95) {
		return errDiskFull
	}

	return nil
}
1239019
func GetSize(f *os.File) (ws Size, err error) {
	_, _, ec := syscall.Syscall(syscall.SYS_IOCTL,
		f.Fd(),
		uintptr(TIOCGWINSZ),
		uintptr(unsafe.Pointer(&ws)))

	err = getError(ec)

	if TIOCGWINSZ == 0 && err != nil {
		ws = Size{80, 25, 0, 0}
	}
	return ws, err
}
438384
func (l *WAL) DiskSizeBytes() int64 {
	return int64(l.tracker.OldSegmentSize() + l.tracker.CurrentSegmentSize())
}
846961
func (c *PackageFile) ArchiveSize() uint64 {
	if i := uint64(c.GetInt(0, 1007)); i > 0 {
		return i
	}

	return uint64(c.GetInt(1, 1046))
}
1238511
func GetVolumeSize(imageClient *gophercloud.ServiceClient, imageID string) (int, error) {
	sourceImage, err := images.Get(imageClient, imageID).Extract()
	if err != nil {
		return 0, err
	}

	if sourceImage.MinDiskGigabytes != 0 {
		return sourceImage.MinDiskGigabytes, nil
	}

	volumeSizeMB := sourceImage.SizeBytes / 1024 / 1024
	volumeSizeGB := int(sourceImage.SizeBytes / 1024 / 1024 / 1024)

	// Increment gigabytes size if the initial size can't be divided without
	// remainder.
	if volumeSizeMB%1024 > 0 {
		volumeSizeGB++
	}

	return volumeSizeGB, nil
}
813553
func (t *Terminal) GetSize() (int, int) {
	if err := t.open(); err != nil {
		return 80, 24
	}
	return t.engine.Size()
}
1147605
func (c *ServicedCli) cmdBackup(ctx *cli.Context)  {
	args := ctx.Args()
	if len(args) < 1 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "backup")
		c.exit(1)
		return
	}
	if ctx.Bool("check") {
		fmt.Printf("Checking for space...\n")
		if backupSpace, err := c.driver.GetBackupEstimate(args[0], ctx.StringSlice("exclude")); err != nil {
			fmt.Fprintf(os.Stderr, "Unable to estimate backup size: %s", err)
			c.exit(1)
			return
		} else {
			if ! backupSpace.AllowBackup {
				fmt.Fprintf(os.Stdout, "Unable to backup: estimated space required (%s) exceeds space available (%s) on %s\n", backupSpace.EstimatedString, backupSpace.AvailableString, backupSpace.BackupPath)
				c.exit(1)
				return
			}
			fmt.Printf("Okay to backup. Estimated space required: %s, Available: %s\n", backupSpace.EstimatedString, backupSpace.AvailableString)
		}
		fmt.Printf("Check only - not taking backup\n")
		return
	}
	// do backup
	if path, err := c.driver.Backup(args[0], ctx.StringSlice("exclude"), ctx.Bool("force")); err != nil {
		fmt.Fprintln(os.Stdout, err)
		c.exit(1)
		return
	} else if path == "" {
		fmt.Fprintln(os.Stderr, "received nil path to backup file")
		c.exit(1)
		return
	} else {
		fmt.Println(path)
	}
}
243349
func checkDiskMinTotal(di disk.Info) (err error) {
	// Remove 5% from total space for cumulative disk space
	// used for journalling, inodes etc.
	totalDiskSpace := float64(di.Total) * 0.95
	if int64(totalDiskSpace) <= diskMinTotalSpace {
		return errMinDiskSize
	}
	return nil
}
725279
func GetWinSize(fd int) *Winsize {
	ws := &Winsize{}
	retCode, _, errno := syscall.Syscall(
		syscall.SYS_IOCTL,
		uintptr(fd),
		uintptr(syscall.TIOCGWINSZ),
		uintptr(unsafe.Pointer(ws)))

	if int(retCode) == -1 {
		panic(errno)
	}
	return ws
}
1112669
func GetsizeFull(t *os.File) (size *Winsize, err error) {
	var ws Winsize
	err = windowRectCall(&ws, t.Fd(), syscall.TIOCGWINSZ)
	return &ws, err
}
360120
func MaximumDiskSize(size int64) Option {
	return func(p *params) {
		p.ext4opts = append(p.ext4opts, compactext4.MaximumDiskSize(size))
	}
}
2196
func GetSize() (*Size, error) {
	envSize := GetEnvWindowSize()
	if envSize != nil && envSize.Lines != 0 && envSize.Columns != 0 {
		return envSize, nil
	}

	fh, err := os.Open("/dev/tty")
	if err != nil {
		// no tty, no point continuing; we only let the environ
		// avoid an error in this case because if someone has faked
		// up an environ with LINES/COLUMNS _both_ set, we should let
		// them
		return nil, err
	}

	size, err := GetTerminalWindowSize(fh)
	if err != nil {
		if envSize != nil {
			return envSize, nil
		}
		return nil, err
	}
	if envSize == nil {
		return size, err
	}

	if envSize.Lines == 0 {
		envSize.Lines = size.Lines
	}
	if envSize.Columns == 0 {
		envSize.Columns = size.Columns
	}
	return envSize, nil
}
244675
func (t *terminal) GetWinSize() (*term.Winsize, error) {
	t.mu.Lock()
	defer t.mu.Unlock()
	if t.pty == nil {
		return nil, trace.NotFound("no pty")
	}
	ws, err := term.GetWinsize(t.pty.Fd())
	if err != nil {
		return nil, trace.Wrap(err)
	}
	return ws, nil
}
225801
func DiskUsage(d Datastore) (uint64, error) {
	persDs, ok := d.(PersistentDatastore)
	if !ok {
		return 0, nil
	}
	return persDs.DiskUsage()
}
61096
func DiskUsage(path string) (*resource.Quantity, error) {
	// Uses the same niceness level as cadvisor.fs does when running du
	// Uses -B 1 to always scale to a blocksize of 1 byte
	out, err := exec.Command("nice", "-n", "19", "du", "-s", "-B", "1", path).CombinedOutput()
	if err != nil {
		return nil, fmt.Errorf("failed command 'du' ($ nice -n 19 du -s -B 1) on path %s with error %v", path, err)
	}
	used, err := resource.ParseQuantity(strings.Fields(string(out))[0])
	if err != nil {
		return nil, fmt.Errorf("failed to parse 'du' output %s due to error %v", out, err)
	}
	used.Format = resource.BinarySI
	return &used, nil
}