goduf-byinode_unix.go
author Mikael Berthe <mikael@lilotux.net>
Sun, 29 Jun 2014 17:47:31 +0200
changeset 17 7e73bb91665e
parent 3 d08d45871171
child 18 5219596f5c71
permissions -rw-r--r--
Add copyright notices to the arch-specific files

/*
 * Copyright (C) 2014 Mikael Berthe <mikael@lilotux.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 */

// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris

package main

import "os"
import "syscall"

// ByInode is a FileObjList type with a sort interface
type ByInode FileObjList

func (a ByInode) Len() int      { return len(a) }
func (a ByInode) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByInode) Less(i, j int) bool {
	// Sort by device id first
	iDevice := a[i].Sys().(*syscall.Stat_t).Dev
	jDevice := a[j].Sys().(*syscall.Stat_t).Dev
	switch {
	case iDevice < jDevice:
		return true
	case iDevice > jDevice:
		return false
	}
	iInode := a[i].Sys().(*syscall.Stat_t).Ino
	jInode := a[j].Sys().(*syscall.Stat_t).Ino
	return iInode < jInode
}

// OSHasInodes returns true iff the O.S. uses inodes for its filesystems.
func OSHasInodes() bool {
	return true
}

// GetDevIno returns the device and inode IDs of a given file.
func GetDevIno(fi os.FileInfo) (uint64, uint64) {
	dev := fi.Sys().(*syscall.Stat_t).Dev
	ino := fi.Sys().(*syscall.Stat_t).Ino
	return uint64(dev), uint64(ino)
}