commands/drvinfo/drvinfo.cpp
changeset 66 2a78c4ff2eab
parent 0 7f656887cf89
child 67 84fefe1cd57f
--- a/commands/drvinfo/drvinfo.cpp	Mon Sep 20 16:46:34 2010 +0100
+++ b/commands/drvinfo/drvinfo.cpp	Wed Oct 13 12:41:05 2010 +0100
@@ -34,6 +34,7 @@
 	HBufC* iDriveLetter;
 	TBool iVerbose;
 	TBool iHuman;
+	TBool iLong;
 	};
 
 
@@ -56,7 +57,7 @@
 
 void CCmdDrvinfo::ArgumentErrorL()
 	{
-	Stderr().Write(_L("Invalid drive specification - use \'<drive_letter>:\', e.g. \'drvinfo c:\'\r\n"));
+	Stderr().Write(_L("Invalid drive specification - use '<drive_letter>:', e.g. 'drvinfo c:'\r\n"));
 	User::Leave(KErrArgument);
 	}
 
@@ -155,20 +156,42 @@
 		}
 	if (iVerbose)
 		{
-		aPrintBuf.AppendFormatL(_L("VolName:\t\'%S\'"), &volInfo.iName);
+		aPrintBuf.AppendFormatL(_L("VolName:\t\'%S\'\r\n"), &volInfo.iName);
 		}
-	aPrintBuf.AppendL(_L("\r\n"));
 	}
 
 void CCmdDrvinfo::PrintDriveInfoL(TInt aDriveNum)
 	{
-	IoUtils::CTextBuffer* buf = IoUtils::CTextBuffer::NewLC(0x100);
-
-	TDriveInfo 	driveInfo;
+	TDriveInfo driveInfo;
 	User::LeaveIfError(FsL().Drive(driveInfo, aDriveNum));
 
 	TVolumeInfo volInfo;
-	User::LeaveIfError(Fs().Volume(volInfo, aDriveNum));
+	TInt volErr = Fs().Volume(volInfo, aDriveNum);
+	
+	if (iLong)
+		{
+		TText readonly = '-';
+		TText removable = '-';
+		TText ram = '-';
+		if (driveInfo.iMediaAtt & KMediaAttWriteProtected) readonly = 'r';
+		if (driveInfo.iDriveAtt & KDriveAttRemovable) removable = 'e';
+		if (driveInfo.iType == EMediaRam) ram = 'm';
+
+		Printf(_L("%c%c%c %c: "), readonly, removable, ram, 'a' + aDriveNum);
+		TInt64 free = 0;
+		TInt64 size = 0;
+		if (volErr == KErrNone)
+			{
+			free = volInfo.iFree;
+			size = volInfo.iSize;
+			}
+		Printf(_L("%Ld %Ld %S"), free, size, &volInfo.iName);
+		return;
+		}
+
+	User::LeaveIfError(volErr); // Long listing handles volErr itself so didn't want to leave
+
+	IoUtils::CTextBuffer* buf = IoUtils::CTextBuffer::NewLC(0x100);
 
 	if (iVerbose || (iDriveLetter == NULL))
 		{
@@ -191,7 +214,7 @@
 		FormatMediaAttInfoL(driveInfo, *buf);
 		}
 
-	FormatVolInfoL(volInfo, *buf);
+	if (volErr == KErrNone) FormatVolInfoL(volInfo, *buf);
 
 	CTextFormatter* formatter = CTextFormatter::NewLC(Stdout());
 	formatter->TabulateL(0, 2, buf->Descriptor());
@@ -231,7 +254,10 @@
 			ArgumentErrorL();
 			}
 		}
-
+	if (iLong && (iVerbose || iHuman))
+		{
+		LeaveIfErr(KErrArgument, _L("--long cannot be specified at same time as either --human or --verbose"));
+		}
 
 	TDriveList driveList;
 	User::LeaveIfError(FsL().DriveList(driveList));
@@ -272,9 +298,11 @@
 	{
 	_LIT(KOptVerbose, "verbose");
 	_LIT(KOptHuman, "human");
+	_LIT(KOptLong, "long");
 
 	aOptions.AppendBoolL(iVerbose, KOptVerbose);
 	aOptions.AppendBoolL(iHuman, KOptHuman);
+	aOptions.AppendBoolL(iLong, KOptLong);
 	}