summaryrefslogtreecommitdiff
path: root/blockdev/linux/file_dev.c
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-04-27 22:56:20 +0200
committerCarl Hetherington <cth@carlh.net>2020-05-02 01:50:32 +0200
commit054612f2417b666ef0ae906dea3646674d2be5ed (patch)
tree517c595c4d80c6f61e2b21b315d32c13bf5fbee6 /blockdev/linux/file_dev.c
parentef0a4fdf9b85692e03a0f13ac4439c37a8b6d4aa (diff)
I don't think we need the whole authopen dance now we're running the writer as root.
Diffstat (limited to 'blockdev/linux/file_dev.c')
-rw-r--r--blockdev/linux/file_dev.c71
1 files changed, 9 insertions, 62 deletions
diff --git a/blockdev/linux/file_dev.c b/blockdev/linux/file_dev.c
index 2797248..4dc53f3 100644
--- a/blockdev/linux/file_dev.c
+++ b/blockdev/linux/file_dev.c
@@ -69,84 +69,31 @@ EXT4_BLOCKDEV_STATIC_INSTANCE(file_dev, EXT4_FILEDEV_BSIZE, 0, file_dev_open,
/******************************************************************************/
static int file_dev_open(struct ext4_blockdev *bdev)
{
-#ifdef __APPLE__
- /* We need to use authopen to open the device. It asks the user for permission
- * then give us an open fd over a socket.
- */
-
- int pipe[2];
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe) < 0) {
- return EFAULT;
- }
-
- pid_t pid = fork();
- if (pid < 0) {
- return EFAULT;
- }
-
- if (pid == 0) {
- close(pipe[0]);
- dup2(pipe[1], STDOUT_FILENO);
- execl("/usr/libexec/authopen", "/usr/libexec/authopen", "-stdoutpipe", "-w", "-a", fname, (char *) 0);
- exit(-1);
- }
-
- close(pipe[1]);
-
- int dev = -1;
-
- size_t const data_buffer_size = sizeof(struct cmsghdr) + sizeof(int);
- char data_buffer[data_buffer_size];
-
- struct iovec io_vec[1];
- io_vec[0].iov_base = data_buffer;
- io_vec[0].iov_len = data_buffer_size;
-
- socklen_t const cmsg_socket_size = CMSG_SPACE(sizeof(int));
- char cmsg_socket[cmsg_socket_size];
- struct msghdr message = { 0 };
- message.msg_iov = io_vec;
- message.msg_iovlen = 1;
- message.msg_control = cmsg_socket;
- message.msg_controllen = cmsg_socket_size;
+ dev_file = fopen(fname, "r+b");
- if (recvmsg(pipe[0], &message, 0) <= 0) {
+ if (!dev_file)
return EIO;
- }
- struct cmsghdr* cmsg_socket_header = CMSG_FIRSTHDR(&message);
- if (cmsg_socket_header && cmsg_socket_header->cmsg_level == SOL_SOCKET && cmsg_socket_header->cmsg_type == SCM_RIGHTS) {
- dev = *((int *) CMSG_DATA(cmsg_socket_header));
- }
+ /*No buffering at file.*/
+ setbuf(dev_file, 0);
+#ifdef __APPLE__
/* The fseek/ftell approach to finding the device's size does not seem
* to work on macOS so do it this way instead.
*/
uint64_t sectors = 0;
- if (ioctl(dev, DKIOCGETBLOCKCOUNT, &sectors) < 0) {
- close(dev);
+ if (ioctl(fileno(dev_file), DKIOCGETBLOCKCOUNT, &sectors) < 0) {
+ fclose(dev_file);
return EFAULT;
}
uint32_t sector_size = 0;
- if (ioctl(dev, DKIOCGETBLOCKSIZE, &sector_size) < 0) {
- close(dev);
+ if (ioctl(fileno(dev_file), DKIOCGETBLOCKSIZE, &sector_size) < 0) {
+ fclose(dev_file);
return EFAULT;
}
off_t size = sectors * sector_size;
-
- dev_file = fdopen(dev, "r+b");
#else
- dev_file = fopen(fname, "r+b");
-#endif
-
- if (!dev_file)
- return EIO;
-
- /*No buffering at file.*/
- setbuf(dev_file, 0);
-
-#ifndef __APPLE__
if (fseeko(dev_file, 0, SEEK_END))
return EFAULT;