char.c (3b4482a26dd6d722004fcb7ee031064ee50288e3) char.c (6fdafac1c165821054e1d0786bd6630e90f2379f)
1/*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 1673 unchanged lines hidden (view full) ---

1682
1683 backend->has_logfile = logfile != NULL;
1684 backend->logfile = logfile ? g_strdup(logfile) : NULL;
1685
1686 backend->has_logappend = true;
1687 backend->logappend = qemu_opt_get_bool(opts, "logappend", false);
1688}
1689
1/*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 1673 unchanged lines hidden (view full) ---

1682
1683 backend->has_logfile = logfile != NULL;
1684 backend->logfile = logfile ? g_strdup(logfile) : NULL;
1685
1686 backend->has_logappend = true;
1687 backend->logappend = qemu_opt_get_bool(opts, "logappend", false);
1688}
1689
1690
1691static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend,
1692 Error **errp)
1693{
1694 const char *path = qemu_opt_get(opts, "path");
1695 ChardevFile *file;
1696
1697 backend->type = CHARDEV_BACKEND_KIND_FILE;
1698 if (path == NULL) {
1699 error_setg(errp, "chardev: file: no filename given");
1700 return;
1701 }
1702 file = backend->u.file.data = g_new0(ChardevFile, 1);
1703 qemu_chr_parse_common(opts, qapi_ChardevFile_base(file));
1704 file->out = g_strdup(path);
1705
1706 file->has_append = true;
1707 file->append = qemu_opt_get_bool(opts, "append", false);
1708}
1709
1710static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend,
1711 Error **errp)
1712{
1713 ChardevStdio *stdio;
1714
1715 backend->type = CHARDEV_BACKEND_KIND_STDIO;
1716 stdio = backend->u.stdio.data = g_new0(ChardevStdio, 1);
1717 qemu_chr_parse_common(opts, qapi_ChardevStdio_base(stdio));

--- 537 unchanged lines hidden (view full) ---

2255 .type = QEMU_OPT_BOOL,
2256 },
2257 { /* end of list */ }
2258 },
2259};
2260
2261#ifdef _WIN32
2262
1690static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend,
1691 Error **errp)
1692{
1693 ChardevStdio *stdio;
1694
1695 backend->type = CHARDEV_BACKEND_KIND_STDIO;
1696 stdio = backend->u.stdio.data = g_new0(ChardevStdio, 1);
1697 qemu_chr_parse_common(opts, qapi_ChardevStdio_base(stdio));

--- 537 unchanged lines hidden (view full) ---

2235 .type = QEMU_OPT_BOOL,
2236 },
2237 { /* end of list */ }
2238 },
2239};
2240
2241#ifdef _WIN32
2242
2263static void qmp_chardev_open_file(Chardev *chr,
2264 ChardevBackend *backend,
2265 bool *be_opened,
2266 Error **errp)
2267{
2268 ChardevFile *file = backend->u.file.data;
2269 HANDLE out;
2270 DWORD accessmode;
2271 DWORD flags;
2272
2273 if (file->has_in) {
2274 error_setg(errp, "input file not supported");
2275 return;
2276 }
2277
2278 if (file->has_append && file->append) {
2279 /* Append to file if it already exists. */
2280 accessmode = FILE_GENERIC_WRITE & ~FILE_WRITE_DATA;
2281 flags = OPEN_ALWAYS;
2282 } else {
2283 /* Truncate file if it already exists. */
2284 accessmode = GENERIC_WRITE;
2285 flags = CREATE_ALWAYS;
2286 }
2287
2288 out = CreateFile(file->out, accessmode, FILE_SHARE_READ, NULL, flags,
2289 FILE_ATTRIBUTE_NORMAL, NULL);
2290 if (out == INVALID_HANDLE_VALUE) {
2291 error_setg(errp, "open %s failed", file->out);
2292 return;
2293 }
2294
2295 qemu_chr_open_win_file(chr, out);
2296}
2297
2298static void qmp_chardev_open_serial(Chardev *chr,
2299 ChardevBackend *backend,
2300 bool *be_opened,
2301 Error **errp)
2302{
2303 ChardevHostdev *serial = backend->u.serial.data;
2304
2305 win_chr_init(chr, serial->device, errp);
2306}
2307
2308#else /* WIN32 */
2309
2243static void qmp_chardev_open_serial(Chardev *chr,
2244 ChardevBackend *backend,
2245 bool *be_opened,
2246 Error **errp)
2247{
2248 ChardevHostdev *serial = backend->u.serial.data;
2249
2250 win_chr_init(chr, serial->device, errp);
2251}
2252
2253#else /* WIN32 */
2254
2310static void qmp_chardev_open_file(Chardev *chr,
2311 ChardevBackend *backend,
2312 bool *be_opened,
2313 Error **errp)
2314{
2315 ChardevFile *file = backend->u.file.data;
2316 int flags, in = -1, out;
2317
2318 flags = O_WRONLY | O_CREAT | O_BINARY;
2319 if (file->has_append && file->append) {
2320 flags |= O_APPEND;
2321 } else {
2322 flags |= O_TRUNC;
2323 }
2324
2325 out = qmp_chardev_open_file_source(file->out, flags, errp);
2326 if (out < 0) {
2327 return;
2328 }
2329
2330 if (file->has_in) {
2331 flags = O_RDONLY;
2332 in = qmp_chardev_open_file_source(file->in, flags, errp);
2333 if (in < 0) {
2334 qemu_close(out);
2335 return;
2336 }
2337 }
2338
2339 qemu_chr_open_fd(chr, in, out);
2340}
2341
2342#ifdef HAVE_CHARDEV_SERIAL
2343static void qmp_chardev_open_serial(Chardev *chr,
2344 ChardevBackend *backend,
2345 bool *be_opened,
2346 Error **errp)
2347{
2348 ChardevHostdev *serial = backend->u.serial.data;
2349 int fd;

--- 60 unchanged lines hidden (view full) ---

2410 .instance_size = sizeof(ParallelChardev),
2411 .instance_finalize = char_parallel_finalize,
2412 .class_init = char_parallel_class_init,
2413};
2414#endif
2415
2416#endif /* WIN32 */
2417
2255#ifdef HAVE_CHARDEV_SERIAL
2256static void qmp_chardev_open_serial(Chardev *chr,
2257 ChardevBackend *backend,
2258 bool *be_opened,
2259 Error **errp)
2260{
2261 ChardevHostdev *serial = backend->u.serial.data;
2262 int fd;

--- 60 unchanged lines hidden (view full) ---

2323 .instance_size = sizeof(ParallelChardev),
2324 .instance_finalize = char_parallel_finalize,
2325 .class_init = char_parallel_class_init,
2326};
2327#endif
2328
2329#endif /* WIN32 */
2330
2418static void char_file_class_init(ObjectClass *oc, void *data)
2419{
2420 ChardevClass *cc = CHARDEV_CLASS(oc);
2421
2422 cc->parse = qemu_chr_parse_file_out;
2423 cc->open = qmp_chardev_open_file;
2424}
2425
2426static const TypeInfo char_file_type_info = {
2427 .name = TYPE_CHARDEV_FILE,
2428#ifdef _WIN32
2429 .parent = TYPE_CHARDEV_WIN,
2430#else
2431 .parent = TYPE_CHARDEV_FD,
2432#endif
2433 .class_init = char_file_class_init,
2434};
2435
2436#ifdef HAVE_CHARDEV_SERIAL
2437
2438static void char_serial_class_init(ObjectClass *oc, void *data)
2439{
2440 ChardevClass *cc = CHARDEV_CLASS(oc);
2441
2442 cc->parse = qemu_chr_parse_serial;
2443 cc->open = qmp_chardev_open_serial;

--- 109 unchanged lines hidden (view full) ---

2553 QTAILQ_FOREACH_SAFE(chr, &chardevs, next, tmp) {
2554 qemu_chr_delete(chr);
2555 }
2556}
2557
2558static void register_types(void)
2559{
2560 type_register_static(&char_type_info);
2331#ifdef HAVE_CHARDEV_SERIAL
2332
2333static void char_serial_class_init(ObjectClass *oc, void *data)
2334{
2335 ChardevClass *cc = CHARDEV_CLASS(oc);
2336
2337 cc->parse = qemu_chr_parse_serial;
2338 cc->open = qmp_chardev_open_serial;

--- 109 unchanged lines hidden (view full) ---

2448 QTAILQ_FOREACH_SAFE(chr, &chardevs, next, tmp) {
2449 qemu_chr_delete(chr);
2450 }
2451}
2452
2453static void register_types(void)
2454{
2455 type_register_static(&char_type_info);
2561 type_register_static(&char_file_type_info);
2562 type_register_static(&char_stdio_type_info);
2563#ifdef HAVE_CHARDEV_SERIAL
2564 type_register_static(&char_serial_type_info);
2565#endif
2566#ifdef HAVE_CHARDEV_PARPORT
2567 type_register_static(&char_parallel_type_info);
2568#endif
2569#ifdef HAVE_CHARDEV_PTY

--- 15 unchanged lines hidden ---
2456 type_register_static(&char_stdio_type_info);
2457#ifdef HAVE_CHARDEV_SERIAL
2458 type_register_static(&char_serial_type_info);
2459#endif
2460#ifdef HAVE_CHARDEV_PARPORT
2461 type_register_static(&char_parallel_type_info);
2462#endif
2463#ifdef HAVE_CHARDEV_PTY

--- 15 unchanged lines hidden ---