Match-id-7f42cd82b8c6b9d8e7fa94c7b5eea0a03384b838

This commit is contained in:
BianTanggui
2020-06-20 11:42:46 +08:00
parent 9aebca5339
commit 4f8bc73909

View File

@@ -12,6 +12,7 @@
#include <sys/fsuid.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h>
#include <sched.h>
#include <dirent.h>
@@ -19,10 +20,6 @@
#include <errno.h>
#include "securec.h"
#undef major
#undef minor
#include <sys/sysmacros.h>
#define DEVICE_NAME "davinci"
#define DAVINCI_MANAGER "davinci_manager"
#define DEVMM_SVM "devmm_svm"
@@ -37,7 +34,7 @@
#define MOUNT_SUBSTR_GAP 2
#define ROOT_SUBSTR_GAP 2
static const struct option g_cmdOpts[] = {
static struct option g_cmdOpts[] = {
{"devices", required_argument, 0, 'd'},
{"pid", required_argument, 0, 'p'},
{"rootfs", required_argument, 0, 'r'},
@@ -56,6 +53,13 @@ struct ParsedConfig {
int originNsFd;
};
struct PathInfo {
char* src;
size_t srcLen;
char* dst;
size_t dstLen;
};
static inline bool IsCmdArgsValid(struct CmdArgs *args)
{
return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0);
@@ -137,14 +141,32 @@ static int CreateFile(const char *path, mode_t mode)
return 0;
}
static int VerfifyPathInfo(const struct PathInfo* pathInfo)
{
if (pathInfo == NULL || pathInfo->dst == NULL || pathInfo->src == NULL) {
return -1;
}
return 0;
}
static int GetDeviceMntSrcDst(const char *rootfs, const char *deviceName,
char *src, size_t srcBufSize, char *dst, size_t dstBufSize)
struct PathInfo* pathInfo)
{
int ret;
error_t err;
char unresolvedDst[BUF_SIZE] = {0};
char resolvedDst[PATH_MAX] = {0};
ret = VerfifyPathInfo(pathInfo);
if (ret < 0) {
return -1;
}
size_t srcBufSize = pathInfo->srcLen;
size_t dstBufSize = pathInfo->dstLen;
char *src = pathInfo->src;
char *dst = pathInfo->dst;
ret = snprintf_s(src, srcBufSize, srcBufSize, "/dev/%s", deviceName);
if (ret < 0) {
return -1;
@@ -174,8 +196,9 @@ int MountDevice(const char *rootfs, const char *deviceName)
int ret;
char src[BUF_SIZE] = {0};
char dst[BUF_SIZE] = {0};
struct PathInfo pathInfo = {src, BUF_SIZE, dst, BUF_SIZE};
ret = GetDeviceMntSrcDst(rootfs, deviceName, src, BUF_SIZE, dst, BUF_SIZE);
ret = GetDeviceMntSrcDst(rootfs, deviceName, &pathInfo);
if (ret < 0) {
fprintf(stderr, "error: failed to get device mount src and(or) dst path, device name: %s\n", deviceName);
return -1;