static int hdev_open(BlockDriverState *bs, const char *filename, int flags)

{

    BDRVRawState *s = bs->opaque;

    int access_flags, create_flags;

    DWORD overlapped;

    char device_name[64];



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

        if (find_cdrom(device_name, sizeof(device_name)) < 0)

            return -ENOENT;

        filename = device_name;

    } else {

        /* transform drive letters into device name */

        if (((filename[0] >= 'a' && filename[0] <= 'z') ||

             (filename[0] >= 'A' && filename[0] <= 'Z')) &&

            filename[1] == ':' && filename[2] == '\0') {

            snprintf(device_name, sizeof(device_name), "\\\\.\\%c:", filename[0]);

            filename = device_name;

        }

    }

    s->type = find_device_type(bs, filename);

    

    if ((flags & BDRV_O_ACCESS) == O_RDWR) {

        access_flags = GENERIC_READ | GENERIC_WRITE;

    } else {

        access_flags = GENERIC_READ;

    }

    create_flags = OPEN_EXISTING;



#ifdef QEMU_TOOL

    overlapped = FILE_ATTRIBUTE_NORMAL;

#else

    overlapped = FILE_FLAG_OVERLAPPED;

#endif

    s->hfile = CreateFile(filename, access_flags, 

                          FILE_SHARE_READ, NULL,

                          create_flags, overlapped, NULL);

    if (s->hfile == INVALID_HANDLE_VALUE) 

        return -1;

    return 0;

}

static int hdev_open(BlockDriverState *bs, const char *filename, int flags)

{

    BDRVRawState *s = bs->opaque;

    int access_flags, create_flags;

    DWORD overlapped;

    char device_name[64];



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

        if (find_cdrom(device_name, sizeof(device_name)) < 0)

            return -ENOENT;

        filename = device_name;

    } else {

        

        if (((filename[0] >= 'a' && filename[0] <= 'z') ||

             (filename[0] >= 'A' && filename[0] <= 'Z')) &&

            filename[1] == ':' && filename[2] == '\0') {

            snprintf(device_name, sizeof(device_name), "\\\\.\\%c:", filename[0]);

            filename = device_name;

        }

    }

    s->type = find_device_type(bs, filename);

    

    if ((flags & BDRV_O_ACCESS) == O_RDWR) {

        access_flags = GENERIC_READ | GENERIC_WRITE;

    } else {

        access_flags = GENERIC_READ;

    }

    create_flags = OPEN_EXISTING;



#ifdef QEMU_TOOL

    overlapped = FILE_ATTRIBUTE_NORMAL;

#else

    overlapped = FILE_FLAG_OVERLAPPED;

#endif

    s->hfile = CreateFile(filename, access_flags, 

                          FILE_SHARE_READ, NULL,

                          create_flags, overlapped, NULL);

    if (s->hfile == INVALID_HANDLE_VALUE) 

        return -1;

    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1, int VAR_2)

{

    BDRVRawState *s = VAR_0->opaque;

    int VAR_3, VAR_4;

    DWORD overlapped;

    char VAR_5[64];



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

        if (find_cdrom(VAR_5, sizeof(VAR_5)) < 0)

            return -ENOENT;

        VAR_1 = VAR_5;

    } else {

        

        if (((VAR_1[0] >= 'a' && VAR_1[0] <= 'z') ||

             (VAR_1[0] >= 'A' && VAR_1[0] <= 'Z')) &&

            VAR_1[1] == ':' && VAR_1[2] == '\0') {

            snprintf(VAR_5, sizeof(VAR_5), "\\\\.\\%c:", VAR_1[0]);

            VAR_1 = VAR_5;

        }

    }

    s->type = find_device_type(VAR_0, VAR_1);

    

    if ((VAR_2 & BDRV_O_ACCESS) == O_RDWR) {

        VAR_3 = GENERIC_READ | GENERIC_WRITE;

    } else {

        VAR_3 = GENERIC_READ;

    }

    VAR_4 = OPEN_EXISTING;



#ifdef QEMU_TOOL

    overlapped = FILE_ATTRIBUTE_NORMAL;

#else

    overlapped = FILE_FLAG_OVERLAPPED;

#endif

    s->hfile = CreateFile(VAR_1, VAR_3, 

                          FILE_SHARE_READ, NULL,

                          VAR_4, overlapped, NULL);

    if (s->hfile == INVALID_HANDLE_VALUE) 

        return -1;

    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1, int VAR_2)
{ BDRVRawState *s = VAR_0->opaque; int VAR_3, VAR_4; DWORD overlapped; char VAR_5[64]; if (strstart(VAR_1, "/dev/cdrom", NULL)) { if (find_cdrom(VAR_5, sizeof(VAR_5)) < 0)
return -ENOENT; VAR_1 = VAR_5; } else { if (((VAR_1[0] >= 'a' && VAR_1[0] <= 'z') ||
(VAR_1[0] >= 'A' && VAR_1[0] <= 'Z')) &&
VAR_1[1] == ':' && VAR_1[2] == '\0') { snprintf(VAR_5, sizeof(VAR_5), "\\\\.\\%c:", VAR_1[0]); VAR_1 = VAR_5; } } s->type = find_device_type(VAR_0, VAR_1); if ((VAR_2 & BDRV_O_ACCESS) == O_RDWR) { VAR_3 = GENERIC_READ | GENERIC_WRITE; } else { VAR_3 = GENERIC_READ; } VAR_4 = OPEN_EXISTING; #ifdef QEMU_TOOL
overlapped = FILE_ATTRIBUTE_NORMAL; #else
overlapped = FILE_FLAG_OVERLAPPED; #endif
s->hfile = CreateFile(VAR_1, VAR_3,
FILE_SHARE_READ, NULL,
VAR_4, overlapped, NULL); if (s->hfile == INVALID_HANDLE_VALUE)
return -1; return 0; }