biosdisk.c (67350cb56a69468c118bd4ccf6e361b7ebfa9eb4) biosdisk.c (75772fa26e9d429e92130d1bfc3b39669a768b64)
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 455 unchanged lines hidden (view full) ---

464
465 if (V86_CY(v86.efl) && ((v86.eax & 0xff00) != 0))
466 return ((v86.eax & 0xff00) >> 8);
467
468 /*
469 * Sector size must be a multiple of 512 bytes.
470 * An alternate test would be to check power of 2,
471 * powerof2(params.sector_size).
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 455 unchanged lines hidden (view full) ---

464
465 if (V86_CY(v86.efl) && ((v86.eax & 0xff00) != 0))
466 return ((v86.eax & 0xff00) >> 8);
467
468 /*
469 * Sector size must be a multiple of 512 bytes.
470 * An alternate test would be to check power of 2,
471 * powerof2(params.sector_size).
472 * 4K is largest read buffer we can use at this time.
472 * 16K is largest read buffer we can use at this time.
473 */
474 if (params.sector_size >= 512 &&
473 */
474 if (params.sector_size >= 512 &&
475 params.sector_size <= 4096 &&
475 params.sector_size <= 16384 &&
476 (params.sector_size % BIOSDISK_SECSIZE) == 0)
477 bd->bd_sectorsize = params.sector_size;
478
479 bd->bd_cyl = params.cylinders;
480 bd->bd_hds = params.heads;
481 bd->bd_sec = params.sectors_per_track;
482
483 if (params.sectors != 0) {

--- 372 unchanged lines hidden (view full) ---

856
857static int
858bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size,
859 char *buf, size_t *rsize)
860{
861 struct disk_devdesc *dev = (struct disk_devdesc *)devdata;
862 bdinfo_t *bd;
863 uint64_t disk_blocks, offset, d_offset;
476 (params.sector_size % BIOSDISK_SECSIZE) == 0)
477 bd->bd_sectorsize = params.sector_size;
478
479 bd->bd_cyl = params.cylinders;
480 bd->bd_hds = params.heads;
481 bd->bd_sec = params.sectors_per_track;
482
483 if (params.sectors != 0) {

--- 372 unchanged lines hidden (view full) ---

856
857static int
858bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size,
859 char *buf, size_t *rsize)
860{
861 struct disk_devdesc *dev = (struct disk_devdesc *)devdata;
862 bdinfo_t *bd;
863 uint64_t disk_blocks, offset, d_offset;
864 size_t blks, blkoff, bsize, rest;
865 caddr_t bbuf;
864 size_t blks, blkoff, bsize, bio_size, rest;
865 caddr_t bbuf = NULL;
866 int rc;
867
868 bd = bd_get_bdinfo(&dev->dd);
869 if (bd == NULL || (bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA)
870 return (EIO);
871
872 /*
873 * First make sure the IO size is a multiple of 512 bytes. While we do

--- 58 unchanged lines hidden (view full) ---

932 * Truncate if we are crossing disk or partition end.
933 */
934 if (dblk + blks >= d_offset + disk_blocks) {
935 blks = d_offset + disk_blocks - dblk;
936 size = blks * bd->bd_sectorsize;
937 DEBUG("short I/O %d", blks);
938 }
939
866 int rc;
867
868 bd = bd_get_bdinfo(&dev->dd);
869 if (bd == NULL || (bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA)
870 return (EIO);
871
872 /*
873 * First make sure the IO size is a multiple of 512 bytes. While we do

--- 58 unchanged lines hidden (view full) ---

932 * Truncate if we are crossing disk or partition end.
933 */
934 if (dblk + blks >= d_offset + disk_blocks) {
935 blks = d_offset + disk_blocks - dblk;
936 size = blks * bd->bd_sectorsize;
937 DEBUG("short I/O %d", blks);
938 }
939
940 if (V86_IO_BUFFER_SIZE / bd->bd_sectorsize == 0)
941 panic("BUG: Real mode buffer is too small");
940 bio_size = min(BIO_BUFFER_SIZE, size);
941 while (bio_size > bd->bd_sectorsize) {
942 bbuf = bio_alloc(bio_size);
943 if (bbuf != NULL)
944 break;
945 bio_size -= bd->bd_sectorsize;
946 }
947 if (bbuf == NULL) {
948 bio_size = V86_IO_BUFFER_SIZE;
949 if (bio_size / bd->bd_sectorsize == 0)
950 panic("BUG: Real mode buffer is too small");
942
951
943 bbuf = PTOV(V86_IO_BUFFER);
952 /* Use alternate 4k buffer */
953 bbuf = PTOV(V86_IO_BUFFER);
954 }
944 rest = size;
955 rest = size;
945
956 rc = 0;
946 while (blks > 0) {
957 while (blks > 0) {
947 int x = min(blks, V86_IO_BUFFER_SIZE / bd->bd_sectorsize);
958 int x = min(blks, bio_size / bd->bd_sectorsize);
948
949 switch (rw & F_MASK) {
950 case F_READ:
951 DEBUG("read %d from %lld to %p", x, dblk, buf);
952 bsize = bd->bd_sectorsize * x - blkoff;
953 if (rest < bsize)
954 bsize = rest;
955
959
960 switch (rw & F_MASK) {
961 case F_READ:
962 DEBUG("read %d from %lld to %p", x, dblk, buf);
963 bsize = bd->bd_sectorsize * x - blkoff;
964 if (rest < bsize)
965 bsize = rest;
966
956 if ((rc = bd_io(dev, bd, dblk, x, bbuf, BD_RD)) != 0)
957 return (EIO);
967 if ((rc = bd_io(dev, bd, dblk, x, bbuf, BD_RD)) != 0) {
968 rc = EIO;
969 goto error;
970 }
958
959 bcopy(bbuf + blkoff, buf, bsize);
960 break;
961 case F_WRITE :
962 DEBUG("write %d from %lld to %p", x, dblk, buf);
963 if (blkoff != 0) {
964 /*
965 * We got offset to sector, read 1 sector to

--- 15 unchanged lines hidden (view full) ---

981 /* We can write full sector(s). */
982 bsize = bd->bd_sectorsize * x;
983 }
984 /*
985 * Put your Data In, Put your Data out,
986 * Put your Data In, and shake it all about
987 */
988 bcopy(buf, bbuf + blkoff, bsize);
971
972 bcopy(bbuf + blkoff, buf, bsize);
973 break;
974 case F_WRITE :
975 DEBUG("write %d from %lld to %p", x, dblk, buf);
976 if (blkoff != 0) {
977 /*
978 * We got offset to sector, read 1 sector to

--- 15 unchanged lines hidden (view full) ---

994 /* We can write full sector(s). */
995 bsize = bd->bd_sectorsize * x;
996 }
997 /*
998 * Put your Data In, Put your Data out,
999 * Put your Data In, and shake it all about
1000 */
1001 bcopy(buf, bbuf + blkoff, bsize);
989 if ((rc = bd_io(dev, bd, dblk, x, bbuf, BD_WR)) != 0)
990 return (EIO);
1002 if ((rc = bd_io(dev, bd, dblk, x, bbuf, BD_WR)) != 0) {
1003 rc = EIO;
1004 goto error;
1005 }
991
992 break;
993 default:
994 /* DO NOTHING */
1006
1007 break;
1008 default:
1009 /* DO NOTHING */
995 return (EROFS);
1010 rc = EROFS;
1011 goto error;
996 }
997
998 blkoff = 0;
999 buf += bsize;
1000 rest -= bsize;
1001 blks -= x;
1002 dblk += x;
1003 }
1004
1005 if (rsize != NULL)
1006 *rsize = size;
1012 }
1013
1014 blkoff = 0;
1015 buf += bsize;
1016 rest -= bsize;
1017 blks -= x;
1018 dblk += x;
1019 }
1020
1021 if (rsize != NULL)
1022 *rsize = size;
1007 return (0);
1023error:
1024 if (bbuf != PTOV(V86_IO_BUFFER))
1025 bio_free(bbuf, bio_size);
1026 return (rc);
1008}
1009
1010static int
1011bd_edd_io(bdinfo_t *bd, daddr_t dblk, int blks, caddr_t dest,
1012 int dowrite)
1013{
1014 static struct edd_packet packet;
1015

--- 245 unchanged lines hidden ---
1027}
1028
1029static int
1030bd_edd_io(bdinfo_t *bd, daddr_t dblk, int blks, caddr_t dest,
1031 int dowrite)
1032{
1033 static struct edd_packet packet;
1034

--- 245 unchanged lines hidden ---