| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Volume Labels |
> What is the best way to get and set disk volume labels (in C) under OS/2?
Here's something for you, but it's not the best way (limited to drive a:
only). The DEBUG case is because I studied how a program handles empty
string as a command line parameter. OS/2's LABEL.EXE doesn't accept an
empty string if you want to clear a volume label, but this program does it.
All compilers I have handles this situation "correctly" except
GNU C/C++.
#define INCL_NOPMAPI
#define INCL_DOSFILEMGR /* File Manager values */
#include
#include
#include
int main (int argc, char **argv)
{
#ifdef __32BIT__
ULONG DriveNumber; /* Drive number */
ULONG FSInfoLevel; /* File system data type */
ULONG FSInfoBufSize; /* File system info buffer size */
VOLUMELABEL FSInfoBuf; /* File system info buffer */
APIRET rc; /* Return code */
#else
USHORT DriveNumber; /* Drive number */
USHORT FSInfoLevel; /* File system data type */
USHORT FSInfoBufSize; /* File system info buffer size */
FSINFO FSInfoBuf;
USHORT rc; /* Return code */
#endif
#ifdef DEBUG
int i, j;
#endif
/* Indicate that the caller wants to change the volume label for the */
/* specified drive */
FSInfoLevel = FSIL_VOLSER;
/* drive A: */
DriveNumber = 1;
/* Size of the entire VOLUMELABEL structure */
#ifdef __32BIT__
FSInfoBufSize = sizeof (VOLUMELABEL);
#else
FSInfoBufSize = sizeof (FSINFO);
#endif
if (argc == 1)
{
#ifdef __32BIT__
rc = DosQueryFSInfo (DriveNumber, FSInfoLevel, &FSInfoBuf, FSInfoBufSize);
printf ("Volume Label = %s\n", FSInfoBuf.szVolLabel);
#else
rc = DosQFSInfo (DriveNumber, FSInfoLevel, (void *)&FSInfoBuf,
FSInfoBufSize);
printf ("Volume Label = %s\n", FSInfoBuf.vol.szVolLabel);
#endif
return (int) rc;
}
#ifdef DEBUG
for (j = 1; j < argc; j++)
for (i = 0; i < strlen (argv[j]); i++)
printf ("argv[%d][%d] = %c (%d)\n", j, i, argv[j][i], argv[j][i]);
#endif
if (argc == 2)
{
if (argv[1][0] == '\"' && argv[1][1] == '\"')
/* The new volume label for logical drive A: */
#ifdef __32BIT__
FSInfoBuf.szVolLabel[0] = '\0';
else
strcpy (FSInfoBuf.szVolLabel, argv[1]);
#else
FSInfoBuf.vol.szVolLabel[0] = '\0';
else
strcpy (FSInfoBuf.vol.szVolLabel, argv[1]);
#endif
/* Length of the volume label string within the VOLUMELABEL structure */
#ifdef __32BIT__
FSInfoBuf.cch = (BYTE) strlen (FSInfoBuf.szVolLabel);
rc = DosSetFSInfo (DriveNumber, FSInfoLevel, &FSInfoBuf, FSInfoBufSize);
#else
FSInfoBuf.vol.cch = (BYTE) strlen (FSInfoBuf.vol.szVolLabel);
FSInfoBufSize = sizeof (VOLUMELABEL);
rc = DosSetFSInfo (DriveNumber, FSInfoLevel,
(PBYTE)(&FSInfoBuf.vol), FSInfoBufSize);
#endif
printf ("DosSetFSInfo return code = %d\n", (int)rc);
/* for debugging purposes */
}
else
{
printf ("USAGE: setvol \n");
return 1;
}
return (int) rc;
}
// Albert (Team OS/2)
email: albert{at}sci.fi
jla{at}to.icl.fi (work)
---
* Origin: Albert's Point/2 in Finland, Europe (2:221/360.20)SEEN-BY: 12/2442 620/243 624/50 632/348 640/820 690/660 711/409 410 413 430 SEEN-BY: 711/807 808 809 934 942 949 712/353 515 713/888 800/1 7877/2809 @PATH: 221/360 0 220/841 201/2104 109/347 2 7 3615/50 229/2 12/2442 711/409 @PATH: 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.