Browse code

Check if the target loopback is a block device

Guillaume J. Charmes authored on 2013/11/28 11:21:17
Showing 2 changed files
... ...
@@ -39,8 +39,9 @@ func openNextAvailableLoopback(index int, sparseFile *osFile) (loopFile *osFile,
39 39
 			return nil, ErrAttachLoopbackDevice
40 40
 		}
41 41
 
42
-		// FIXME: Check here if target is a block device (in C: S_ISBLK(mode))
43
-		if fi.IsDir() {
42
+		if fi.Mode()&osModeDevice != osModeDevice {
43
+			utils.Errorf("Loopback device %s is not a block device.", target)
44
+			continue
44 45
 		}
45 46
 
46 47
 		// Open the targeted loopback (use OpenFile because Open sets O_CLOEXEC)
... ...
@@ -46,9 +46,10 @@ const (
46 46
 	sysSysIoctl = syscall.SYS_IOCTL
47 47
 	sysEBusy    = syscall.EBUSY
48 48
 
49
-	osORdOnly = os.O_RDONLY
50
-	osORdWr   = os.O_RDWR
51
-	osOCreate = os.O_CREATE
49
+	osORdOnly    = os.O_RDONLY
50
+	osORdWr      = os.O_RDWR
51
+	osOCreate    = os.O_CREATE
52
+	osModeDevice = os.ModeDevice
52 53
 )
53 54
 
54 55
 func toSysStatT(i interface{}) *sysStatT {