block.c (9f4793d8f2f1abf20dc1d7d55f65ce8df081ca7a) | block.c (2d9158ce79f8d9ca45c74bc496b483e95b4a398c) |
---|---|
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 --- 187 unchanged lines hidden (view full) --- 196 197 result = g_malloc(len + strlen(filename) + 1); 198 memcpy(result, base_path, len); 199 strcpy(result + len, filename); 200 201 return result; 202} 203 | 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 --- 187 unchanged lines hidden (view full) --- 196 197 result = g_malloc(len + strlen(filename) + 1); 198 memcpy(result, base_path, len); 199 strcpy(result + len, filename); 200 201 return result; 202} 203 |
204static void path_combine_deprecated(char *dest, int dest_size, 205 const char *base_path, 206 const char *filename) 207{ 208 char *combined = path_combine(base_path, filename); 209 pstrcpy(dest, dest_size, combined); 210 g_free(combined); 211} 212 | |
213/* 214 * Helper function for bdrv_parse_filename() implementations to remove optional 215 * protocol prefixes (especially "file:") from a filename and for putting the 216 * stripped filename into the options QDict if there is such a prefix. 217 */ 218void bdrv_parse_filename_strip_prefix(const char *filename, const char *prefix, 219 QDict *options) 220{ --- 4428 unchanged lines hidden (view full) --- 4649 BlockDriverState *retval = NULL; 4650 4651 if (!bs || !bs->drv || !backing_file) { 4652 return NULL; 4653 } 4654 4655 filename_full = g_malloc(PATH_MAX); 4656 backing_file_full = g_malloc(PATH_MAX); | 204/* 205 * Helper function for bdrv_parse_filename() implementations to remove optional 206 * protocol prefixes (especially "file:") from a filename and for putting the 207 * stripped filename into the options QDict if there is such a prefix. 208 */ 209void bdrv_parse_filename_strip_prefix(const char *filename, const char *prefix, 210 QDict *options) 211{ --- 4428 unchanged lines hidden (view full) --- 4640 BlockDriverState *retval = NULL; 4641 4642 if (!bs || !bs->drv || !backing_file) { 4643 return NULL; 4644 } 4645 4646 filename_full = g_malloc(PATH_MAX); 4647 backing_file_full = g_malloc(PATH_MAX); |
4657 filename_tmp = g_malloc(PATH_MAX); | |
4658 4659 is_protocol = path_has_protocol(backing_file); 4660 | 4648 4649 is_protocol = path_has_protocol(backing_file); 4650 |
4661 /* This will recursively refresh everything in the backing chain */ 4662 bdrv_refresh_filename(bs); 4663 | |
4664 for (curr_bs = bs; curr_bs->backing; curr_bs = curr_bs->backing->bs) { 4665 4666 /* If either of the filename paths is actually a protocol, then 4667 * compare unmodified paths; otherwise make paths relative */ 4668 if (is_protocol || path_has_protocol(curr_bs->backing_file)) { 4669 char *backing_file_full_ret; 4670 4671 if (strcmp(backing_file, curr_bs->backing_file) == 0) { --- 9 unchanged lines hidden (view full) --- 4681 if (equal) { 4682 retval = curr_bs->backing->bs; 4683 break; 4684 } 4685 } 4686 } else { 4687 /* If not an absolute filename path, make it relative to the current 4688 * image's filename path */ | 4651 for (curr_bs = bs; curr_bs->backing; curr_bs = curr_bs->backing->bs) { 4652 4653 /* If either of the filename paths is actually a protocol, then 4654 * compare unmodified paths; otherwise make paths relative */ 4655 if (is_protocol || path_has_protocol(curr_bs->backing_file)) { 4656 char *backing_file_full_ret; 4657 4658 if (strcmp(backing_file, curr_bs->backing_file) == 0) { --- 9 unchanged lines hidden (view full) --- 4668 if (equal) { 4669 retval = curr_bs->backing->bs; 4670 break; 4671 } 4672 } 4673 } else { 4674 /* If not an absolute filename path, make it relative to the current 4675 * image's filename path */ |
4689 path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filename, 4690 backing_file); 4691 4692 /* We are going to compare absolute pathnames */ 4693 if (!realpath(filename_tmp, filename_full)) { | 4676 filename_tmp = bdrv_make_absolute_filename(curr_bs, backing_file, 4677 NULL); 4678 /* We are going to compare canonicalized absolute pathnames */ 4679 if (!filename_tmp || !realpath(filename_tmp, filename_full)) { 4680 g_free(filename_tmp); |
4694 continue; 4695 } | 4681 continue; 4682 } |
4683 g_free(filename_tmp); |
|
4696 4697 /* We need to make sure the backing filename we are comparing against 4698 * is relative to the current image filename (or absolute) */ | 4684 4685 /* We need to make sure the backing filename we are comparing against 4686 * is relative to the current image filename (or absolute) */ |
4699 path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filename, 4700 curr_bs->backing_file); 4701 4702 if (!realpath(filename_tmp, backing_file_full)) { | 4687 filename_tmp = bdrv_get_full_backing_filename(curr_bs, NULL); 4688 if (!filename_tmp || !realpath(filename_tmp, backing_file_full)) { 4689 g_free(filename_tmp); |
4703 continue; 4704 } | 4690 continue; 4691 } |
4692 g_free(filename_tmp); |
|
4705 4706 if (strcmp(backing_file_full, filename_full) == 0) { 4707 retval = curr_bs->backing->bs; 4708 break; 4709 } 4710 } 4711 } 4712 4713 g_free(filename_full); 4714 g_free(backing_file_full); | 4693 4694 if (strcmp(backing_file_full, filename_full) == 0) { 4695 retval = curr_bs->backing->bs; 4696 break; 4697 } 4698 } 4699 } 4700 4701 g_free(filename_full); 4702 g_free(backing_file_full); |
4715 g_free(filename_tmp); | |
4716 return retval; 4717} 4718 4719void bdrv_init(void) 4720{ 4721 module_call_init(MODULE_INIT_BLOCK); 4722} 4723 --- 1077 unchanged lines hidden --- | 4703 return retval; 4704} 4705 4706void bdrv_init(void) 4707{ 4708 module_call_init(MODULE_INIT_BLOCK); 4709} 4710 --- 1077 unchanged lines hidden --- |