本文整理汇总了C++中qemu_open函数的典型用法代码示例。如果您正苦于以下问题:C++ qemu_open函数的具体用法?C++ qemu_open怎么用?C++ qemu_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qemu_open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: qemu_char_open
static void qemu_char_open(Chardev *chr, ChardevBackend *backend,
bool *be_opened, Error **errp)
{
ChardevClass *cc = CHARDEV_GET_CLASS(chr);
/* Any ChardevCommon member would work */
ChardevCommon *common = backend ? backend->u.null.data : NULL;
if (common && common->has_logfile) {
int flags = O_WRONLY | O_CREAT;
if (common->has_logappend &&
common->logappend) {
flags |= O_APPEND;
} else {
flags |= O_TRUNC;
}
chr->logfd = qemu_open(common->logfile, flags, 0666);
if (chr->logfd < 0) {
error_setg_errno(errp, errno,
"Unable to open logfile %s",
common->logfile);
return;
}
}
if (cc->open) {
cc->open(chr, backend, be_opened, errp);
}
}
开发者ID:mdroth,项目名称:qemu,代码行数:28,代码来源:char.c
示例2: write_pidfile
static void write_pidfile(void)
{
int pidfd;
char pidstr[32];
pidfd = qemu_open(pidfile, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);
if (pidfd == -1) {
error_report("Cannot open pid file, %s", strerror(errno));
exit(EXIT_FAILURE);
}
if (lockf(pidfd, F_TLOCK, 0)) {
error_report("Cannot lock pid file, %s", strerror(errno));
goto fail;
}
if (ftruncate(pidfd, 0)) {
error_report("Failed to truncate pid file");
goto fail;
}
snprintf(pidstr, sizeof(pidstr), "%d\n", getpid());
if (write(pidfd, pidstr, strlen(pidstr)) != strlen(pidstr)) {
error_report("Failed to write pid file");
goto fail;
}
return;
fail:
unlink(pidfile);
close(pidfd);
exit(EXIT_FAILURE);
}
开发者ID:Dovgalyuk,项目名称:qemu,代码行数:32,代码来源:qemu-pr-helper.c
示例3: raw_create
static int raw_create(const char *filename, QEMUOptionParameter *options)
{
int fd;
int result = 0;
int64_t total_size = 0;
/* Read out options */
while (options && options->name) {
if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
total_size = options->value.n / BDRV_SECTOR_SIZE;
}
options++;
}
fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
if (fd < 0) {
result = -errno;
} else {
if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
result = -errno;
}
if (qemu_close(fd) != 0) {
result = -errno;
}
}
return result;
}
开发者ID:01org,项目名称:KVMGT-qemu,代码行数:28,代码来源:raw-posix.c
示例4: floppy_probe_device
static int floppy_probe_device(const char *filename)
{
int fd, ret;
int prio = 0;
struct floppy_struct fdparam;
struct stat st;
if (strstart(filename, "/dev/fd", NULL) &&
!strstart(filename, "/dev/fdset/", NULL)) {
prio = 50;
}
fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
goto out;
}
ret = fstat(fd, &st);
if (ret == -1 || !S_ISBLK(st.st_mode)) {
goto outc;
}
/* Attempt to detect via a floppy specific ioctl */
ret = ioctl(fd, FDGETPRM, &fdparam);
if (ret >= 0)
prio = 100;
outc:
qemu_close(fd);
out:
return prio;
}
开发者ID:01org,项目名称:KVMGT-qemu,代码行数:31,代码来源:raw-posix.c
示例5: rtc_start_timer
static int rtc_start_timer(struct qemu_alarm_timer *t)
{
int rtc_fd;
unsigned long current_rtc_freq = 0;
TFR(rtc_fd = qemu_open("/dev/rtc", O_RDONLY));
if (rtc_fd < 0)
return -1;
ioctl(rtc_fd, RTC_IRQP_READ, ¤t_rtc_freq);
if (current_rtc_freq != RTC_FREQ &&
ioctl(rtc_fd, RTC_IRQP_SET, RTC_FREQ) < 0) {
fprintf(stderr, "Could not configure '/dev/rtc' to have a 1024 Hz timer. This is not a fatal\n"
"error, but for better emulation accuracy either use a 2.6 host Linux kernel or\n"
"type 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' as root.\n");
goto fail;
}
if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
fail:
close(rtc_fd);
return -1;
}
enable_sigio_timer(rtc_fd);
t->priv = (void *)(long)rtc_fd;
return 0;
}
开发者ID:stefanneumann,项目名称:marss,代码行数:28,代码来源:qemu-timer.c
示例6: ga_open_pidfile
static bool ga_open_pidfile(const char *pidfile)
{
int pidfd;
char pidstr[32];
pidfd = qemu_open(pidfile, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);
if (pidfd == -1 || lockf(pidfd, F_TLOCK, 0)) {
g_critical("Cannot lock pid file, %s", strerror(errno));
if (pidfd != -1) {
close(pidfd);
}
return false;
}
if (ftruncate(pidfd, 0)) {
g_critical("Failed to truncate pid file");
goto fail;
}
snprintf(pidstr, sizeof(pidstr), "%d\n", getpid());
if (write(pidfd, pidstr, strlen(pidstr)) != strlen(pidstr)) {
g_critical("Failed to write pid file");
goto fail;
}
/* keep pidfile open & locked forever */
return true;
fail:
unlink(pidfile);
close(pidfd);
return false;
}
开发者ID:JunaidLoonat,项目名称:qemu,代码行数:32,代码来源:main.c
示例7: qemu_create_pidfile
int qemu_create_pidfile(const char *filename)
{
char buffer[128];
int len;
int fd;
fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
if (fd == -1) {
return -1;
}
#ifndef __ANDROID__
if (lockf(fd, F_TLOCK, 0) == -1) {
close(fd);
return -1;
}
len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
if (write(fd, buffer, len) != len) {
close(fd);
return -1;
}
#endif // __ANDROID__
/* keep pidfile open & locked forever */
return 0;
}
开发者ID:limboemu,项目名称:limbo,代码行数:25,代码来源:os-posix.c
示例8: hdev_create
static int hdev_create(const char *filename, QEMUOptionParameter *options)
{
int fd;
int ret = 0;
struct stat stat_buf;
int64_t total_size = 0;
/* Read out options */
while (options && options->name) {
if (!strcmp(options->name, "size")) {
total_size = options->value.n / BDRV_SECTOR_SIZE;
}
options++;
}
fd = qemu_open(filename, O_WRONLY | O_BINARY);
if (fd < 0)
return -errno;
if (fstat(fd, &stat_buf) < 0)
ret = -errno;
else if (!S_ISBLK(stat_buf.st_mode) && !S_ISCHR(stat_buf.st_mode))
ret = -ENODEV;
else if (lseek(fd, 0, SEEK_END) < total_size * BDRV_SECTOR_SIZE)
ret = -ENOSPC;
qemu_close(fd);
return ret;
}
开发者ID:01org,项目名称:KVMGT-qemu,代码行数:29,代码来源:raw-posix.c
示例9: cdrom_probe_device
static int cdrom_probe_device(const char *filename)
{
int fd, ret;
int prio = 0;
struct stat st;
fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
goto out;
}
ret = fstat(fd, &st);
if (ret == -1 || !S_ISBLK(st.st_mode)) {
goto outc;
}
/* Attempt to detect via a CDROM specific ioctl */
ret = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
if (ret >= 0)
prio = 100;
outc:
qemu_close(fd);
out:
return prio;
}
开发者ID:01org,项目名称:KVMGT-qemu,代码行数:25,代码来源:raw-posix.c
示例10: raw_open_common
static int raw_open_common(BlockDriverState *bs, QDict *options,
int bdrv_flags, int open_flags)
{
BDRVRawState *s = bs->opaque;
QemuOpts *opts;
Error *local_err = NULL;
const char *filename;
int fd, ret;
opts = qemu_opts_create_nofail(&raw_runtime_opts);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (error_is_set(&local_err)) {
qerror_report_err(local_err);
error_free(local_err);
ret = -EINVAL;
goto fail;
}
filename = qemu_opt_get(opts, "filename");
ret = raw_normalize_devicepath(&filename);
if (ret != 0) {
goto fail;
}
s->open_flags = open_flags;
raw_parse_flags(bdrv_flags, &s->open_flags);
s->fd = -1;
fd = qemu_open(filename, s->open_flags, 0644);
if (fd < 0) {
ret = -errno;
if (ret == -EROFS) {
ret = -EACCES;
}
goto fail;
}
s->fd = fd;
#ifdef CONFIG_LINUX_AIO
if (raw_set_aio(&s->aio_ctx, &s->use_aio, bdrv_flags)) {
qemu_close(fd);
ret = -errno;
goto fail;
}
#endif
s->has_discard = 1;
#ifdef CONFIG_XFS
if (platform_test_xfs_fd(s->fd)) {
s->is_xfs = 1;
}
#endif
ret = 0;
fail:
qemu_opts_del(opts);
return ret;
}
开发者ID:01org,项目名称:KVMGT-qemu,代码行数:59,代码来源:raw-posix.c
示例11: qmp_chardev_open_file_source
int qmp_chardev_open_file_source(char *src, int flags, Error **errp)
{
int fd = -1;
TFR(fd = qemu_open(src, flags, 0666));
if (fd == -1) {
error_setg_file_open(errp, errno, src);
}
return fd;
}
开发者ID:mdroth,项目名称:qemu,代码行数:10,代码来源:char-fd.c
示例12: rng_random_opened
static void rng_random_opened(RngBackend *b, Error **errp)
{
RndRandom *s = RNG_RANDOM(b);
if (s->filename == NULL) {
error_set(errp, QERR_INVALID_PARAMETER_VALUE,
"filename", "a valid filename");
} else {
s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK);
if (s->fd == -1) {
error_setg_file_open(errp, errno, s->filename);
}
}
}
开发者ID:Aakriti,项目名称:qemu,代码行数:14,代码来源:rng-random.c
示例13: tpm_passthrough_open_sysfs_cancel
/*
* Unless path or file descriptor set has been provided by user,
* determine the sysfs cancel file following kernel documentation
* in Documentation/ABI/stable/sysfs-class-tpm.
* From /dev/tpm0 create /sys/class/misc/tpm0/device/cancel
*/
static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb)
{
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
int fd = -1;
char *dev;
char path[PATH_MAX];
if (tb->cancel_path) {
fd = qemu_open(tb->cancel_path, O_WRONLY);
if (fd < 0) {
error_report("Could not open TPM cancel path : %s",
strerror(errno));
}
return fd;
}
dev = strrchr(tpm_pt->tpm_dev, '/');
if (dev) {
dev++;
if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/cancel",
dev) < sizeof(path)) {
fd = qemu_open(path, O_WRONLY);
if (fd >= 0) {
tb->cancel_path = g_strdup(path);
} else {
error_report("tpm_passthrough: Could not open TPM cancel "
"path %s : %s", path, strerror(errno));
}
}
} else {
error_report("tpm_passthrough: Bad TPM device path %s",
tpm_pt->tpm_dev);
}
return fd;
}
开发者ID:ChenXuJasper,项目名称:qemu,代码行数:42,代码来源:tpm_passthrough.c
示例14: floppy_eject
static void floppy_eject(BlockDriverState *bs, bool eject_flag)
{
BDRVRawState *s = bs->opaque;
int fd;
if (s->fd >= 0) {
qemu_close(s->fd);
s->fd = -1;
}
fd = qemu_open(bs->filename, s->open_flags | O_NONBLOCK);
if (fd >= 0) {
if (ioctl(fd, FDEJECT, 0) < 0)
perror("FDEJECT");
qemu_close(fd);
}
}
开发者ID:01org,项目名称:KVMGT-qemu,代码行数:16,代码来源:raw-posix.c
示例15: tpm_passthrough_handle_device_opts
static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)
{
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
const char *value;
value = qemu_opt_get(opts, "cancel-path");
if (value) {
tb->cancel_path = g_strdup(value);
}
value = qemu_opt_get(opts, "path");
if (!value) {
value = TPM_PASSTHROUGH_DEFAULT_DEVICE;
}
tpm_pt->tpm_dev = g_strdup(value);
tb->path = g_strdup(tpm_pt->tpm_dev);
tpm_pt->tpm_fd = qemu_open(tpm_pt->tpm_dev, O_RDWR);
if (tpm_pt->tpm_fd < 0) {
error_report("Cannot access TPM device using '%s': %s\n",
tpm_pt->tpm_dev, strerror(errno));
goto err_free_parameters;
}
if (tpm_passthrough_test_tpmdev(tpm_pt->tpm_fd)) {
error_report("'%s' is not a TPM device.\n",
tpm_pt->tpm_dev);
goto err_close_tpmdev;
}
return 0;
err_close_tpmdev:
qemu_close(tpm_pt->tpm_fd);
tpm_pt->tpm_fd = -1;
err_free_parameters:
g_free(tb->path);
tb->path = NULL;
g_free(tpm_pt->tpm_dev);
tpm_pt->tpm_dev = NULL;
return 1;
}
开发者ID:BernardXiong,项目名称:qemu,代码行数:47,代码来源:tpm_passthrough.c
示例16: qemu_create_pidfile
int qemu_create_pidfile(const char *filename)
{
char buffer[128];
int len;
#ifndef _WIN32
int fd;
fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
if (fd == -1)
return -1;
if (lockf(fd, F_TLOCK, 0) == -1)
return -1;
len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
if (write(fd, buffer, len) != len)
return -1;
#else
HANDLE file;
DWORD flags;
OVERLAPPED overlap;
BOOL ret;
/* Open for writing with no sharing. */
file = CreateFile(filename, GENERIC_WRITE, 0, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE)
return -1;
flags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
overlap.hEvent = 0;
/* Lock 1 byte. */
ret = LockFileEx(file, flags, 0, 0, 1, &overlap);
if (ret == 0)
return -1;
/* Write PID to file. */
len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
&overlap, NULL);
if (ret == 0)
return -1;
#endif
return 0;
}
开发者ID:joshsyu,项目名称:PQEMU,代码行数:46,代码来源:osdep.c
示例17: hdev_open
static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVRawState *s = bs->opaque;
#if defined(__APPLE__) && defined(__MACH__)
if (strstart(filename, "/dev/cdrom", NULL)) {
kern_return_t kernResult;
io_iterator_t mediaIterator;
char bsdPath[ MAXPATHLEN ];
int fd;
kernResult = FindEjectableCDMedia( &mediaIterator );
kernResult = GetBSDPath( mediaIterator, bsdPath, sizeof( bsdPath ) );
if ( bsdPath[ 0 ] != '\0' ) {
strcat(bsdPath,"s0");
/* some CDs don't have a partition 0 */
fd = qemu_open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE);
if (fd < 0) {
bsdPath[strlen(bsdPath)-1] = '1';
} else {
qemu_close(fd);
}
filename = bsdPath;
}
if ( mediaIterator )
IOObjectRelease( mediaIterator );
}
#endif
s->type = FTYPE_FILE;
#if defined(__linux__)
{
char resolved_path[ MAXPATHLEN ], *temp;
temp = realpath(filename, resolved_path);
if (temp && strstart(temp, "/dev/sg", NULL)) {
bs->sg = 1;
}
}
#endif
return raw_open_common(bs, filename, flags, 0);
}
开发者ID:Jokymon,项目名称:qemu,代码行数:45,代码来源:raw-posix.c
示例18: fd_open
/* Note: we do not have a reliable method to detect if the floppy is
present. The current method is to try to open the floppy at every
I/O and to keep it opened during a few hundreds of ms. */
static int fd_open(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
int last_media_present;
if (s->type != FTYPE_FD)
return 0;
last_media_present = (s->fd >= 0);
if (s->fd >= 0 &&
(get_clock() - s->fd_open_time) >= FD_OPEN_TIMEOUT) {
qemu_close(s->fd);
s->fd = -1;
#ifdef DEBUG_FLOPPY
printf("Floppy closed\n");
#endif
}
if (s->fd < 0) {
if (s->fd_got_error &&
(get_clock() - s->fd_error_time) < FD_OPEN_TIMEOUT) {
#ifdef DEBUG_FLOPPY
printf("No floppy (open delayed)\n");
#endif
return -EIO;
}
s->fd = qemu_open(bs->filename, s->open_flags & ~O_NONBLOCK);
if (s->fd < 0) {
s->fd_error_time = get_clock();
s->fd_got_error = 1;
if (last_media_present)
s->fd_media_changed = 1;
#ifdef DEBUG_FLOPPY
printf("No floppy\n");
#endif
return -EIO;
}
#ifdef DEBUG_FLOPPY
printf("Floppy opened\n");
#endif
}
if (!last_media_present)
s->fd_media_changed = 1;
s->fd_open_time = get_clock();
s->fd_got_error = 0;
return 0;
}
开发者ID:01org,项目名称:KVMGT-qemu,代码行数:48,代码来源:raw-posix.c
示例19: qemu_create_pidfile
int qemu_create_pidfile(const char *filename)
{
char buffer[128];
int len;
int fd;
fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
if (fd == -1) {
return -1;
}
if (lockf(fd, F_TLOCK, 0) == -1) {
return -1;
}
len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
if (write(fd, buffer, len) != len) {
return -1;
}
return 0;
}
开发者ID:Anastasiia-Lada,项目名称:QEMU-s5l89xx-port,代码行数:20,代码来源:os-posix.c
示例20: hpet_start_timer
static int hpet_start_timer(struct qemu_alarm_timer *t)
{
struct hpet_info info;
int r, fd;
fd = qemu_open("/dev/hpet", O_RDONLY);
if (fd < 0)
return -1;
/* Set frequency */
r = ioctl(fd, HPET_IRQFREQ, RTC_FREQ);
if (r < 0) {
fprintf(stderr, "Could not configure '/dev/hpet' to have a 1024Hz timer. This is not a fatal\n"
"error, but for better emulation accuracy type:\n"
"'echo 1024 > /proc/sys/dev/hpet/max-user-freq' as root.\n");
goto fail;
}
/* Check capabilities */
r = ioctl(fd, HPET_INFO, &info);
if (r < 0)
goto fail;
/* Enable periodic mode */
r = ioctl(fd, HPET_EPI, 0);
if (info.hi_flags && (r < 0))
goto fail;
/* Enable interrupt */
r = ioctl(fd, HPET_IE_ON, 0);
if (r < 0)
goto fail;
enable_sigio_timer(fd);
t->priv = (void *)(long)fd;
return 0;
fail:
close(fd);
return -1;
}
开发者ID:stefanneumann,项目名称:marss,代码行数:41,代码来源:qemu-timer.c
注:本文中的qemu_open函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论