INT cmd_vol (LPTSTR param) { TCHAR szRootPath[] = _T("A:\\"); TCHAR szPath[MAX_PATH]; if (!_tcsncmp(param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_VOL_HELP4); return 0; } nErrorLevel = 0; if (param[0] == _T('\0')) { GetCurrentDirectory(MAX_PATH, szPath); szRootPath[0] = szPath[0]; } else { _tcsupr (param); if (param[1] == _T(':')) { szRootPath[0] = param[0]; } else { error_invalid_drive (); nErrorLevel = 1; return 1; } } if (!IsValidPathName (szRootPath)) { error_invalid_drive (); nErrorLevel = 1; return 1; } /* print the header */ if (!PrintVolumeHeader (szRootPath)) { nErrorLevel = 1; return 1; } return 0; }
/* * CD / CHDIR * */ INT cmd_chdir (LPTSTR param) { TCHAR szCurrent[MAX_PATH]; BOOL bChangeDrive = FALSE; /* Filter out special cases first */ /* Print Help */ if (!_tcsncmp(param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_CD_HELP); return 0; } /* Remove " */ StripQuotes(param); /* Set Error Level to Success */ nErrorLevel = 0; /* Print Current Directory on a disk */ if (_tcslen(param) == 2 && param[1] == _T(':')) { if (GetRootPath(param, szCurrent, MAX_PATH)) { error_invalid_drive(); return 1; } ConOutPuts(szCurrent); return 0; } /* Get Current Directory */ GetCurrentDirectory(MAX_PATH, szCurrent); if (param[0] == _T('\0')) { ConOutPuts(szCurrent); return 0; } /* Input String Contains /D Switch */ if (!_tcsncicmp(param, _T("/D"), 2)) { bChangeDrive = TRUE; param += 2; while (_istspace(*param)) param++; } if (!SetRootPath(bChangeDrive ? NULL : szCurrent, param)) return 1; return 0; }
int changeDrive(int drive) { drive = drvNum(drive); setdisk(drive); if (getdisk() == drive) return 0; error_invalid_drive(drive); return 1; }
INT cmd_label (LPTSTR param) { TCHAR szRootPath[] = _T("A:\\"); TCHAR szLabel[80]; TCHAR szOldLabel[80]; DWORD dwSerialNr; /* set empty label string */ szLabel[0] = _T('\0'); nErrorLevel = 0; /* print help */ if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_LABEL_HELP1); return 0; } /* get parameters */ if (param[0] != _T('\0') && param[1] == _T(':')) { szRootPath[0] = (TCHAR)toupper(*param); param += 2; while (_istspace(*param)) param++; } else { /* get label of current drive */ TCHAR szCurPath[MAX_PATH]; GetCurrentDirectory (MAX_PATH, szCurPath); szRootPath[0] = szCurPath[0]; } _tcsncat(szLabel, param, 79); /* check root path */ if (!IsValidPathName (szRootPath)) { error_invalid_drive (); nErrorLevel = 1; return 1; } if (szLabel[0] == _T('\0')) { GetVolumeInformation(szRootPath, szOldLabel, 80, &dwSerialNr, NULL, NULL, NULL, 0); /* print drive info */ if (szOldLabel[0] != _T('\0')) { ConOutResPrintf(STRING_LABEL_HELP2, _totupper(szRootPath[0]), szOldLabel); } else { ConOutResPrintf(STRING_LABEL_HELP3, _totupper(szRootPath[0])); } /* print the volume serial number */ ConOutResPrintf(STRING_LABEL_HELP4, HIWORD(dwSerialNr), LOWORD(dwSerialNr)); ConOutResPuts(STRING_LABEL_HELP5); ConInString(szLabel, 80); } if (!SetVolumeLabel(szRootPath, szLabel)) { ConOutFormatMessage(GetLastError()); nErrorLevel = 1; return 1; } return 0; }