github.com/stolowski/snapd@v0.0.0-20210407085831-115137ce5a22/osutil/nfs_linux.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package osutil 21 22 import ( 23 "fmt" 24 "strings" 25 ) 26 27 // IsHomeUsingNFS returns true if NFS mounts are defined or mounted under /home. 28 // 29 // Internally /proc/self/mountinfo and /etc/fstab are interrogated (for current 30 // and possible mounted filesystems). If either of those describes NFS 31 // filesystem mounted under or beneath /home/ then the return value is true. 32 func IsHomeUsingNFS() (bool, error) { 33 mountinfo, err := LoadMountInfo() 34 if err != nil { 35 return false, fmt.Errorf("cannot parse mountinfo: %s", err) 36 } 37 for _, entry := range mountinfo { 38 if (entry.FsType == "nfs4" || entry.FsType == "nfs" || entry.FsType == "autofs") && (strings.HasPrefix(entry.MountDir, "/home/") || entry.MountDir == "/home") { 39 return true, nil 40 } 41 } 42 fstab, err := LoadMountProfile(etcFstab) 43 if err != nil { 44 return false, fmt.Errorf("cannot parse %s: %s", etcFstab, err) 45 } 46 for _, entry := range fstab.Entries { 47 if (entry.Type == "nfs4" || entry.Type == "nfs") && (strings.HasPrefix(entry.Dir, "/home/") || entry.Dir == "/home") { 48 return true, nil 49 } 50 } 51 return false, nil 52 }