Revision 5fafdf24 block-raw.c

b/block-raw.c
1 1
/*
2 2
 * Block driver for RAW files
3
 * 
3
 *
4 4
 * Copyright (c) 2006 Fabrice Bellard
5
 * 
5
 *
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
8 8
 * in the Software without restriction, including without limitation the rights
......
137 137
#endif
138 138
*/
139 139

  
140
static int raw_pread(BlockDriverState *bs, int64_t offset, 
140
static int raw_pread(BlockDriverState *bs, int64_t offset,
141 141
                     uint8_t *buf, int count)
142 142
{
143 143
    BDRVRawState *s = bs->opaque;
144 144
    int ret;
145
    
145
   
146 146
    ret = fd_open(bs);
147 147
    if (ret < 0)
148 148
        return ret;
......
189 189
    return ret;
190 190
}
191 191

  
192
static int raw_pwrite(BlockDriverState *bs, int64_t offset, 
192
static int raw_pwrite(BlockDriverState *bs, int64_t offset,
193 193
                      const uint8_t *buf, int count)
194 194
{
195 195
    BDRVRawState *s = bs->opaque;
196 196
    int ret;
197
    
197
   
198 198
    ret = fd_open(bs);
199 199
    if (ret < 0)
200 200
        return ret;
......
259 259
    struct sigaction act;
260 260

  
261 261
    aio_initialized = 1;
262
    
262
   
263 263
    sigfillset(&act.sa_mask);
264 264
    act.sa_flags = 0; /* do not restart syscalls to interrupt select() */
265 265
    act.sa_handler = aio_signal_handler;
......
401 401
    if (aio_read(&acb->aiocb) < 0) {
402 402
        qemu_aio_release(acb);
403 403
        return NULL;
404
    } 
404
    }
405 405
    return &acb->common;
406 406
}
407 407

  
......
417 417
    if (aio_write(&acb->aiocb) < 0) {
418 418
        qemu_aio_release(acb);
419 419
        return NULL;
420
    } 
420
    }
421 421
    return &acb->common;
422 422
}
423 423

  
......
522 522
    if (flags || backing_file)
523 523
        return -ENOTSUP;
524 524

  
525
    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 
525
    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
526 526
              0644);
527 527
    if (fd < 0)
528 528
        return -EIO;
......
547 547
    raw_close,
548 548
    raw_create,
549 549
    raw_flush,
550
    
550
   
551 551
    .bdrv_aio_read = raw_aio_read,
552 552
    .bdrv_aio_write = raw_aio_write,
553 553
    .bdrv_aio_cancel = raw_aio_cancel,
......
568 568

  
569 569
kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator )
570 570
{
571
    kern_return_t       kernResult; 
571
    kern_return_t       kernResult;
572 572
    mach_port_t     masterPort;
573 573
    CFMutableDictionaryRef  classesToMatch;
574 574

  
......
576 576
    if ( KERN_SUCCESS != kernResult ) {
577 577
        printf( "IOMasterPort returned %d\n", kernResult );
578 578
    }
579
    
580
    classesToMatch = IOServiceMatching( kIOCDMediaClass ); 
579
   
580
    classesToMatch = IOServiceMatching( kIOCDMediaClass );
581 581
    if ( classesToMatch == NULL ) {
582 582
        printf( "IOServiceMatching returned a NULL dictionary.\n" );
583 583
    } else {
......
588 588
    {
589 589
        printf( "IOServiceGetMatchingServices returned %d\n", kernResult );
590 590
    }
591
    
591
   
592 592
    return kernResult;
593 593
}
594 594

  
......
614 614
        }
615 615
        IOObjectRelease( nextMedia );
616 616
    }
617
    
617
   
618 618
    return kernResult;
619 619
}
620 620

  
......
631 631
        io_iterator_t mediaIterator;
632 632
        char bsdPath[ MAXPATHLEN ];
633 633
        int fd;
634
 
634

  
635 635
        kernResult = FindEjectableCDMedia( &mediaIterator );
636 636
        kernResult = GetBSDPath( mediaIterator, bsdPath, sizeof( bsdPath ) );
637
    
637
   
638 638
        if ( bsdPath[ 0 ] != '\0' ) {
639 639
            strcat(bsdPath,"s0");
640 640
            /* some CDs don't have a partition 0 */
......
646 646
            }
647 647
            filename = bsdPath;
648 648
        }
649
        
649
       
650 650
        if ( mediaIterator )
651 651
            IOObjectRelease( mediaIterator );
652 652
    }
......
704 704
    if (s->type != FTYPE_FD)
705 705
        return 0;
706 706
    last_media_present = (s->fd >= 0);
707
    if (s->fd >= 0 && 
707
    if (s->fd >= 0 &&
708 708
        (qemu_get_clock(rt_clock) - s->fd_open_time) >= FD_OPEN_TIMEOUT) {
709 709
        close(s->fd);
710 710
        s->fd = -1;
......
713 713
#endif
714 714
    }
715 715
    if (s->fd < 0) {
716
        if (s->fd_got_error && 
716
        if (s->fd_got_error &&
717 717
            (qemu_get_clock(rt_clock) - s->fd_error_time) < FD_OPEN_TIMEOUT) {
718 718
#ifdef DEBUG_FLOPPY
719 719
            printf("No floppy (open delayed)\n");
......
883 883
    raw_close,
884 884
    NULL,
885 885
    raw_flush,
886
    
886
   
887 887
    .bdrv_aio_read = raw_aio_read,
888 888
    .bdrv_aio_write = raw_aio_write,
889 889
    .bdrv_aio_cancel = raw_aio_cancel,
......
979 979
#else
980 980
    overlapped = FILE_FLAG_OVERLAPPED;
981 981
#endif
982
    s->hfile = CreateFile(filename, access_flags, 
982
    s->hfile = CreateFile(filename, access_flags,
983 983
                          FILE_SHARE_READ, NULL,
984 984
                          create_flags, overlapped, NULL);
985 985
    if (s->hfile == INVALID_HANDLE_VALUE) {
......
992 992
    return 0;
993 993
}
994 994

  
995
static int raw_pread(BlockDriverState *bs, int64_t offset, 
995
static int raw_pread(BlockDriverState *bs, int64_t offset,
996 996
                     uint8_t *buf, int count)
997 997
{
998 998
    BDRVRawState *s = bs->opaque;
999 999
    OVERLAPPED ov;
1000 1000
    DWORD ret_count;
1001 1001
    int ret;
1002
    
1002
   
1003 1003
    memset(&ov, 0, sizeof(ov));
1004 1004
    ov.Offset = offset;
1005 1005
    ov.OffsetHigh = offset >> 32;
......
1014 1014
    return ret_count;
1015 1015
}
1016 1016

  
1017
static int raw_pwrite(BlockDriverState *bs, int64_t offset, 
1017
static int raw_pwrite(BlockDriverState *bs, int64_t offset,
1018 1018
                      const uint8_t *buf, int count)
1019 1019
{
1020 1020
    BDRVRawState *s = bs->opaque;
1021 1021
    OVERLAPPED ov;
1022 1022
    DWORD ret_count;
1023 1023
    int ret;
1024
    
1024
   
1025 1025
    memset(&ov, 0, sizeof(ov));
1026 1026
    ov.Offset = offset;
1027 1027
    ov.OffsetHigh = offset >> 32;
......
1171 1171
{
1172 1172
    BDRVRawState *s = bs->opaque;
1173 1173
    LARGE_INTEGER l;
1174
    ULARGE_INTEGER available, total, total_free; 
1174
    ULARGE_INTEGER available, total, total_free;
1175 1175
    DISK_GEOMETRY dg;
1176 1176
    DWORD count;
1177 1177
    BOOL status;
......
1209 1209
    if (flags || backing_file)
1210 1210
        return -ENOTSUP;
1211 1211

  
1212
    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 
1212
    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
1213 1213
              0644);
1214 1214
    if (fd < 0)
1215 1215
        return -EIO;
......
1256 1256
    raw_close,
1257 1257
    raw_create,
1258 1258
    raw_flush,
1259
    
1259
   
1260 1260
#if 0
1261 1261
    .bdrv_aio_read = raw_aio_read,
1262 1262
    .bdrv_aio_write = raw_aio_write,
......
1335 1335
        }
1336 1336
    }
1337 1337
    s->type = find_device_type(bs, filename);
1338
    
1338
   
1339 1339
    if ((flags & BDRV_O_ACCESS) == O_RDWR) {
1340 1340
        access_flags = GENERIC_READ | GENERIC_WRITE;
1341 1341
    } else {
......
1348 1348
#else
1349 1349
    overlapped = FILE_FLAG_OVERLAPPED;
1350 1350
#endif
1351
    s->hfile = CreateFile(filename, access_flags, 
1351
    s->hfile = CreateFile(filename, access_flags,
1352 1352
                          FILE_SHARE_READ, NULL,
1353 1353
                          create_flags, overlapped, NULL);
1354 1354
    if (s->hfile == INVALID_HANDLE_VALUE) {
......
1382 1382
    if (s->type == FTYPE_FILE)
1383 1383
        return -ENOTSUP;
1384 1384
    if (eject_flag) {
1385
        DeviceIoControl(s->hfile, IOCTL_STORAGE_EJECT_MEDIA, 
1385
        DeviceIoControl(s->hfile, IOCTL_STORAGE_EJECT_MEDIA,
1386 1386
                        NULL, 0, NULL, 0, &lpBytesReturned, NULL);
1387 1387
    } else {
1388
        DeviceIoControl(s->hfile, IOCTL_STORAGE_LOAD_MEDIA, 
1388
        DeviceIoControl(s->hfile, IOCTL_STORAGE_LOAD_MEDIA,
1389 1389
                        NULL, 0, NULL, 0, &lpBytesReturned, NULL);
1390 1390
    }
1391 1391
}
......
1406 1406
    raw_close,
1407 1407
    NULL,
1408 1408
    raw_flush,
1409
    
1409
   
1410 1410
#if 0
1411 1411
    .bdrv_aio_read = raw_aio_read,
1412 1412
    .bdrv_aio_write = raw_aio_write,

Also available in: Unified diff