Annotation of os2sdk/demos/examples/fsinfo/fsinfo.c, revision 1.1

1.1     ! root        1: /***
        !             2:  *     Example of DOSQFSINFO and DOSSETFSINFO. Also DOSERROR.
        !             3:  *
        !             4:  *     First do a DOSQFSINFO level 1 to get the A drive 
        !             5:  *     parameters, then a DOSQFSINFO level 2 to check the volume 
        !             6:  *     label of the A drive. Next do a DOSSETFSINFO to
        !             7:  *     change the volume label to FSIDEMO, and lastly another
        !             8:  *     DOSQFSINFO level 2 to verify the set.
        !             9:  */
        !            10: 
        !            11: #include <doscalls.h>
        !            12: 
        !            13: #define FSIBUF 40
        !            14: 
        !            15: unsigned drive;                        /* drive number */
        !            16: unsigned retcode;              /* return code from call */
        !            17: unsigned testbufsiz;           /* length of volume label to set */
        !            18: int *date_time;                        /* date and time returned by level 2 query */
        !            19: char setlabel[] = "\007FSIDEMO";    /* buffer for DosSetFSInfo */
        !            20:                                    /* starts with byte of string length */
        !            21: 
        !            22: /* FSInfoBuf level 1 */
        !            23: typedef struct {
        !            24:        unsigned long fsID;             /* file system ID */
        !            25:        unsigned long SecPerAU;         /* number of sectors per alloc. unit */
        !            26:        unsigned long NumAU;            /* number of allocation units */
        !            27:        unsigned long NumAUAvail;       /* available allocation units */
        !            28:        unsigned BytesSec;              /* number of bytes per sector */
        !            29: } lev1buf;
        !            30: 
        !            31: lev1buf fsinfobuf;
        !            32: 
        !            33: /*     the level 2 FSInfoBuf buffer contains
        !            34:  *             2 bytes - volume label date of creation
        !            35:  *             2 bytes - volume label time of creation
        !            36:  *             1 byte - length of volume label
        !            37:  *             'n' bytes - the volume label string
        !            38:  */
        !            39: 
        !            40: char buffer[FSIBUF];           /* buffer for DosQFSInfo, level 2 */
        !            41: 
        !            42: main()
        !            43: {
        !            44:        unsigned level;
        !            45:        drive = 1;                      /* A drive */
        !            46: 
        !            47:        /* turn off hard errors so we see if user has drive A open */
        !            48:        DOSERROR(0);
        !            49: 
        !            50:        /* check the parameters of the A drive using DOSQFSINFO level 1 */
        !            51:        level = 1;
        !            52:        retcode = DOSQFSINFO( drive, level, (char *)&fsinfobuf, FSIBUF);
        !            53: 
        !            54:        if ( retcode )
        !            55:                printf("Received error %d from DOSQFSINFO\n", retcode);
        !            56:        else {
        !            57:                printf("DOSQFSINFO provided the following information:\n");
        !            58:                printf("   File System ID - %ld\n", fsinfobuf.fsID);
        !            59:                printf("   Sectors per allocation unit - %ld\n",
        !            60:                    fsinfobuf.SecPerAU);
        !            61:                printf("   Number of allocation units - %ld\n",
        !            62:                    fsinfobuf.NumAU);
        !            63:                printf("   Available allocation units - %ld\n",
        !            64:                    fsinfobuf.NumAUAvail);
        !            65:                printf("   Bytes per sector - %d\n\n",
        !            66:                    fsinfobuf.BytesSec);
        !            67:        }
        !            68: 
        !            69:        /* check for a volume label on the A drive using DOSQFSINFO 
        !            70:         * level 2.  Access the data in the buffer as follows:
        !            71:         *      time - first pair of bytes in the buffer (date_time[0])
        !            72:         *      date - second pair of bytes in the buffer (date_time[1])
        !            73:         *      label length - resides at buffer[4], 4 bytes into buffer
        !            74:         *      label - string starts at the fifth byte of the buffer
        !            75:         */
        !            76: 
        !            77:        level = 2;
        !            78:        retcode = DOSQFSINFO( drive, level, (char *)buffer, FSIBUF);
        !            79: 
        !            80:        date_time = (int *)buffer;      /* pointer into time/date info */
        !            81:        if ( !retcode ) {               /* got volume label */
        !            82:                printf("DOSQFSINFO found volume label %s on drive %d\n", 
        !            83:                    buffer+5, drive );
        !            84:                printf("   label length %d, date 0x%x, time 0x%x\n\n", 
        !            85:                    buffer[4], date_time[0], date_time[1] );
        !            86:        }
        !            87:        else if ( retcode == 125 )
        !            88:                printf("No volume label found by DOSQFSINFO on drive %d\n\n", 
        !            89:                    drive );
        !            90:        else
        !            91:                printf("DOSQFSINFO call failed with error %d\n\n", retcode );
        !            92: 
        !            93:        /* do a DosSetFSInfo, changing the volume label to FSIDEMO  */
        !            94:        testbufsiz = strlen( setlabel );
        !            95: 
        !            96:        retcode = DOSSETFSINFO( drive, level, setlabel, testbufsiz);
        !            97: 
        !            98:        if ( retcode )
        !            99:                printf("Error %d setting volume label to %s on drive %d\n\n", 
        !           100:                       retcode, setlabel, drive);
        !           101:        else {
        !           102:                printf("DOSSETFSINFO set volume label %s\n", setlabel+1);
        !           103: 
        !           104:                /* do a DosQFSInfo to verify the set */
        !           105:                DOSQFSINFO( drive, level, (char *)buffer, FSIBUF);
        !           106:                printf("DOSQFSINFO found label %s\n", buffer+5);
        !           107:        }
        !           108: }

unix.superglobalmegacorp.com

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