block.c (b3d6ca770dd916bceaa7a421252734f86dc07e38) | block.c (eba25057b9a5e19d10ace2bc7716667a31297169) |
---|---|
1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 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 --- 395 unchanged lines hidden (view full) --- 404 drv = bdrv_find_protocol(filename); 405 if (drv == NULL) { 406 return -ENOENT; 407 } 408 409 return bdrv_create(drv, filename, options); 410} 411 | 1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 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 --- 395 unchanged lines hidden (view full) --- 404 drv = bdrv_find_protocol(filename); 405 if (drv == NULL) { 406 return -ENOENT; 407 } 408 409 return bdrv_create(drv, filename, options); 410} 411 |
412#ifdef _WIN32 413void get_tmp_filename(char *filename, int size) | 412/* 413 * Create a uniquely-named empty temporary file. 414 * Return 0 upon success, otherwise a negative errno value. 415 */ 416int get_tmp_filename(char *filename, int size) |
414{ | 417{ |
418#ifdef _WIN32 |
|
415 char temp_dir[MAX_PATH]; | 419 char temp_dir[MAX_PATH]; |
416 417 GetTempPath(MAX_PATH, temp_dir); 418 GetTempFileName(temp_dir, "qem", 0, filename); 419} | 420 /* GetTempFileName requires that its output buffer (4th param) 421 have length MAX_PATH or greater. */ 422 assert(size >= MAX_PATH); 423 return (GetTempPath(MAX_PATH, temp_dir) 424 && GetTempFileName(temp_dir, "qem", 0, filename) 425 ? 0 : -GetLastError()); |
420#else | 426#else |
421void get_tmp_filename(char *filename, int size) 422{ | |
423 int fd; 424 const char *tmpdir; | 427 int fd; 428 const char *tmpdir; |
425 /* XXX: race condition possible */ | |
426 tmpdir = getenv("TMPDIR"); 427 if (!tmpdir) 428 tmpdir = "/tmp"; | 429 tmpdir = getenv("TMPDIR"); 430 if (!tmpdir) 431 tmpdir = "/tmp"; |
429 snprintf(filename, size, "%s/vl.XXXXXX", tmpdir); | 432 if (snprintf(filename, size, "%s/vl.XXXXXX", tmpdir) >= size) { 433 return -EOVERFLOW; 434 } |
430 fd = mkstemp(filename); | 435 fd = mkstemp(filename); |
431 close(fd); 432} | 436 if (fd < 0 || close(fd)) { 437 return -errno; 438 } 439 return 0; |
433#endif | 440#endif |
441} |
|
434 435/* 436 * Detect host devices. By convention, /dev/cdrom[N] is always 437 * recognized as a host CDROM. 438 */ 439static BlockDriver *find_hdev_driver(const char *filename) 440{ 441 int score_max = 0, score; --- 306 unchanged lines hidden (view full) --- 748 } 749 total_size = bdrv_getlength(bs1) & BDRV_SECTOR_MASK; 750 751 if (bs1->drv && bs1->drv->protocol_name) 752 is_protocol = 1; 753 754 bdrv_delete(bs1); 755 | 442 443/* 444 * Detect host devices. By convention, /dev/cdrom[N] is always 445 * recognized as a host CDROM. 446 */ 447static BlockDriver *find_hdev_driver(const char *filename) 448{ 449 int score_max = 0, score; --- 306 unchanged lines hidden (view full) --- 756 } 757 total_size = bdrv_getlength(bs1) & BDRV_SECTOR_MASK; 758 759 if (bs1->drv && bs1->drv->protocol_name) 760 is_protocol = 1; 761 762 bdrv_delete(bs1); 763 |
756 get_tmp_filename(tmp_filename, sizeof(tmp_filename)); | 764 ret = get_tmp_filename(tmp_filename, sizeof(tmp_filename)); 765 if (ret < 0) { 766 return ret; 767 } |
757 758 /* Real path is meaningless for protocols */ 759 if (is_protocol) 760 snprintf(backing_filename, sizeof(backing_filename), 761 "%s", filename); 762 else if (!realpath(filename, backing_filename)) 763 return -errno; 764 --- 3535 unchanged lines hidden --- | 768 769 /* Real path is meaningless for protocols */ 770 if (is_protocol) 771 snprintf(backing_filename, sizeof(backing_filename), 772 "%s", filename); 773 else if (!realpath(filename, backing_filename)) 774 return -errno; 775 --- 3535 unchanged lines hidden --- |