Bladeren bron

Check if the target loopback is a block device

Guillaume J. Charmes 11 jaren geleden
bovenliggende
commit
8a5d927a53
2 gewijzigde bestanden met toevoegingen van 7 en 5 verwijderingen
  1. 3 2
      graphdriver/devmapper/attachLoopback.go
  2. 4 3
      graphdriver/devmapper/sys.go

+ 3 - 2
graphdriver/devmapper/attachLoopback.go

@@ -39,8 +39,9 @@ func openNextAvailableLoopback(index int, sparseFile *osFile) (loopFile *osFile,
 			return nil, ErrAttachLoopbackDevice
 		}
 
-		// FIXME: Check here if target is a block device (in C: S_ISBLK(mode))
-		if fi.IsDir() {
+		if fi.Mode()&osModeDevice != osModeDevice {
+			utils.Errorf("Loopback device %s is not a block device.", target)
+			continue
 		}
 
 		// Open the targeted loopback (use OpenFile because Open sets O_CLOEXEC)

+ 4 - 3
graphdriver/devmapper/sys.go

@@ -46,9 +46,10 @@ const (
 	sysSysIoctl = syscall.SYS_IOCTL
 	sysEBusy    = syscall.EBUSY
 
-	osORdOnly = os.O_RDONLY
-	osORdWr   = os.O_RDWR
-	osOCreate = os.O_CREATE
+	osORdOnly    = os.O_RDONLY
+	osORdWr      = os.O_RDWR
+	osOCreate    = os.O_CREATE
+	osModeDevice = os.ModeDevice
 )
 
 func toSysStatT(i interface{}) *sysStatT {