static int hdev_open(BlockDriverState *bs, QDict *options, int flags,

                     Error **errp)

{

    BDRVRawState *s = bs->opaque;

    Error *local_err = NULL;

    int ret;



#if defined(__APPLE__) && defined(__MACH__)

    const char *filename = qdict_get_str(options, "filename");



    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),

                                flags);

        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;

            qdict_put(options, "filename", qstring_from_str(filename));

        }



        if ( mediaIterator )

            IOObjectRelease( mediaIterator );

    }

#endif



    s->type = FTYPE_FILE;



    ret = raw_open_common(bs, options, flags, 0, &local_err);

    if (ret < 0) {

        if (local_err) {

            error_propagate(errp, local_err);

        }

        return ret;

    }



    /* Since this does ioctl the device must be already opened */

    bs->sg = hdev_is_sg(bs);



    if (flags & BDRV_O_RDWR) {

        ret = check_hdev_writable(s);

        if (ret < 0) {

            raw_close(bs);

            error_setg_errno(errp, -ret, "The device is not writable");

            return ret;

        }

    }



    return ret;

}

static int hdev_open(BlockDriverState *bs, QDict *options, int flags,

                     Error **errp)

{

    BDRVRawState *s = bs->opaque;

    Error *local_err = NULL;

    int ret;



#if defined(__APPLE__) && defined(__MACH__)

    const char *filename = qdict_get_str(options, "filename");



    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),

                                flags);

        if ( bsdPath[ 0 ] != '\0' ) {

            strcat(bsdPath,"s0");

            

            fd = qemu_open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE);

            if (fd < 0) {

                bsdPath[strlen(bsdPath)-1] = '1';

            } else {

                qemu_close(fd);

            }

            filename = bsdPath;

            qdict_put(options, "filename", qstring_from_str(filename));

        }



        if ( mediaIterator )

            IOObjectRelease( mediaIterator );

    }

#endif



    s->type = FTYPE_FILE;



    ret = raw_open_common(bs, options, flags, 0, &local_err);

    if (ret < 0) {

        if (local_err) {

            error_propagate(errp, local_err);

        }

        return ret;

    }



    

    bs->sg = hdev_is_sg(bs);



    if (flags & BDRV_O_RDWR) {

        ret = check_hdev_writable(s);

        if (ret < 0) {

            raw_close(bs);

            error_setg_errno(errp, -ret, "The device is not writable");

            return ret;

        }

    }



    return ret;

}

static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,

                     Error **VAR_3)

{

    BDRVRawState *s = VAR_0->opaque;

    Error *local_err = NULL;

    int VAR_4;



#if defined(__APPLE__) && defined(__MACH__)

    const char *VAR_5 = qdict_get_str(VAR_1, "VAR_5");



    if (strstart(VAR_5, "/dev/cdrom", NULL)) {

        kern_return_t kernResult;

        io_iterator_t mediaIterator;

        char VAR_6[ MAXPATHLEN ];

        int VAR_7;



        kernResult = FindEjectableCDMedia( &mediaIterator );

        kernResult = GetBSDPath(mediaIterator, VAR_6, sizeof(VAR_6),

                                VAR_2);

        if ( VAR_6[ 0 ] != '\0' ) {

            strcat(VAR_6,"s0");

            

            VAR_7 = qemu_open(VAR_6, O_RDONLY | O_BINARY | O_LARGEFILE);

            if (VAR_7 < 0) {

                VAR_6[strlen(VAR_6)-1] = '1';

            } else {

                qemu_close(VAR_7);

            }

            VAR_5 = VAR_6;

            qdict_put(VAR_1, "VAR_5", qstring_from_str(VAR_5));

        }



        if ( mediaIterator )

            IOObjectRelease( mediaIterator );

    }

#endif



    s->type = FTYPE_FILE;



    VAR_4 = raw_open_common(VAR_0, VAR_1, VAR_2, 0, &local_err);

    if (VAR_4 < 0) {

        if (local_err) {

            error_propagate(VAR_3, local_err);

        }

        return VAR_4;

    }



    

    VAR_0->sg = hdev_is_sg(VAR_0);



    if (VAR_2 & BDRV_O_RDWR) {

        VAR_4 = check_hdev_writable(s);

        if (VAR_4 < 0) {

            raw_close(VAR_0);

            error_setg_errno(VAR_3, -VAR_4, "The device is not writable");

            return VAR_4;

        }

    }



    return VAR_4;

}

static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,
Error **VAR_3)
{ BDRVRawState *s = VAR_0->opaque; Error *local_err = NULL; int VAR_4; #if defined(__APPLE__) && defined(__MACH__)
const char *VAR_5 = qdict_get_str(VAR_1, "VAR_5"); if (strstart(VAR_5, "/dev/cdrom", NULL)) { kern_return_t kernResult; io_iterator_t mediaIterator; char VAR_6[ MAXPATHLEN ]; int VAR_7; kernResult = FindEjectableCDMedia( &mediaIterator ); kernResult = GetBSDPath(mediaIterator, VAR_6, sizeof(VAR_6),
VAR_2); if ( VAR_6[ 0 ] != '\0' ) { strcat(VAR_6,"s0"); VAR_7 = qemu_open(VAR_6, O_RDONLY | O_BINARY | O_LARGEFILE); if (VAR_7 < 0) { VAR_6[strlen(VAR_6)-1] = '1'; } else { qemu_close(VAR_7); } VAR_5 = VAR_6; qdict_put(VAR_1, "VAR_5", qstring_from_str(VAR_5)); } if ( mediaIterator )
IOObjectRelease( mediaIterator ); } #endif
s->type = FTYPE_FILE; VAR_4 = raw_open_common(VAR_0, VAR_1, VAR_2, 0, &local_err); if (VAR_4 < 0) { if (local_err) { error_propagate(VAR_3, local_err); } return VAR_4; } VAR_0->sg = hdev_is_sg(VAR_0); if (VAR_2 & BDRV_O_RDWR) { VAR_4 = check_hdev_writable(s); if (VAR_4 < 0) { raw_close(VAR_0); error_setg_errno(VAR_3, -VAR_4, "The device is not writable"); return VAR_4; } } return VAR_4; }