[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make
From: |
Programmingkid |
Subject: |
Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host |
Date: |
Tue, 2 Feb 2016 20:15:01 -0500 |
On Feb 2, 2016, at 5:04 PM, Eric Blake wrote:
> On 02/02/2016 02:23 PM, Programmingkid wrote:
>
>>> And why isn't bsd_path usable for that purpose?
>>
>> After trying it out, I found out why bsd_path isn't usable for that purpose.
>> It is because the user might try to use a flash drive as the the cdrom. Say
>> a flash drive is set to /dev/disk2s9. If the user issues the monitor command
>> "change ide1-cd0 /dev/disk2s9", this will make "if (strcmp(filename,
>> "/dev/cdrom") == 0)" false and bsd_path would never be set. bsd_path
>> contents would be garbage.
>>
>> This would lead to this code not printing the unmounting directions:
>>
>> if (strncmp(filename, "/dev/", 5) == 0) {
>> print_unmounting_directions(filename);
>> return -1;
>> }
>>
>> It looks keeping filename as an character array is best.
>
> No, keep filename as a const char * pointer. It's easy to avoid use of
> uninitialized memory. Try this:
>
> const char *filename;
> char bsd_path[MAXPATHLEN] = "";
> ...
> if (strncmp("/dev/cdrom"...) {
> bsd_path = ...
> }
> ...
> if (strncmp("/dev/"...) {
> print_unmounting_directions(*bsd_path ? bsd_path : filename);
At first I thought this code looked unusual, but it does work. Is this ok?
#if defined(__APPLE__) && defined(__MACH__)
/* if a physical device experienced an error while being opened */
if (strncmp((*bsd_path ? bsd_path : filename), "/dev/", 5) == 0) {
print_unmounting_directions(*bsd_path ? bsd_path : filename);
return -1;
}
#endif /* defined(__APPLE__) && defined(__MACH__) */
- [Qemu-block] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Programmingkid, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Daniel P. Berrange, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Programmingkid, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Daniel P. Berrange, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Programmingkid, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Eric Blake, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Programmingkid, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Programmingkid, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Eric Blake, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host,
Programmingkid <=
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Eric Blake, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Programmingkid, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Eric Blake, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Programmingkid, 2016/02/03
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Eric Blake, 2016/02/04
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Eric Blake, 2016/02/02
- Re: [Qemu-block] [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host, Kevin Wolf, 2016/02/03