/* * Return the drive letter and volume label * If the drive doesn't have a volume assigned, space is returned for the letter */ BOOL GetDriveLabel(DWORD DriveIndex, char* letters, char** label) { HANDLE hPhysical; DWORD size; char AutorunPath[] = "#:\\autorun.inf", *AutorunLabel = NULL; wchar_t wDrivePath[] = L"#:\\"; wchar_t wVolumeLabel[MAX_PATH+1]; static char VolumeLabel[MAX_PATH+1]; *label = STR_NO_LABEL; if (!GetDriveLetters(DriveIndex, letters)) return FALSE; if (letters[0] == 0) { // Drive without volume assigned - always enabled return TRUE; } // We only care about an autorun.inf if we have a single volume AutorunPath[0] = letters[0]; wDrivePath[0] = letters[0]; // Try to read an extended label from autorun first. Fallback to regular label if not found. // In the case of card readers with no card, users can get an annoying popup asking them // to insert media. Use IOCTL_STORAGE_CHECK_VERIFY to prevent this hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE); if (DeviceIoControl(hPhysical, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, NULL, 0, &size, NULL)) AutorunLabel = get_token_data_file("label", AutorunPath); else if (GetLastError() == ERROR_NOT_READY) uprintf("Ignoring autorun.inf label for drive %c: %s\n", letters[0], (HRESULT_CODE(GetLastError()) == ERROR_NOT_READY)?"No media":WindowsErrorString()); safe_closehandle(hPhysical); if (AutorunLabel != NULL) { uprintf("Using autorun.inf label for drive %c: '%s'\n", letters[0], AutorunLabel); safe_strcpy(VolumeLabel, sizeof(VolumeLabel), AutorunLabel); safe_free(AutorunLabel); *label = VolumeLabel; } else if (GetVolumeInformationW(wDrivePath, wVolumeLabel, ARRAYSIZE(wVolumeLabel), NULL, NULL, NULL, NULL, 0) && *wVolumeLabel) { wchar_to_utf8_no_alloc(wVolumeLabel, VolumeLabel, sizeof(VolumeLabel)); *label = VolumeLabel; } return TRUE; }
TInt E32Main() { TInt r; test.Title(); test.Start(_L("Starting T_DENYCLAMP ...")); test(TheFs.Connect()==KErrNone); GetDriveLetters(); TBuf<256> pathName; //************************************************************************ // // Test on FAT (writable file system) // //************************************************************************ if(NandFatDrv!='?') { pathName=_L("?:\\CLAMP-TST\\"); // FAT on NAND pathName[0]=(TText)NandFatDrv; r=TheFs.MkDirAll(pathName); test(r==KErrNone || r== KErrAlreadyExists); TheFs.SetSessionPath(pathName); test.Printf( _L("T_DENYCLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv); Test1(); // Basic clamp operation Test2(); // Invalid clamp requests // Test3(pathName);// Denied FS requests when files are clamped - invalid for T_DENYCLAMP r=TheFs.RmDir(pathName); test(r==KErrNone); } else test.Printf( _L("T_DENYCLAMP: FAT drive not tested\n")); //************************************************************************ // // Test on ROFS (non-writable file system) // //************************************************************************ if(RofsDrv!='?') { pathName=_L("?:\\"); pathName[0]=(TText)RofsDrv; TheFs.SetSessionPath(pathName); test.Printf( _L("T_DENYCLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv); Test4(pathName); // Clamp tests for non-writable file system } else test.Printf( _L("T_DENYCLAMP: ROFS drive not tested\n")); //************************************************************************ // // Test on Z: - Composite File System, or ROMFS (non-writable file system) // //************************************************************************ if(CompDrv!='?') { pathName=_L("?:\\TEST\\"); pathName[0]=(TText)CompDrv; TheFs.SetSessionPath(pathName); test.Printf( _L("T_DENYCLAMP: testing Z drive (on %C)\n"),(TText)CompDrv); Test4(pathName); // Clamp tests for non-writable file system } else test.Printf( _L("T_DENYCLAMP: Z drive not tested\n")); //************************************************************************ // // Test on LFFS (non-clampable file system) // //************************************************************************ if(LffsDrv!='?') { TBuf<256> unsuppPath; unsuppPath=_L("?:\\CLAMP-TST\\"); unsuppPath[0]=(TText)LffsDrv; r=TheFs.MkDirAll(unsuppPath); test(r==KErrNone || r== KErrAlreadyExists); TheFs.SetSessionPath(unsuppPath); test.Printf( _L("T_DENYCLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv); Test5(); // Clamp requests on non-clamping file systems } else test.Printf( _L("T_DENYCLAMP: LFFS drive not tested\n")); test.End(); return 0; }