lib/efi: Add check for ioctl_iflags support
authorGeoff Levand <geoff@infradead.org>
Wed, 8 Aug 2018 00:01:10 +0000 (00:01 +0000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 14 Aug 2018 01:11:48 +0000 (11:11 +1000)
The efi tests may use a filesystem which does not support
ioctl_iflags.  Add a check and skip the ioctl_iflags
operations if not supported.

Signed-off-by: Geoff Levand <geoff@infradead.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
lib/efi/efivar.c

index 21c5d344f582b212eec8af2bcd53d93a11040b80..91b2507c67d8d70ece14e642b9f27ee8c818a68f 100644 (file)
@@ -83,17 +83,32 @@ int efi_del_variable(const char *guidstr, const char *name)
                return -1;
 
        rc = ioctl(fd, FS_IOC_GETFLAGS, &flag);
                return -1;
 
        rc = ioctl(fd, FS_IOC_GETFLAGS, &flag);
-       if (rc == -1)
+       if (rc == -1 && errno == ENOTTY) {
+               pb_debug_fn("'%s' does not support ioctl_iflags.\n",
+                       efivarfs_path);
+               goto delete;
+       } else if (rc == -1) {
+               pb_log_fn("FS_IOC_GETFLAGS failed: (%d) %s\n", errno,
+                       strerror(errno));
                goto exit;
                goto exit;
+       }
 
        flag &= ~FS_IMMUTABLE_FL;
        rc = ioctl(fd, FS_IOC_SETFLAGS, &flag);
 
        flag &= ~FS_IMMUTABLE_FL;
        rc = ioctl(fd, FS_IOC_SETFLAGS, &flag);
-       if (rc == -1)
+       if (rc == -1) {
+               pb_log_fn("FS_IOC_SETFLAGS failed: (%d) %s\n", errno,
+                       strerror(errno));
                goto exit;
                goto exit;
+       }
 
 
+delete:
        close(fd);
        fd = 0;
        rc = unlink(path);
        close(fd);
        fd = 0;
        rc = unlink(path);
+       if (rc == -1) {
+               pb_log_fn("unlink failed: (%d) %s\n", errno, strerror(errno));
+               goto exit;
+       }
 exit:
        talloc_free(path);
        close(fd);
 exit:
        talloc_free(path);
        close(fd);