Compare commits
10 Commits
3461ff5c9a
...
981e9b47b1
Author | SHA1 | Date |
---|---|---|
lambdadroid | 981e9b47b1 | 2 years ago |
Jani Lusikka | 943774c8e5 | 2 years ago |
Sam Mortimer | feca80c63d | 2 years ago |
Jani Lusikka | f4028eedc5 | 2 years ago |
Tom Marshall | 76c235ffe3 | 2 years ago |
Tom Marshall | af516f8875 | 2 years ago |
Michael Bestas | c803d524ea | 2 years ago |
Dan Pasanen | 584c493f5e | 2 years ago |
Luca Stefani | 6220c269ed | 3 years ago |
Eric Biggers | ca79199a58 | 3 years ago |
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
|
||||
#include <logwrap/logwrap.h>
|
||||
|
||||
#include "Ntfs.h"
|
||||
#include "Utils.h"
|
||||
|
||||
using android::base::StringPrintf;
|
||||
|
||||
namespace android {
|
||||
namespace vold {
|
||||
namespace ntfs {
|
||||
|
||||
static const char* kMkfsPath = "/system/bin/mkfs.ntfs";
|
||||
static const char* kFsckPath = "/system/bin/fsck.ntfs";
|
||||
static const char* kMountPath = "/system/bin/mount.ntfs";
|
||||
|
||||
bool IsSupported() {
|
||||
return access(kMkfsPath, X_OK) == 0
|
||||
&& access(kFsckPath, X_OK) == 0
|
||||
&& access(kMountPath, X_OK) == 0
|
||||
&& IsFilesystemSupported("ntfs");
|
||||
}
|
||||
|
||||
status_t Check(const std::string& source) {
|
||||
std::vector<std::string> cmd;
|
||||
cmd.push_back(kFsckPath);
|
||||
cmd.push_back("-n");
|
||||
cmd.push_back(source);
|
||||
|
||||
int rc = ForkExecvp(cmd, nullptr, sFsckUntrustedContext);
|
||||
if (rc == 0) {
|
||||
LOG(INFO) << "Check OK";
|
||||
return 0;
|
||||
} else {
|
||||
LOG(ERROR) << "Check failed (code " << rc << ")";
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
status_t Mount(const std::string& source, const std::string& target, int ownerUid, int ownerGid,
|
||||
int permMask) {
|
||||
auto mountData = android::base::StringPrintf("utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,"
|
||||
"shortname=mixed,nodev,nosuid,dirsync,noatime,"
|
||||
"noexec", ownerUid, ownerGid, permMask, permMask);
|
||||
|
||||
std::vector<std::string> cmd;
|
||||
cmd.push_back(kMountPath);
|
||||
cmd.push_back("-o");
|
||||
cmd.push_back(mountData.c_str());
|
||||
cmd.push_back(source.c_str());
|
||||
cmd.push_back(target.c_str());
|
||||
|
||||
int rc = ForkExecvp(cmd);
|
||||
if (rc == 0) {
|
||||
LOG(INFO) << "Mount OK";
|
||||
return 0;
|
||||
} else {
|
||||
LOG(ERROR) << "Mount failed (code " << rc << ")";
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
status_t Format(const std::string& source) {
|
||||
std::vector<std::string> cmd;
|
||||
cmd.push_back(kMkfsPath);
|
||||
cmd.push_back(source);
|
||||
|
||||
int rc = ForkExecvp(cmd);
|
||||
if (rc == 0) {
|
||||
LOG(INFO) << "Format OK";
|
||||
return 0;
|
||||
} else {
|
||||
LOG(ERROR) << "Format failed (code " << rc << ")";
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace ntfs
|
||||
} // namespace vold
|
||||
} // namespace android
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_VOLD_NTFS_H
|
||||
#define ANDROID_VOLD_NTFS_H
|
||||
|
||||
#include <utils/Errors.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace android {
|
||||
namespace vold {
|
||||
namespace ntfs {
|
||||
|
||||
bool IsSupported();
|
||||
|
||||
status_t Check(const std::string& source);
|
||||
status_t Mount(const std::string& source, const std::string& target, int ownerUid, int ownerGid,
|
||||
int permMask);
|
||||
status_t Format(const std::string& source);
|
||||
|
||||
} // namespace ntfs
|
||||
} // namespace vold
|
||||
} // namespace android
|
||||
|
||||
#endif
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Cyanogen, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "DiskPartition.h"
|
||||
#include "PublicVolume.h"
|
||||
#include "PrivateVolume.h"
|
||||
#include "Utils.h"
|
||||
#include "VolumeBase.h"
|
||||
#include "VolumeManager.h"
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <diskconfig/diskconfig.h>
|
||||
|
||||
#include <vector>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
using android::base::ReadFileToString;
|
||||
using android::base::WriteStringToFile;
|
||||
using android::base::StringPrintf;
|
||||
|
||||
namespace android {
|
||||
namespace vold {
|
||||
|
||||
DiskPartition::DiskPartition(const std::string& eventPath, dev_t device,
|
||||
const std::string& nickname, int flags, int partnum,
|
||||
const std::string& fstype /* = "" */, const std::string& mntopts /* = "" */) :
|
||||
Disk(eventPath, device, nickname, flags),
|
||||
mPartNum(partnum),
|
||||
mFsType(fstype),
|
||||
mMntOpts(mntopts) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
DiskPartition::~DiskPartition() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
status_t DiskPartition::create() {
|
||||
CHECK(!mCreated);
|
||||
mCreated = true;
|
||||
auto listener = VolumeManager::Instance()->getListener();
|
||||
if (listener) listener->onDiskCreated(getId(), mFlags);
|
||||
dev_t partDevice = makedev(major(mDevice), minor(mDevice) + mPartNum);
|
||||
createPublicVolume(partDevice, mFsType, mMntOpts);
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t DiskPartition::destroy() {
|
||||
CHECK(mCreated);
|
||||
destroyAllVolumes();
|
||||
mCreated = false;
|
||||
auto listener = VolumeManager::Instance()->getListener();
|
||||
if (listener) listener->onDiskDestroyed(getId());
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t DiskPartition::partitionPublic() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
status_t DiskPartition::partitionPrivate() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
status_t DiskPartition::partitionMixed(int8_t ratio) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace vold
|
||||
} // namespace android
|
||||
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Cyanogen, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_VOLD_DISKPARTITION_H
|
||||
#define ANDROID_VOLD_DISKPARTITION_H
|
||||
|
||||
#include "Disk.h"
|
||||
|
||||
namespace android {
|
||||
namespace vold {
|
||||
|
||||
/*
|
||||
* Representation of a single partition on physical media. Useful for
|
||||
* single media partitions such as "internal" sdcard partitions.
|
||||
*/
|
||||
|
||||
class DiskPartition : public Disk {
|
||||
public:
|
||||
DiskPartition(const std::string& eventPath, dev_t device,
|
||||
const std::string& nickname,
|
||||
int flags, int partnum,
|
||||
const std::string& fstype = "", const std::string& mntopts = "");
|
||||
virtual ~DiskPartition();
|
||||
|
||||
virtual status_t create();
|
||||
virtual status_t destroy();
|
||||
|
||||
virtual status_t partitionPublic();
|
||||
virtual status_t partitionPrivate();
|
||||
virtual status_t partitionMixed(int8_t ratio);
|
||||
|
||||
private:
|
||||
/* Partition number */
|
||||
int mPartNum;
|
||||
/* Filesystem type */
|
||||
std::string mFsType;
|
||||
/* Mount options */
|
||||
std::string mMntOpts;
|
||||
};
|
||||
|
||||
} // namespace vold
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in new issue