Skip to content

Commit

Permalink
Store DADiskRef for every mounted volume
Browse files Browse the repository at this point in the history
  • Loading branch information
bfleischer committed Jan 7, 2017
1 parent b2f7f79 commit 9adef7e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
3 changes: 3 additions & 0 deletions configure.ac
Expand Up @@ -76,6 +76,9 @@ AC_ARG_WITH([libiconv-prefix],
AM_ICONV
libfuse_libs="$libfuse_libs $LTLIBICONV"
AM_CONDITIONAL(ICONV, test "$am_cv_func_iconv" = yes)
if test "$arch" = darwin; then
libfuse_libs="$libfuse_libs -framework CoreFoundation -framework DiskArbitration"
fi
AC_SUBST(libfuse_libs)

if test -z "$MOUNT_FUSE_PATH"; then
Expand Down
11 changes: 10 additions & 1 deletion lib/fuse_darwin.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2006-2008 Amit Singh/Google Inc.
* Copyright (c) 2012 Anatol Pomozov
* Copyright (c) 2011-2016 Benjamin Fleischer
* Copyright (c) 2011-2017 Benjamin Fleischer
*/

#include "fuse_i.h"
Expand All @@ -20,6 +20,8 @@
#include <sys/types.h>
#include <unistd.h>

#include <CoreFoundation/CoreFoundation.h>

/*
* Semaphore implementation based on:
*
Expand Down Expand Up @@ -367,6 +369,8 @@ fuse_remove_signal_handlers_internal_np(void)

/********************/

DASessionRef fuse_dasession;

pthread_mutex_t mount_lock;
hash_table *mount_hash;
int mount_count;
Expand All @@ -378,6 +382,8 @@ static void fuse_lib_destructor(void) __attribute__((destructor));
static void
fuse_lib_constructor(void)
{
fuse_dasession = DASessionCreate(NULL);

pthread_mutex_init(&mount_lock, NULL);
mount_hash = hash_create(OSXFUSE_NDEVICES);
mount_count = 0;
Expand All @@ -398,4 +404,7 @@ fuse_lib_destructor(void)
free(mount_hash);
mount_hash = NULL;
mount_count = 0;

CFRelease(fuse_dasession);
fuse_dasession = NULL;
}
11 changes: 7 additions & 4 deletions lib/fuse_darwin_private.h
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2006-2008 Amit Singh/Google Inc.
* Copyright (c) 2011-2016 Benjamin Fleischer
* Copyright (c) 2011-2017 Benjamin Fleischer
*/

#ifdef __APPLE__
Expand All @@ -24,15 +24,16 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
#include <time.h>


#include <DiskArbitration/DiskArbitration.h>

#ifdef __cplusplus
}
#endif

/* Semaphores */

struct __local_sem_t
{
struct __local_sem_t {
unsigned int count;
pthread_mutex_t count_lock;
pthread_cond_t count_cond;
Expand Down Expand Up @@ -87,6 +88,8 @@ void fuse_exit_handler_internal_np(void);

int fuse_remove_signal_handlers_internal_np(void);

extern DASessionRef fuse_dasession;

/*
* The mount_hash maps char* mountpoint -> struct mount_info. It is protected
* by the mount_lock mutex, which is held across a mount operation.
Expand Down
14 changes: 14 additions & 0 deletions lib/fuse_i.h
Expand Up @@ -6,9 +6,17 @@
See the file COPYING.LIB
*/

/*
* Copyright (c) 2017 Benjamin Fleischer
*/

#include "fuse.h"
#include "fuse_lowlevel.h"

#ifdef __APPLE__
# include <DiskArbitration/DiskArbitration.h>
#endif

struct fuse_chan;
struct fuse_ll;

Expand Down Expand Up @@ -106,6 +114,12 @@ struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args,
size_t op_size, void *userdata);

void fuse_kern_unmount_compat22(const char *mountpoint);

#ifdef __APPLE__
DADiskRef fuse_chan_disk(struct fuse_chan *ch);
void fuse_chan_set_disk(struct fuse_chan *ch, DADiskRef disk);
#endif

int fuse_chan_clearfd(struct fuse_chan *ch);

void fuse_kern_unmount(const char *mountpoint, int fd);
Expand Down
32 changes: 31 additions & 1 deletion lib/fuse_session.c
Expand Up @@ -8,7 +8,7 @@

/*
* Copyright (c) 2006-2008 Amit Singh/Google Inc.
* Copyright (c) 2011-2012 Benjamin Fleischer
* Copyright (c) 2011-2017 Benjamin Fleischer
*/

#include "fuse_i.h"
Expand All @@ -25,11 +25,19 @@
# include <sys/param.h>
#endif

#ifdef __APPLE__
# include <CoreFoundation/CoreFoundation.h>
#endif

struct fuse_chan {
struct fuse_chan_ops op;

struct fuse_session *se;

#ifdef __APPLE__
DADiskRef disk;
#endif

int fd;

size_t bufsize;
Expand Down Expand Up @@ -185,6 +193,24 @@ struct fuse_chan *fuse_chan_new_compat24(struct fuse_chan_ops_compat24 *op,
data, 24);
}

#ifdef __APPLE__

DADiskRef fuse_chan_disk(struct fuse_chan *ch)
{
return ch->disk;
}

void fuse_chan_set_disk(struct fuse_chan *ch, DADiskRef disk)
{
if (ch->disk)
CFRelease(ch->disk);
if (disk)
CFRetain(disk);
ch->disk = disk;
}

#endif /* __APPLE__ */

int fuse_chan_fd(struct fuse_chan *ch)
{
return ch->fd;
Expand Down Expand Up @@ -240,6 +266,10 @@ void fuse_chan_destroy(struct fuse_chan *ch)
fuse_session_remove_chan(ch);
if (ch->op.destroy)
ch->op.destroy(ch);
#ifdef __APPLE__
if (ch->disk)
CFRelease(ch->disk);
#endif
free(ch);
}

Expand Down
23 changes: 22 additions & 1 deletion lib/helper.c
Expand Up @@ -8,7 +8,7 @@

/*
* Copyright (c) 2006-2008 Amit Singh/Google Inc.
* Copyright (c) 2011-2016 Benjamin Fleischer
* Copyright (c) 2011-2017 Benjamin Fleischer
*/

#include "config.h"
Expand All @@ -30,6 +30,11 @@
#include <errno.h>
#include <sys/param.h>

#ifdef __APPLE__
# include <CoreFoundation/CoreFoundation.h>
# include <DiskArbitration/DiskArbitration.h>
#endif

enum {
KEY_HELP,
KEY_HELP_NOHEADER,
Expand Down Expand Up @@ -257,6 +262,11 @@ static struct fuse_chan *fuse_mount_common(const char *mountpoint,
struct fuse_chan *ch;
int fd;

#ifdef __APPLE__
CFURLRef mountpoint_url;
DADiskRef disk;
#endif

/*
* Make sure file descriptors 0, 1 and 2 are open, otherwise chaos
* would ensue.
Expand All @@ -275,6 +285,17 @@ static struct fuse_chan *fuse_mount_common(const char *mountpoint,
if (!ch)
fuse_kern_unmount(mountpoint, fd);

#ifdef __APPLE__
mountpoint_url = CFURLCreateFromFileSystemRepresentation(
NULL, (const UInt8 *)mountpoint, strlen(mountpoint), TRUE);

disk = DADiskCreateFromVolumePath(NULL, fuse_dasession, mountpoint_url);
fuse_chan_set_disk(ch, disk);
CFRelease(disk);

CFRelease(mountpoint_url);
#endif

return ch;
}

Expand Down

0 comments on commit 9adef7e

Please sign in to comment.