Revision 5bbdbb46 block.c

b/block.c
1319 1319
    *psecs = bs->secs;
1320 1320
}
1321 1321

  
1322
/* Recognize floppy formats */
1323
typedef struct FDFormat {
1324
    FDriveType drive;
1325
    uint8_t last_sect;
1326
    uint8_t max_track;
1327
    uint8_t max_head;
1328
} FDFormat;
1329

  
1330
static const FDFormat fd_formats[] = {
1331
    /* First entry is default format */
1332
    /* 1.44 MB 3"1/2 floppy disks */
1333
    { FDRIVE_DRV_144, 18, 80, 1, },
1334
    { FDRIVE_DRV_144, 20, 80, 1, },
1335
    { FDRIVE_DRV_144, 21, 80, 1, },
1336
    { FDRIVE_DRV_144, 21, 82, 1, },
1337
    { FDRIVE_DRV_144, 21, 83, 1, },
1338
    { FDRIVE_DRV_144, 22, 80, 1, },
1339
    { FDRIVE_DRV_144, 23, 80, 1, },
1340
    { FDRIVE_DRV_144, 24, 80, 1, },
1341
    /* 2.88 MB 3"1/2 floppy disks */
1342
    { FDRIVE_DRV_288, 36, 80, 1, },
1343
    { FDRIVE_DRV_288, 39, 80, 1, },
1344
    { FDRIVE_DRV_288, 40, 80, 1, },
1345
    { FDRIVE_DRV_288, 44, 80, 1, },
1346
    { FDRIVE_DRV_288, 48, 80, 1, },
1347
    /* 720 kB 3"1/2 floppy disks */
1348
    { FDRIVE_DRV_144,  9, 80, 1, },
1349
    { FDRIVE_DRV_144, 10, 80, 1, },
1350
    { FDRIVE_DRV_144, 10, 82, 1, },
1351
    { FDRIVE_DRV_144, 10, 83, 1, },
1352
    { FDRIVE_DRV_144, 13, 80, 1, },
1353
    { FDRIVE_DRV_144, 14, 80, 1, },
1354
    /* 1.2 MB 5"1/4 floppy disks */
1355
    { FDRIVE_DRV_120, 15, 80, 1, },
1356
    { FDRIVE_DRV_120, 18, 80, 1, },
1357
    { FDRIVE_DRV_120, 18, 82, 1, },
1358
    { FDRIVE_DRV_120, 18, 83, 1, },
1359
    { FDRIVE_DRV_120, 20, 80, 1, },
1360
    /* 720 kB 5"1/4 floppy disks */
1361
    { FDRIVE_DRV_120,  9, 80, 1, },
1362
    { FDRIVE_DRV_120, 11, 80, 1, },
1363
    /* 360 kB 5"1/4 floppy disks */
1364
    { FDRIVE_DRV_120,  9, 40, 1, },
1365
    { FDRIVE_DRV_120,  9, 40, 0, },
1366
    { FDRIVE_DRV_120, 10, 41, 1, },
1367
    { FDRIVE_DRV_120, 10, 42, 1, },
1368
    /* 320 kB 5"1/4 floppy disks */
1369
    { FDRIVE_DRV_120,  8, 40, 1, },
1370
    { FDRIVE_DRV_120,  8, 40, 0, },
1371
    /* 360 kB must match 5"1/4 better than 3"1/2... */
1372
    { FDRIVE_DRV_144,  9, 80, 0, },
1373
    /* end */
1374
    { FDRIVE_DRV_NONE, -1, -1, 0, },
1375
};
1376

  
1377
void bdrv_get_floppy_geometry_hint(BlockDriverState *bs, int *nb_heads,
1378
                                   int *max_track, int *last_sect,
1379
                                   FDriveType drive_in, FDriveType *drive)
1380
{
1381
    const FDFormat *parse;
1382
    uint64_t nb_sectors, size;
1383
    int i, first_match, match;
1384

  
1385
    bdrv_get_geometry_hint(bs, nb_heads, max_track, last_sect);
1386
    if (*nb_heads != 0 && *max_track != 0 && *last_sect != 0) {
1387
        /* User defined disk */
1388
    } else {
1389
        bdrv_get_geometry(bs, &nb_sectors);
1390
        match = -1;
1391
        first_match = -1;
1392
        for (i = 0; ; i++) {
1393
            parse = &fd_formats[i];
1394
            if (parse->drive == FDRIVE_DRV_NONE) {
1395
                break;
1396
            }
1397
            if (drive_in == parse->drive ||
1398
                drive_in == FDRIVE_DRV_NONE) {
1399
                size = (parse->max_head + 1) * parse->max_track *
1400
                    parse->last_sect;
1401
                if (nb_sectors == size) {
1402
                    match = i;
1403
                    break;
1404
                }
1405
                if (first_match == -1) {
1406
                    first_match = i;
1407
                }
1408
            }
1409
        }
1410
        if (match == -1) {
1411
            if (first_match == -1) {
1412
                match = 1;
1413
            } else {
1414
                match = first_match;
1415
            }
1416
            parse = &fd_formats[match];
1417
        }
1418
        *nb_heads = parse->max_head + 1;
1419
        *max_track = parse->max_track;
1420
        *last_sect = parse->last_sect;
1421
        *drive = parse->drive;
1422
    }
1423
}
1424

  
1322 1425
int bdrv_get_type_hint(BlockDriverState *bs)
1323 1426
{
1324 1427
    return bs->type;

Also available in: Unified diff