Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
medialibrary
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
57
Issues
57
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VideoLAN
medialibrary
Commits
4e039f6a
Commit
4e039f6a
authored
Jul 19, 2016
by
Felix Paul Kühne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file system: add stub implementation for appleOS
parent
f77656cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
215 additions
and
0 deletions
+215
-0
Makefile.am
Makefile.am
+7
-0
src/filesystem/darwin/Device.mm
src/filesystem/darwin/Device.mm
+208
-0
No files found.
Makefile.am
View file @
4e039f6a
...
...
@@ -155,9 +155,16 @@ if HAVE_LINUX
libmedialibrary_la_SOURCES
+=
\
src/filesystem/unix/Device.cpp
endif
if
HAVE_DARWIN
libmedialibrary_la_SOURCES
+=
\
src/filesystem/darwin/Device.mm
endif
endif
libmedialibrary_la_LDFLAGS
=
-no-undefined
-export-symbols-regex
'NewMediaLibrary'
if
HAVE_DARWIN
libmedialibrary_la_LDFLAGS
+=
-Wl
,-undefined,dynamic_lookup,-framework,Foundation
endif
libmedialibrary_la_CPPFLAGS
=
\
$(MEDIALIB_CPPFLAGS)
\
...
...
src/filesystem/darwin/Device.mm
0 → 100644
View file @
4e039f6a
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015-2016 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
* Felix Paul Kühne <fkuehne@videolan.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "../unix/Device.h"
#include "../unix/Directory.h"
#include "utils/Filename.h"
#include "logging/Logger.h"
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <dirent.h>
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#import <Foundation/Foundation.h>
namespace
{
// Allow private ctors to be used from make_shared
struct
DeviceBuilder
:
public
medialibrary
::
fs
::
Device
{
template
<
typename
...
Args
>
DeviceBuilder
(
Args
&&
...
args
)
:
Device
(
std
::
forward
<
Args
>
(
args
)...
)
{}
};
}
namespace
medialibrary
{
namespace
fs
{
Device
::
DeviceMap
Device
::
Devices
;
Device
::
MountpointMap
Device
::
Mountpoints
;
Device
::
DeviceCacheMap
Device
::
DeviceCache
;
Device
::
Device
(
const
std
::
string
&
uuid
,
const
std
::
string
&
mountpoint
,
bool
isRemovable
)
:
m_uuid
(
uuid
)
,
m_mountpoint
(
mountpoint
)
,
m_present
(
true
)
,
m_removable
(
isRemovable
)
{
if
(
*
m_mountpoint
.
crbegin
()
!=
'/'
)
m_mountpoint
+=
'/'
;
}
const
std
::
string
&
Device
::
uuid
()
const
{
return
m_uuid
;
}
bool
Device
::
isRemovable
()
const
{
return
m_removable
;
}
bool
Device
::
isPresent
()
const
{
return
m_present
;
}
const
std
::
string
&
Device
::
mountpoint
()
const
{
return
m_mountpoint
;
}
std
::
shared_ptr
<
IDevice
>
Device
::
fromPath
(
const
std
::
string
&
path
)
{
std
::
shared_ptr
<
IDevice
>
res
;
for
(
const
auto
&
p
:
DeviceCache
)
{
if
(
path
.
find
(
p
.
second
->
mountpoint
()
)
==
0
)
{
if
(
res
==
nullptr
||
res
->
mountpoint
().
length
()
<
p
.
second
->
mountpoint
().
length
()
)
res
=
p
.
second
;
}
}
return
res
;
}
std
::
shared_ptr
<
IDevice
>
Device
::
fromUuid
(
const
std
::
string
&
uuid
)
{
auto
it
=
DeviceCache
.
find
(
uuid
);
if
(
it
!=
end
(
DeviceCache
)
)
return
it
->
second
;
return
nullptr
;
}
bool
Device
::
populateCache
()
{
Devices
=
listDevices
();
Mountpoints
=
listMountpoints
();
DeviceCache
=
populateDeviceCache
();
return
true
;
}
Device
::
DeviceMap
Device
::
listDevices
()
{
DeviceMap
res
;
return
res
;
}
Device
::
MountpointMap
Device
::
listMountpoints
()
{
NSFileManager
*
fileManager
=
[[
NSFileManager
alloc
]
init
];
NSArray
*
mountedVolumes
=
[
fileManager
mountedVolumeURLsIncludingResourceValuesForKeys
:
nil
options
:
NSVolumeEnumerationSkipHiddenVolumes
];
NSLog
(
@"mountedVolumes: %@"
,
mountedVolumes
);
MountpointMap
res
;
return
res
;
}
Device
::
DeviceCacheMap
Device
::
populateDeviceCache
()
{
Device
::
DeviceCacheMap
res
;
for
(
const
auto
&
p
:
Mountpoints
)
{
const
auto
&
devicePath
=
p
.
first
;
auto
deviceName
=
utils
::
file
::
fileName
(
devicePath
);
const
auto
&
mountpoint
=
p
.
second
;
auto
it
=
Devices
.
find
(
deviceName
);
std
::
string
uuid
;
if
(
it
!=
end
(
Devices
)
)
uuid
=
it
->
second
;
else
{
deviceName
=
deviceFromDeviceMapper
(
devicePath
);
it
=
Devices
.
find
(
deviceName
);
if
(
it
!=
end
(
Devices
)
)
uuid
=
it
->
second
;
else
{
LOG_ERROR
(
"Failed to resolve mountpoint "
,
mountpoint
,
" to any known device"
);
continue
;
}
}
auto
removable
=
isRemovable
(
deviceName
,
mountpoint
);
LOG_INFO
(
"Adding device to cache: {"
,
uuid
,
"} mounted on "
,
mountpoint
,
" Removable: "
,
removable
);
res
[
uuid
]
=
std
::
make_shared
<
DeviceBuilder
>
(
uuid
,
mountpoint
,
removable
);
}
return
res
;
}
std
::
string
Device
::
deviceFromDeviceMapper
(
const
std
::
string
&
devicePath
)
{
if
(
devicePath
.
find
(
"/dev/mapper"
)
!=
0
)
return
{};
char
linkPath
[
PATH_MAX
];
if
(
readlink
(
devicePath
.
c_str
(),
linkPath
,
PATH_MAX
)
<
0
)
{
std
::
stringstream
err
;
err
<<
"Failed to resolve device -> mapper link: "
<<
devicePath
<<
" ("
<<
strerror
(
errno
)
<<
')'
;
throw
std
::
runtime_error
(
err
.
str
()
);
}
const
auto
dmName
=
utils
::
file
::
fileName
(
linkPath
);
std
::
string
dmSlavePath
=
"/sys/block/"
+
dmName
+
"/slaves"
;
std
::
unique_ptr
<
DIR
,
int
(
*
)(
DIR
*
)
>
dir
(
opendir
(
dmSlavePath
.
c_str
()
),
&
closedir
);
std
::
string
res
;
if
(
dir
==
nullptr
)
return
{};
dirent
*
result
;
while
(
(
result
=
readdir
(
dir
.
get
()
)
)
!=
nullptr
)
{
if
(
strcmp
(
result
->
d_name
,
"."
)
==
0
||
strcmp
(
result
->
d_name
,
".."
)
==
0
)
{
continue
;
}
if
(
res
.
empty
()
==
true
)
res
=
result
->
d_name
;
else
LOG_WARN
(
"More than one slave for device mapper "
,
linkPath
);
}
LOG_INFO
(
"Device mapper "
,
dmName
,
" maps to "
,
res
);
return
res
;
}
bool
Device
::
isRemovable
(
const
std
::
string
&
deviceName
,
const
std
::
string
&
mountpoint
)
{
return
false
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment