[BACK]Return to fdd.c CVS log [TXT][DIR] Up to [local] / prex-old / usr / test / fdd

Annotation of prex-old/usr/test/fdd/fdd.c, Revision 1.1

1.1     ! nbrk        1: /*-
        !             2:  * Copyright (c) 2005-2006, Kohsuke Ohtani
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms, with or without
        !             6:  * modification, are permitted provided that the following conditions
        !             7:  * are met:
        !             8:  * 1. Redistributions of source code must retain the above copyright
        !             9:  *    notice, this list of conditions and the following disclaimer.
        !            10:  * 2. Redistributions in binary form must reproduce the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer in the
        !            12:  *    documentation and/or other materials provided with the distribution.
        !            13:  * 3. Neither the name of the author nor the names of any co-contributors
        !            14:  *    may be used to endorse or promote products derived from this software
        !            15:  *    without specific prior written permission.
        !            16:  *
        !            17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
        !            18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
        !            21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            27:  * SUCH DAMAGE.
        !            28:  */
        !            29:
        !            30: /*
        !            31:  * fdd.c - fdd driver test program.
        !            32:  */
        !            33:
        !            34: #include <prex/prex.h>
        !            35: #include <stdio.h>
        !            36: #include <string.h>
        !            37: #include <ctype.h>
        !            38:
        !            39: int
        !            40: test_read(int sector)
        !            41: {
        !            42:        device_t fdd;
        !            43:        size_t size;
        !            44:        int err, i, j;
        !            45:        static unsigned char disk_buf[512];
        !            46:        unsigned char ch;
        !            47:
        !            48:        printf("open fd0\n");
        !            49:        err = device_open("fd0", 0, &fdd);
        !            50:        if (err) {
        !            51:                printf("open failed\n");
        !            52:                return 0;
        !            53:        }
        !            54:        printf("opened\n");
        !            55:
        !            56:        printf("fdd read: sector=%d buf=%x\n", sector, (u_int)disk_buf);
        !            57:        size = 512;
        !            58:        err = device_read(fdd, disk_buf, &size, sector);
        !            59:        if (err) {
        !            60:                printf("read failed\n");
        !            61:                device_close(fdd);
        !            62:                return 0;
        !            63:        }
        !            64:        printf("read comp: sector=%d buf=%x\n", sector, (u_int)disk_buf);
        !            65:
        !            66:        for (i = 0; i < (512 / 16); i++) {
        !            67:                for (j = 0; j < 16; j++)
        !            68:                        printf("%02x ", disk_buf[i * 16 + j]);
        !            69:                printf("    ");
        !            70:                for (j = 0; j < 16; j++) {
        !            71:                        ch = disk_buf[i * 16 + j];
        !            72:                        if (isprint(ch))
        !            73:                                putchar(ch);
        !            74:                        else
        !            75:                                putchar('.');
        !            76:
        !            77:                }
        !            78:                printf("\n");
        !            79:        }
        !            80:        printf("\n");
        !            81:        err = device_close(fdd);
        !            82:        if (err)
        !            83:                printf("close failed\n");
        !            84:
        !            85:        return 0;
        !            86: }
        !            87:
        !            88: int
        !            89: test_write(int sector)
        !            90: {
        !            91:        device_t fdd;
        !            92:        size_t size;
        !            93:        int err;
        !            94:        static unsigned char disk_buf[512];
        !            95:
        !            96:        printf("open fd0\n");
        !            97:        err = device_open("fd0", 0, &fdd);
        !            98:        if (err) {
        !            99:                printf("open failed\n");
        !           100:                return 0;
        !           101:        }
        !           102:        printf("opened\n");
        !           103:
        !           104:        size = 512;
        !           105:        err = device_read(fdd, disk_buf, &size, sector);
        !           106:        if (err) {
        !           107:                printf("read failed\n");
        !           108:                device_close(fdd);
        !           109:                return 0;
        !           110:        }
        !           111:        printf("read comp sector=%d\n", sector);
        !           112:
        !           113:        size = 512;
        !           114:        err = device_write(fdd, disk_buf, &size, sector);
        !           115:        if (err) {
        !           116:                printf("write failed\n");
        !           117:                device_close(fdd);
        !           118:                return 0;
        !           119:        }
        !           120:        printf("write comp sector=%d\n", sector);
        !           121:
        !           122:        err = device_close(fdd);
        !           123:        if (err)
        !           124:                printf("close failed\n");
        !           125:        return 0;
        !           126: }
        !           127:
        !           128: int
        !           129: main(int argc, char *argv[])
        !           130: {
        !           131:        test_read(0);
        !           132:        test_read(1);
        !           133:        test_read(2);
        !           134:
        !           135:        test_write(1);
        !           136:
        !           137:        return 0;
        !           138: }

CVSweb