Annotation of coherent/d/bin/dos/dosdrives.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * dosdrives.c
        !             3:  * 12/5/90
        !             4:  * Display MS-DOS drive information.
        !             5:  */
        !             6: 
        !             7: #include <stdio.h>
        !             8: #include <sys/fdisk.h>
        !             9: 
        !            10: extern long lseek();
        !            11: 
        !            12: /* Globals. */
        !            13: char   buf[512];
        !            14: char   buf2[512];
        !            15: char   *devp;
        !            16: char   devname[10];
        !            17: int    drive;
        !            18: int    fd;
        !            19: int    pass;
        !            20: 
        !            21: /*
        !            22:  * List of partition tables to search.
        !            23:  * This must be updated as new devices are added to the system.
        !            24:  */
        !            25: char *devices[] = {
        !            26:        "/dev/at0x", "/dev/at1x",
        !            27:        "/dev/sd0x", "/dev/sd1x", "/dev/sd2x", "/dev/sd3x",
        !            28:        "/dev/sd4x", "/dev/sd5x", "/dev/sd6x"
        !            29: };
        !            30: #define        DEVMAX  (sizeof(devices)/sizeof(devices[0]))
        !            31: 
        !            32: void   checkdev();
        !            33: void   fatal();
        !            34: 
        !            35: main(argc, argv) int argc; char        *argv[];
        !            36: {
        !            37:        register int dev;
        !            38: 
        !            39:        printf("A:\nB:\n");
        !            40:        drive = 2;
        !            41:        for (pass = 1; pass <= 2; pass++) {
        !            42:                for (dev = 0; dev < DEVMAX; dev++) {
        !            43:                        devp = devices[dev];
        !            44:                        if ((fd = open(devp, 0)) < 0)
        !            45:                                continue;
        !            46:                        checkdev();
        !            47:                        close(fd);
        !            48:                }
        !            49:        }
        !            50:        exit(0);
        !            51: }
        !            52: 
        !            53: void
        !            54: checkdev()
        !            55: {
        !            56:        register int i, j, sys;
        !            57:        FDISK_S *fdp1, *fdp2;
        !            58:        HDISK_S *hdp, *hdp2;
        !            59:        long partseek1, partseek2;
        !            60: 
        !            61:        /* Read the partition table. */
        !            62:        if (read(fd, buf, sizeof(buf)) != sizeof(buf))
        !            63:                fatal("read1 failed on \"%s\"", devp);
        !            64:        hdp = buf;
        !            65:        if (hdp->hd_sig != HDSIG)
        !            66:                return;                         /* no signature, ignore */
        !            67:        for (i = 0; i < NPARTN; i++) {
        !            68:                sys = (hdp->hd_partn[i]).p_sys;
        !            69:                if (sys != SYS_DOS_12
        !            70:                 && sys != SYS_DOS_16
        !            71:                 && sys != SYS_DOS_XP
        !            72:                 && sys != SYS_DOS_LARGE)
        !            73:                        continue;               /* not a DOS partition */
        !            74:                strcpy(devname, devp);
        !            75:                devname[strlen(devname)-1] = 'a' + i;
        !            76:                if (pass == 1 && sys != SYS_DOS_XP) {
        !            77:                        /* Count non-extended partitions on pass 1. */
        !            78:                        printf("%c: %s\n", 'A'+drive, devname);
        !            79:                        ++drive;
        !            80:                        continue;
        !            81:                } else if (pass == 2 && sys == SYS_DOS_XP) {
        !            82:                        /* Count extended partitions on pass 2. */
        !            83:                        fdp2 = &(hdp->hd_partn[i]);
        !            84:                        partseek1 = fdp2->p_base * 512; /* base of first */
        !            85:                        partseek2 = 0L;                 /* offset from first */
        !            86:                        for (j = 1; ; j++) {
        !            87:                                if (lseek(fd, partseek1+partseek2, 0) == -1L)
        !            88:                                        fatal("lseek failed");
        !            89:                                /* Read the extended DOS drive partition table. */
        !            90:                                if (read(fd, buf2, sizeof(buf2)) != sizeof(buf2))
        !            91:                                        fatal("read2 failed on \"%s\" at %lx",
        !            92:                                                devp, partseek1+partseek2);
        !            93:                                hdp2 = buf2;
        !            94:                                fdp1 = &(hdp2->hd_partn[0]);
        !            95:                                fdp2 = &(hdp2->hd_partn[1]);
        !            96:                                printf("%c: %s %d\n", 'A'+drive, devname, j);
        !            97:                                ++drive;
        !            98:                                if (fdp2->p_sys != SYS_DOS_XP)
        !            99:                                        break;          /* done */
        !           100:                                partseek2 = fdp2->p_base * 512;
        !           101:                        }
        !           102:                }
        !           103:        }
        !           104: }
        !           105: 
        !           106: void
        !           107: fatal(s) char *s;
        !           108: {
        !           109:        fprintf(stderr, "dosdrives: %r\n", &s);
        !           110:        exit(1);
        !           111: }
        !           112: 
        !           113: /* end of dosdrives.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.