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

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

unix.superglobalmegacorp.com

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