RTR3DECL(int) RTFsQueryType(const char *pszFsPath, PRTFSTYPE penmType) { *penmType = RTFSTYPE_UNKNOWN; AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER); AssertReturn(*pszFsPath, VERR_INVALID_PARAMETER); /* * Convert the path and try open it. */ PRTUTF16 pwszFsPath; int rc = RTStrToUtf16(pszFsPath, &pwszFsPath); if (RT_SUCCESS(rc)) { HANDLE hFile = CreateFileW(pwszFsPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (hFile != INVALID_HANDLE_VALUE) { /* * Use the NT api directly to get the file system name. */ char abBuf[8192]; IO_STATUS_BLOCK Ios; NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, abBuf, sizeof(abBuf), FileFsAttributeInformation); if (rcNt >= 0) { PFILE_FS_ATTRIBUTE_INFORMATION pFsAttrInfo = (PFILE_FS_ATTRIBUTE_INFORMATION)abBuf; if (pFsAttrInfo->FIleSystemNameLength) { } #define IS_FS(szName) \ rtFsWinAreEqual(pFsAttrInfo->FileSystemName, pFsAttrInfo->FIleSystemNameLength, szName, sizeof(szName) - 1) if (IS_FS("NTFS")) *penmType = RTFSTYPE_NTFS; else if (IS_FS("FAT")) *penmType = RTFSTYPE_FAT; else if (IS_FS("FAT32")) *penmType = RTFSTYPE_FAT; else if (IS_FS("VBoxSharedFolderFS")) *penmType = RTFSTYPE_VBOXSHF; #undef IS_FS } else rc = RTErrConvertFromNtStatus(rcNt); CloseHandle(hFile); } else rc = RTErrConvertFromWin32(GetLastError()); RTUtf16Free(pwszFsPath); } return rc; }
RTR3DECL(int) RTFsQueryType(const char *pszFsPath, PRTFSTYPE penmType) { /* * Validate input. */ *penmType = RTFSTYPE_UNKNOWN; AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER); AssertReturn(*pszFsPath, VERR_INVALID_PARAMETER); /* * Open the file/dir/whatever. */ HANDLE hFile; int rc = rtNtPathOpen(pszFsPath, GENERIC_READ, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OPEN, FILE_OPEN_FOR_BACKUP_INTENT, OBJ_CASE_INSENSITIVE, &hFile, NULL); if (RT_SUCCESS(rc)) { /* * Get the file system name. */ union { FILE_FS_ATTRIBUTE_INFORMATION FsAttrInfo; uint8_t abBuf[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 4096]; } u; IO_STATUS_BLOCK Ios = MY_IO_STATUS_BLOCK_INITIALIZER; NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &u, sizeof(u), FileFsAttributeInformation); if (NT_SUCCESS(rcNt)) { #define IS_FS(a_szName) \ rtNtCompWideStrAndAscii(u.FsAttrInfo.FileSystemName, u.FsAttrInfo.FileSystemNameLength, RT_STR_TUPLE(a_szName)) if (IS_FS("NTFS")) *penmType = RTFSTYPE_NTFS; else if (IS_FS("FAT")) *penmType = RTFSTYPE_FAT; else if (IS_FS("FAT32")) *penmType = RTFSTYPE_FAT; else if (IS_FS("VBoxSharedFolderFS")) *penmType = RTFSTYPE_VBOXSHF; #undef IS_FS } else rc = RTErrConvertFromNtStatus(rcNt); rtNtPathClose(hFile); } return rc; }
int sam_set_fs_thresh( ushort_t eq_ord, /* Equipment ordinal */ int min_threshold, /* Minimum threshold to stop release */ int max_threshold, /* Maximum threshold to start release */ /* LINTED argument unused in function */ int wait_response) /* Nonzero value to wait for response */ { char *fifo_path; /* Path to FIFO pipe, from shared memory */ dev_ent_t *device; operator_t operator; /* Data on operator */ char value[20]; /* * Get device entry and FIFO path from master shared memory segment */ if (sam_get_dev(eq_ord, &device, &fifo_path, &operator) < 0) { return (-1); } if (!IS_FS(device)) { errno = ER_DEVICE_NOT_CORRECT_TYPE; return (-1); } sprintf(value, "%d", min_threshold); (void) SetFsParam(device->set, "low", value); sprintf(value, "%d", max_threshold); (void) SetFsParam(device->set, "high", value); return (0); }
int sam_set_fs_contig( ushort_t eq_ord, /* Equipment ordinal */ int type, /* CT_readahead or CT_writebehind */ int contig, /* Maximum readahead/writebehind kilobytes */ /* LINTED argument unused in function */ int wait_response) /* Nonzero value to wait for response */ { char *fifo_path; /* Path to FIFO pipe, from shared memory */ dev_ent_t *device; operator_t operator; /* Data on operator */ char value[20]; /* * Get device entry and FIFO path from master shared memory segment */ if (sam_get_dev(eq_ord, &device, &fifo_path, &operator) < 0) { return (-1); } /* * If operator does not have 'root' authority, return with error */ if (!SAM_ROOT_LEVEL(operator)) { errno = ER_OPERATOR_NOT_PRIV; return (-1); } /* * If device is not a disk family set device, return with error */ if (!IS_FS(device)) { errno = ER_DEVICE_NOT_CORRECT_TYPE; return (-1); } sprintf(value, "%d", contig); if (type == CNTG_readahead) { (void) SetFsParam(device->set, "readahead", value); } else { (void) SetFsParam(device->set, "writebehind", value); } return (0); }