// display drive information void CPieView::DisplayDrive(CString driveLetter) { pDiskLetter=driveLetter; GetDiskInfo(driveLetter); folderSize.GetFolderSize(driveLetter,&folderCount,&fileCount,pOther); Invalidate(); }
static int updateToc(void) { if (tocUpToDate) return 0; if (GetDiskInfo() < 0) return -EIO; if (GetToc() < 0) return -EIO; tocUpToDate = 1; return 0; }
/********************************************************************************************************* ** 函数名称: ChangeDrive ** 功能描述: 改变当前逻辑盘 ** ** 输 入: Drive:逻辑盘符字符串 ** ** 输 出: RETURN_OK:成功 ** NOT_FIND_DISK:逻辑盘不存在 ** PARAMETER_ERR:非法参数 ** 全局变量: 无 ** 调用模块: strupr,GetDiskInfo ********************************************************************************************************/ acoral_u8 ChangeDrive(acoral_char *Drive) { acoral_u8 Rt; Disk_Info *Disk; Rt = PARAMETER_ERR; strupr(Drive); /* 变为大写 */ if (Drive[1] == ':') { Rt = NOT_FIND_DISK; Disk = GetDiskInfo(Drive[0] - 'A'); if (Disk != NULL) { CurrentDrive = Drive[0] - 'A'; Rt = RETURN_OK; } } return Rt; }
PartitionSelect::PartitionSelect(QWidget *parent) : QDialog(parent), ui(new Ui::PartitionSelect){ ui->setupUi(this); if(parent!=0){ //Center the window on the parent QPoint ctr = parent->geometry().center(); this->move(ctr.x() - (this->width()/2), ctr.y()-(this->height()/2) ); } //Initial output values selected = false; HD.clear(); PART.clear(); //Load the disk information GetDiskInfo(); //Now load the available hard disks into the UI UpdateDisks(); //Now load the available partitions on the current disk into the UI UpdateParts(); //Now setup the signals/slots connect(ui->combo_hd, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateParts()) ); connect(ui->list_part, SIGNAL(currentRowChanged(int)), this, SLOT(CheckValidity()) ); }
/********************************************************************************************************* ** 函数名称: ChangeDir ** 功能描述: 改变当前目录 ** ** 输 入: Path:路径名 ** ** 输 出: RETURN_OK:成功 ** 其它参考fat.h中关于返回值的说明 ** 全局变量: 无 ** 调用模块: GetDirClusIndex,GetDiskInfo ********************************************************************************************************/ acoral_u8 ChangeDir(acoral_char *Path) { acoral_u32 ClusIndex; acoral_u8 Rt, Drive; Disk_Info *Disk; Rt = PATH_NOT_FIND; ClusIndex = GetDirClusIndex(Path); if (ClusIndex != BAD_CLUS) { Drive = GetDrive(Path); Disk = GetDiskInfo(Drive); Rt = NOT_FIND_DISK; if (Disk != NULL) { Rt = RETURN_OK; Disk->PathClusIndex = ClusIndex; } } return Rt; }
// Check if a volume/path is available BOOL VolumePresent(DirBuffer *buffer) { D_S(struct InfoData, info) struct DosList *dos; char volume[32]; // Valid path? if (!buffer->buf_Path[0]) return 0; // Get current disk info if (!(GetDiskInfo(buffer->buf_Path,info)) || !(dos=(struct DosList *)BADDR(info->id_VolumeNode))) return 0; // Valid dos list? if (!dos || !dos->dol_Name) return 0; // Is volume mounted? if (info->id_DiskType==ID_NO_DISK_PRESENT || info->id_DiskType==ID_UNREADABLE_DISK) return 0; // Get current disk name if (dos->dol_Name) BtoCStr(dos->dol_Name,volume,32); else { char *ptr; stccpy(volume,buffer->buf_ExpandedPath,32); if ((ptr=strchr(volume,':'))) *ptr=0; } // Compare disk name if (strcmp(volume,buffer->buf_VolumeLabel)!=0) return 0; // Compare date stamp if (CompareDates(&dos->dol_misc.dol_volume.dol_VolumeDate,&buffer->buf_VolumeDate)!=0) return 0; // Volume is available return 1; }
std::string CSysInfo::GetAllInfo (void) { struct sInfo { map<string, string> * pMap; string Part; }; sInfo Infos[ ] = { {&m_mapCPU , "CPU" }, {&m_mapOS , "OS" }, {&m_mapVideo, "Video" }, {&m_mapDisc , "Disk" }, {&m_mapMem , "Memory"} }; std::map<string, string>::iterator im; GetCpuInfo (); GetDiskInfo (); GetOSInfo (); GetVideoInfo (); GetMemInfo (); string strInfo; for(int i = 0; i < sizeof (Infos) / sizeof (sInfo); i++) { strInfo += "[ "; strInfo += Infos[ i ].Part + " ]\n"; for(im = Infos[ i ].pMap->begin (); im != Infos[ i ].pMap->end (); im++) { strInfo += im->first; strInfo += " : "; strInfo += im->second; strInfo += "\n"; } } return strInfo; }
// // Target can be file name // Arg[0]: Device number. Optional // // From NdasOpReadDIB, LurnRMDRead // int CmdViewMeta(char* target, char* arg[]) { UINT64 Pos = 10; int retval = 0; SOCKET connsock; PUCHAR data = NULL; int iResult; unsigned UserId; FILE* file = NULL; NDAS_DIB_V2 DIB_V2; NDAS_RAID_META_DATA Rmd; NDAS_LAST_WRITTEN_REGION_BLOCK Lwr; UINT32 i, j; BOOL IsTargetFile; UINT64 DiskSectorCount; char* str; PNDAS_UNIT_META_DATA UnitMeta; data = (PUCHAR) malloc(MAX_DATA_BUFFER_SIZE); if (strcspn(target, ":") >=strlen(target)) { IsTargetFile = TRUE; } else { IsTargetFile = FALSE; } if (IsTargetFile) { struct __stat64 statbuff; file = fopen(target, "r"); if (file ==NULL) { fprintf(stderr, "Failed to open file\n"); retval = GetLastError(); goto errout; } iResult = _stat64(target, &statbuff); if (iResult !=0) { fprintf(stderr, "Failed to get stat file\n"); goto errout; } DiskSectorCount = statbuff.st_size/BLOCK_SIZE; } else { int dev; UserId = MAKE_USER_ID(DEFAULT_USER_NUM, USER_PERMISSION_SW); if (arg[0]) dev = (int) _strtoi64(arg[0], NULL, 0); else dev = 0; if (dev==0) { // } else { UserId |= 0x100; } if (ConnectToNdas(&connsock, target, UserId, NULL) !=0) goto errout; // Need to get disk info before IO if((iResult = GetDiskInfo(connsock, iTargetID, TRUE, TRUE)) != 0) { fprintf(stderr, "GetDiskInfo Failed...\n"); retval = iResult; goto errout; } DiskSectorCount = PerTarget[iTargetID].SectorCount; } fprintf(stderr,"Total sector count = %I64d\n", DiskSectorCount); // Read an NDAS_DIB_V2 structure from the NDAS Device at NDAS_BLOCK_LOCATION_DIB_V2 if (IsTargetFile) { iResult = fseek(file, (long)((DiskSectorCount + NDAS_BLOCK_LOCATION_DIB_V2)*BLOCK_SIZE), SEEK_SET); if (iResult != 0) { fprintf(stderr, "fseek error\n"); goto errout; } iResult = (int)fread((void*)&DIB_V2, 512, 1, file); if (iResult == 0) { fprintf(stderr, "fread error\n"); goto errout; } } else { iResult = IdeCommand(connsock, iTargetID, 0, WIN_READ, DiskSectorCount + NDAS_BLOCK_LOCATION_DIB_V2, 1, 0, sizeof(DIB_V2), (PCHAR)&DIB_V2, 0, 0); if (iResult != 0) { fprintf(stderr, "READ Failed.\n"); goto errout; } } // Check Signature, Version and CRC informations in NDAS_DIB_V2 and accept if all the informations are correct if(NDAS_DIB_V2_SIGNATURE != DIB_V2.Signature) { if (DIB_V2.Signature == 0) { fprintf(stderr, "No DIBv2 signature. Single disk or uninitialized disk.\n"); } else { fprintf(stderr, "V2 Signature mismatch\n"); } goto errout; //goto process_v1; } if(!IS_DIB_CRC_VALID(crc32_calc, DIB_V2)) { fprintf(stderr, "CRC mismatch\n"); goto errout; // goto process_v1; } if(NDAS_BLOCK_SIZE_XAREA != DIB_V2.sizeXArea && NDAS_BLOCK_SIZE_XAREA * SECTOR_SIZE != DIB_V2.sizeXArea) { fprintf(stderr, "Reserved size mismatch\n"); goto errout; // goto process_v1; } if(DIB_V2.sizeUserSpace + DIB_V2.sizeXArea > DiskSectorCount) { fprintf(stderr, "Disk size mistmatch\n"); goto errout; // goto process_v1; } #if 0 nTotalDiskCount = DIB_V2.nDiskCount + DIB_V2.nSpareCount; // check DIB_V2.nDiskCount if(!NdasOpVerifyDiskCount(DIB_V2.iMediaType, DIB_V2.nDiskCount)) goto process_v1; #endif // Dump DIB info printf("DIBV2 Major Version = %d, Minor version = %d\n", DIB_V2.MajorVersion, DIB_V2.MinorVersion); printf("User Space in sectors=%I64d, X space=%I64d\n", DIB_V2.sizeUserSpace, DIB_V2.sizeXArea); printf("Bitmap sector per bit=%d(%fMbyte)\n", DIB_V2.iSectorsPerBit, DIB_V2.iSectorsPerBit / 2.0/1024); switch(DIB_V2.iMediaType) { case NMT_SINGLE: str="Single"; break; case NMT_MIRROR: str="Mirror without repair info"; break; case NMT_AGGREGATE: str="Aggregation"; break; case NMT_RAID0: str="RAID0"; break; case NMT_RAID1: str="RAID1(~3.10)"; break; case NMT_RAID4: str="RAID4(~3.10)"; break; case NMT_RAID1R2: str="RAID1(3.11~)"; break; case NMT_RAID4R2: str="RAID4(3.11~)"; break; case NMT_RAID1R3: str="RAID1(3.20~)"; break; case NMT_RAID4R3: str="RAID4(3.20~)"; break; case NMT_AOD: str="Append only disk"; break; case NMT_VDVD: str="Virtual DVD"; break; case NMT_CDROM: str="packet device, CD / DVD"; break; case NMT_OPMEM: str="packet device, Magnetic Optical"; break; case NMT_FLASH: str="flash card"; break; default: str="Unknown"; break; } printf("Media type=%d(%s)\n", DIB_V2.iMediaType, str); printf("Diskcount=%d, Sequence=%d, SpareCount=%d\n", DIB_V2.nDiskCount, DIB_V2.iSequence, DIB_V2.nSpareCount); for(i=0;i<DIB_V2.nDiskCount+DIB_V2.nSpareCount;i++) { printf(" * Unit disk %d: ", i); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x, VID: %x, UnitNumber=%d, HwVersion=%d\n", DIB_V2.UnitDisks[i].MACAddr[0], DIB_V2.UnitDisks[i].MACAddr[1], DIB_V2.UnitDisks[i].MACAddr[2], DIB_V2.UnitDisks[i].MACAddr[3], DIB_V2.UnitDisks[i].MACAddr[4], DIB_V2.UnitDisks[i].MACAddr[5], DIB_V2.UnitDisks[i].VID, DIB_V2.UnitDisks[i].UnitNumber, DIB_V2.UnitDiskInfos[i].HwVersion ); } // Show RMD info if (IsTargetFile) { iResult = fseek(file, (long)((DiskSectorCount + NDAS_BLOCK_LOCATION_RMD)*BLOCK_SIZE), SEEK_SET); if (iResult != 0) { fprintf(stderr, "fseek error\n"); goto errout; } iResult = (int)fread((void*)&Rmd, 512, 1, file); if (iResult == 0) { fprintf(stderr, "fread error\n"); goto errout; } } else { iResult = IdeCommand(connsock, iTargetID, 0, WIN_READ, DiskSectorCount + NDAS_BLOCK_LOCATION_RMD, 1, 0, sizeof(Rmd), (PCHAR)&Rmd, 0, 0); if (iResult != 0) { fprintf(stderr, "READ Failed.\n"); goto errout; } } // Check Signature, Version and CRC informations in NDAS_DIB_V2 and accept if all the informations are correct if(NDAS_RAID_META_DATA_SIGNATURE != Rmd.Signature) { fprintf(stderr, "RMD Signature mismatch: %I64x\n", Rmd.Signature); goto errout; //goto process_v1; } if(!IS_RMD_CRC_VALID(crc32_calc, Rmd)) { fprintf(stderr, "RMD CRC mismatch\n"); goto errout; // goto process_v1; } printf("RAID Set ID = %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n", Rmd.guid.Data1, Rmd.guid.Data2, Rmd.guid.Data3, Rmd.guid.Data4[0], Rmd.guid.Data4[1], Rmd.guid.Data4[2], Rmd.guid.Data4[3], Rmd.guid.Data4[4], Rmd.guid.Data4[5], Rmd.guid.Data4[6], Rmd.guid.Data4[7] ); printf("Config Set ID= %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n", Rmd.ConfigSetId.Data1, Rmd.ConfigSetId.Data2, Rmd.ConfigSetId.Data3, Rmd.ConfigSetId.Data4[0], Rmd.ConfigSetId.Data4[1], Rmd.ConfigSetId.Data4[2], Rmd.ConfigSetId.Data4[3], Rmd.ConfigSetId.Data4[4], Rmd.ConfigSetId.Data4[5], Rmd.ConfigSetId.Data4[6], Rmd.ConfigSetId.Data4[7] ); printf("USN: %d\n", Rmd.uiUSN); switch(Rmd.state & (NDAS_RAID_META_DATA_STATE_MOUNTED | NDAS_RAID_META_DATA_STATE_UNMOUNTED)) { case NDAS_RAID_META_DATA_STATE_MOUNTED: str= "Mounted"; break; case NDAS_RAID_META_DATA_STATE_UNMOUNTED: str= "Unmounted"; break; default: str = "Unknown/Never Mounted"; break; } if (Rmd.state & NDAS_RAID_META_DATA_STATE_USED_IN_DEGRADED) { printf("This member is used in degraded mode\n"); } printf("State: %d(%s)\n", Rmd.state, str); for(i=0;i<NDAS_DRAID_ARBITER_ADDR_COUNT;i++) { if (Rmd.ArbiterInfo[i].Type == 0) break; printf("DRAID Listen Address: Type %d - %02x:%02x:%02x:%02x:%02x:%02x\n", Rmd.ArbiterInfo[i].Type, Rmd.ArbiterInfo[i].Addr[0], Rmd.ArbiterInfo[i].Addr[1], Rmd.ArbiterInfo[i].Addr[2], Rmd.ArbiterInfo[i].Addr[3], Rmd.ArbiterInfo[i].Addr[4], Rmd.ArbiterInfo[i].Addr[5] ); } for(i=0;i<DIB_V2.nDiskCount+DIB_V2.nSpareCount;i++) { char* DefectStr; printf(" * Role %d: ", i); UnitMeta = &Rmd.UnitMetaData[i]; printf("Unit index=%d Status=%d(%s%s%s%s%s%s)\n", UnitMeta->iUnitDeviceIdx, UnitMeta->UnitDeviceStatus, (UnitMeta->UnitDeviceStatus==0)?"Normal ":"", (UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_NOT_SYNCED)?"Out-of-sync ":"", (UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_SPARE)?"Spare ":"", (UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_BAD_DISK)?"Bad disk ":"", (UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_BAD_SECTOR)?"Bad sector ":"", (UnitMeta->UnitDeviceStatus & NDAS_UNIT_META_BIND_STATUS_REPLACED_BY_SPARE)?"Replaced by spare ":"" ); } // // Dump bitmap // if (DIB_V2.iMediaType == NMT_RAID1R3) { UINT32 BitCount = (UINT32)((DIB_V2.sizeUserSpace + DIB_V2.iSectorsPerBit - 1)/DIB_V2.iSectorsPerBit); UINT32 BmpSectorCount = (BitCount + NDAS_BIT_PER_OOS_BITMAP_BLOCK -1)/NDAS_BIT_PER_OOS_BITMAP_BLOCK; UINT32 CurBitCount; PNDAS_OOS_BITMAP_BLOCK BmpBuffer; UCHAR OnBits[] = {1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7}; UINT32 BitOn, BitOnStart, BitOnEnd; printf("\nBitmap sector per bit=0x%x, Bit count =0x%x, BmpSector count=0x%x\n", DIB_V2.iSectorsPerBit, BitCount, BmpSectorCount); BmpBuffer = (PNDAS_OOS_BITMAP_BLOCK) malloc(BmpSectorCount* 512); iResult = IdeCommand(connsock, iTargetID, 0, WIN_READ, DiskSectorCount + NDAS_BLOCK_LOCATION_BITMAP, (_int16)BmpSectorCount, 0, BmpSectorCount* 512, (PCHAR)BmpBuffer, 0, 0); if (iResult != 0) { fprintf(stderr, "READ Failed.\n"); free(BmpBuffer); goto errout; } CurBitCount = 0; for(i=0;i<BmpSectorCount;i++) { printf(" Bitmap sector %d, Seq head=%I64x, tail=%I64x\n", i, BmpBuffer[i].SequenceNumHead,BmpBuffer[i].SequenceNumTail); BitOn = FALSE; BitOnStart = BitOnEnd = 0; for(j=0;j<NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8;j++) { if (BitOn == FALSE && (BmpBuffer[i].Bits[j/8] & OnBits[j%8])) { BitOn = TRUE; BitOnStart = i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j; printf(" Bit on from bit %x ~ ", BitOnStart); } if (BitOn == TRUE && (BmpBuffer[i].Bits[j/8] & OnBits[j%8]) == 0) { BitOn = FALSE; BitOnEnd = i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j; printf("%x\n", BitOnEnd-1); } CurBitCount++; if (CurBitCount >= BitCount) break; } if (BitOn == TRUE) { printf("%x\n", i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j); } } free(BmpBuffer); } printf("\n"); DisconnectFromNdas(connsock, UserId); errout: closesocket(connsock); if (data) free(data); return retval; }
/********************************************************************************************************* ** 函数名称: GetDirClusIndex ** 功能描述: 获取指定目录开始簇号 ** ** 输 入: Path:路径名 ** ** 输 出: 开始簇号,EMPTY_CLUS:为根目录 ** ** 全局变量: 无 ** 调用模块: strupr,GetDiskInfo,FindFDTInfo ********************************************************************************************************/ acoral_u32 GetDirClusIndex(acoral_char *Path) { acoral_char DirName[12]; acoral_u8 Drive; acoral_u32 Rt; FDT temp; Disk_Info *Disk; Rt = BAD_CLUS; if (Path != NULL) { strupr(Path); /* 变为大写 */ Drive = GetDrive(Path); /* 获取路基盘符 */ if (Path[1] == ':') { Path += 2; } Disk = GetDiskInfo(Drive); /* 获取逻辑盘信息 */ if (Disk != NULL) { Rt = 0; if (Disk->FATType == FAT32) /* FAT32 根目录 */ { Rt = Disk->RootDirTable; } if (Path[0] != '\\' || Path[0] != '/') /* 不是目录分隔符号,表明起点是当前路径 */ { Rt = Disk->PathClusIndex; } else { Path++; } if (Path[0] == '.') /* '\.'表明起点是当前路径 */ { Rt = Disk->PathClusIndex; if (Path[1] == 0 || Path[1] == '\\' || Path[1] == '/') { Path++; } } if (Path[0] == '\\' || Path[0] == '/') { Path++; } DirName[11] = 0; while (Path[0] != 0) { /* 获取子目录名 */ StrToFDTName(DirName , Path); /* 子目录名开始簇号 */ if (DirName[0] == 0x20) { Rt = BAD_CLUS; break; } /* 获取FDT信息 */ if (FindFDTInfo(&temp, Drive, Rt, DirName) != RETURN_OK) { Rt = BAD_CLUS; break; } /* FDT是否是目录 */ if ((temp.Attr & ATTR_DIRECTORY) == 0) { Rt = BAD_CLUS; break; } Rt = temp.FstClusLO + ((acoral_u32)(temp.FstClusHI) << 16); /* 字符串到下一个目录 */ while (1) { if (*Path == '\\' || *Path == '/') { Path++; break; } if (*Path == 0) { break; } Path++; } } } if (Disk->FATType == FAT32) if (Rt != BAD_CLUS) if (Rt == Disk->RootDirTable) { Rt = 0; } } return Rt; }
/////////////////////////////////////////////////////////////////////////////// // SMC_IOControl - the I/O control entry point for the memory driver // Input: Handle - the context returned from SMC_Open // IoctlCode - the ioctl code // pInBuf - the input buffer from the user // InBufSize - the length of the input buffer // pOutBuf - the output buffer from the user // InBufSize - the length of the output buffer // pBytesReturned - the size of the transfer // Output: // Return: TRUE if ioctl was handled // Notes: /////////////////////////////////////////////////////////////////////////////// extern "C" BOOL WINAPI SMC_IOControl( DWORD Handle, DWORD IoctlCode, PBYTE pInBuf, DWORD InBufSize, PBYTE pOutBuf, DWORD OutBufSize, PDWORD pBytesReturned ) { DWORD Status = ERROR_SUCCESS; // win32 status PSD_MEMCARD_INFO pHandle = (PSD_MEMCARD_INFO)Handle; // memcard info PSG_REQ pSG; // scatter gather buffer SD_API_STATUS sdStatus; // SD API status DWORD SafeBytesReturned = 0; // safe copy of pBytesReturned DWORD dwStartTicks = 0; DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: +SMC_IOControl\r\n"))); // any of these IOCTLs can access the device instance or card handle so we // must protect it from being freed from XXX_Deinit; Windows CE does not // synchronize the callback from Deinit AcquireRemovalLock(pHandle); if (pHandle->fPreDeinitCalled) { Status = ERROR_INVALID_HANDLE; goto ErrorStatusReturn; } sdStatus = RequestPrologue(pHandle, IoctlCode); if (!SD_API_SUCCESS(sdStatus)) { ReleaseRemovalLock(pHandle); SetLastError(SDAPIStatusToErrorCode(sdStatus)); return FALSE; } DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("SMC_IOControl: Recevied IOCTL %d ="), IoctlCode)); switch(IoctlCode) { case IOCTL_DISK_READ: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_READ\r\n"))); break; case DISK_IOCTL_READ: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_READ\r\n"))); break; case IOCTL_DISK_WRITE: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_WRITE\r\n"))); break; case DISK_IOCTL_WRITE: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_WRITE\r\n"))); break; case IOCTL_DISK_GETINFO: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_GETINFO\r\n"))); break; case DISK_IOCTL_GETINFO: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_GETINFO\r\n"))); break; case IOCTL_DISK_SETINFO: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_SETINFO\r\n"))); break; case DISK_IOCTL_INITIALIZED: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_INITIALIZED\r\n"))); break; case IOCTL_DISK_INITIALIZED: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_INITIALIZED\r\n"))); break; case IOCTL_DISK_GETNAME: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_GETNAME\r\n"))); break; case DISK_IOCTL_GETNAME: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_GETNAME\r\n"))); break; case IOCTL_DISK_GET_STORAGEID: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_GET_STORAGEID\r\n"))); break; case IOCTL_DISK_FORMAT_MEDIA: case DISK_IOCTL_FORMAT_MEDIA: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_FORMAT_MEDIA\r\n"))); break; case IOCTL_DISK_DEVICE_INFO: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_DEVICE_INFO\r\n"))); break; case IOCTL_DISK_DELETE_SECTORS: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_DELETE_SECTORS\r\n"))); break; default: DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("**UNKNOWN**\r\n"))); break; } // validate parameters switch(IoctlCode) { case IOCTL_DISK_READ: case DISK_IOCTL_READ: case IOCTL_DISK_WRITE: case DISK_IOCTL_WRITE: if (pInBuf == NULL || InBufSize < sizeof(SG_REQ) || InBufSize > (sizeof(SG_REQ) + ((MAX_SG_BUF - 1) * sizeof(SG_BUF)))) { Status = ERROR_INVALID_PARAMETER; } break; case DISK_IOCTL_GETINFO: case IOCTL_DISK_SETINFO: if (NULL == pInBuf || InBufSize != sizeof(DISK_INFO)) { Status = ERROR_INVALID_PARAMETER; } break; case IOCTL_DISK_DELETE_SECTORS: if (pInBuf == NULL || InBufSize != sizeof(DELETE_SECTOR_INFO)) { Status = ERROR_INVALID_PARAMETER; } break; case IOCTL_DISK_GETINFO: if (pOutBuf == NULL || OutBufSize != sizeof(DISK_INFO)) { Status = ERROR_INVALID_PARAMETER; } break; case IOCTL_DISK_GET_STORAGEID: // the identification data is stored after the struct, so the out // buffer must be at least the size of the struct. if (pOutBuf == NULL || OutBufSize < sizeof(STORAGE_IDENTIFICATION)) { Status = ERROR_INVALID_PARAMETER; } break; case IOCTL_DISK_FORMAT_MEDIA: case DISK_IOCTL_FORMAT_MEDIA: break; case IOCTL_DISK_DEVICE_INFO: if (NULL == pInBuf || (InBufSize != sizeof(STORAGEDEVICEINFO))) { Status = ERROR_INVALID_PARAMETER; } break; case IOCTL_POWER_CAPABILITIES: if (!pOutBuf || OutBufSize < sizeof(POWER_CAPABILITIES) || !pBytesReturned) { Status = ERROR_INVALID_PARAMETER; } break; case IOCTL_POWER_SET: if (!pOutBuf || OutBufSize < sizeof(CEDEVICE_POWER_STATE) || !pBytesReturned) { Status = ERROR_INVALID_PARAMETER; } break; default: Status = ERROR_INVALID_PARAMETER; } if (Status != ERROR_SUCCESS) { goto ErrorStatusReturn; } // execute the IOCTL switch(IoctlCode) { case IOCTL_DISK_READ: case DISK_IOCTL_READ: pSG = (PSG_REQ)pInBuf; if (0 == CeSafeCopyMemory((LPVOID)pHandle->pSterileIoRequest, (LPVOID)pSG, InBufSize)) { Status = ERROR_INVALID_PARAMETER; break; } Status = SDMemRead(pHandle, pHandle->pSterileIoRequest); __try { pSG->sr_status = Status; if (pBytesReturned && (ERROR_SUCCESS == Status)) { *pBytesReturned = (pHandle->pSterileIoRequest->sr_num_sec * SD_BLOCK_SIZE); } } __except(EXCEPTION_EXECUTE_HANDLER) { Status = ERROR_INVALID_PARAMETER; } break; case IOCTL_DISK_WRITE: case DISK_IOCTL_WRITE: pSG = (PSG_REQ)pInBuf; if (0 == CeSafeCopyMemory((LPVOID)pHandle->pSterileIoRequest, (LPVOID)pSG, InBufSize)) { Status = ERROR_INVALID_PARAMETER; break; } Status = SDMemWrite(pHandle, pHandle->pSterileIoRequest); __try { pSG->sr_status = Status; if (pBytesReturned && (ERROR_SUCCESS == Status)) { *pBytesReturned = (pHandle->pSterileIoRequest->sr_num_sec * SD_BLOCK_SIZE); } } __except(EXCEPTION_EXECUTE_HANDLER) { Status = ERROR_INVALID_PARAMETER; } break; case IOCTL_DISK_GETINFO: { DISK_INFO SafeDiskInfo = {0}; SafeBytesReturned = sizeof(DISK_INFO); Status = GetDiskInfo(pHandle, &SafeDiskInfo); if (0 == CeSafeCopyMemory((LPVOID)pOutBuf, (LPVOID)&SafeDiskInfo, sizeof(DISK_INFO))) { Status = ERROR_INVALID_PARAMETER; break; } if (pBytesReturned) { if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) { Status = ERROR_INVALID_PARAMETER; break; } } } break; case DISK_IOCTL_GETINFO: { DISK_INFO SafeDiskInfo = {0}; SafeBytesReturned = sizeof(DISK_INFO); Status = GetDiskInfo(pHandle, &SafeDiskInfo); if (0 == CeSafeCopyMemory((LPVOID)pInBuf, (LPVOID)&SafeDiskInfo, sizeof(DISK_INFO))) { Status = ERROR_INVALID_PARAMETER; break; } if (pBytesReturned) { if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) { Status = ERROR_INVALID_PARAMETER; break; } } } break; case IOCTL_DISK_SETINFO: { DISK_INFO SafeDiskInfo = {0}; if (0 == CeSafeCopyMemory((LPVOID)&SafeDiskInfo, (LPVOID)pInBuf, sizeof(DISK_INFO))) { Status = ERROR_INVALID_PARAMETER; break; } Status = SetDiskInfo(pHandle, &SafeDiskInfo); } break; case IOCTL_DISK_FORMAT_MEDIA: case DISK_IOCTL_FORMAT_MEDIA: Status = ERROR_SUCCESS; break; case IOCTL_DISK_GET_STORAGEID: { __try { Status = GetStorageID( pHandle, (PSTORAGE_IDENTIFICATION)pOutBuf, OutBufSize, pBytesReturned); } __except(EXCEPTION_EXECUTE_HANDLER) { Status = ERROR_INVALID_PARAMETER; } } break; case IOCTL_DISK_DEVICE_INFO: { STORAGEDEVICEINFO SafeStorageDeviceInfo = {0}; SafeBytesReturned = sizeof(STORAGEDEVICEINFO); if (!GetDeviceInfo(pHandle, &SafeStorageDeviceInfo)) { Status = ERROR_GEN_FAILURE; break; } if (0 == CeSafeCopyMemory((LPVOID)pInBuf, (LPVOID)&SafeStorageDeviceInfo, sizeof(STORAGEDEVICEINFO))) { Status = ERROR_INVALID_PARAMETER; break; } Status = ERROR_SUCCESS; if (pBytesReturned) { if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) { Status = ERROR_INVALID_PARAMETER; } } } break; case IOCTL_DISK_DELETE_SECTORS: { DELETE_SECTOR_INFO SafeDeleteSectorInfo = {0}; if (0 == CeSafeCopyMemory((LPVOID)&SafeDeleteSectorInfo, (LPVOID)pInBuf, sizeof(DELETE_SECTOR_INFO))) { Status = ERROR_INVALID_PARAMETER; break; } Status = SDMemErase(pHandle, &SafeDeleteSectorInfo); } break; case IOCTL_POWER_CAPABILITIES: { POWER_CAPABILITIES SafePowerCapabilities = {0}; SafeBytesReturned = sizeof(POWER_CAPABILITIES); // support D0 + PowerStateForIdle (D2, by default) SafePowerCapabilities.DeviceDx = DX_MASK(D0) | DX_MASK(pHandle->PowerStateForIdle); SafePowerCapabilities.Power[D0] = PwrDeviceUnspecified; SafePowerCapabilities.Power[D1] = PwrDeviceUnspecified; SafePowerCapabilities.Power[D2] = PwrDeviceUnspecified; SafePowerCapabilities.Power[D3] = PwrDeviceUnspecified; SafePowerCapabilities.Power[D4] = PwrDeviceUnspecified; SafePowerCapabilities.Latency[D0] = 0; SafePowerCapabilities.Latency[D1] = 0; SafePowerCapabilities.Latency[D2] = 0; SafePowerCapabilities.Latency[D3] = 0; SafePowerCapabilities.Latency[D4] = 1000; // no device wake SafePowerCapabilities.WakeFromDx = 0; // no inrush SafePowerCapabilities.InrushDx = 0; if (0 == CeSafeCopyMemory((LPVOID)pOutBuf, (LPVOID)&SafePowerCapabilities, sizeof(POWER_CAPABILITIES))) { Status = ERROR_INVALID_PARAMETER; break; } Status = ERROR_SUCCESS; if (pBytesReturned) { if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) { Status = ERROR_INVALID_PARAMETER; } } } break; case IOCTL_POWER_SET: { // pOutBuf is a pointer to CEDEVICE_POWER_STATE; this is the device // state incd .. which to put the device; if the driver does not support // the requested power state, then we return the adjusted power // state CEDEVICE_POWER_STATE SafeCeDevicePowerState; SafeBytesReturned = sizeof(CEDEVICE_POWER_STATE); if (0 == CeSafeCopyMemory((LPVOID)&SafeCeDevicePowerState, (LPVOID)pOutBuf, sizeof(CEDEVICE_POWER_STATE))) { Status = ERROR_INVALID_PARAMETER; break; } Status = ERROR_SUCCESS; HandleIoctlPowerSet(pHandle, &SafeCeDevicePowerState); // return the adjusted power state if (0 == CeSafeCopyMemory((LPVOID)pOutBuf, (LPVOID)&SafeCeDevicePowerState, sizeof(CEDEVICE_POWER_STATE))) { Status = ERROR_INVALID_PARAMETER; break; } if (pBytesReturned) { if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) { Status = ERROR_INVALID_PARAMETER; } } } break; default: Status = ERROR_INVALID_PARAMETER; break; } RequestEnd(pHandle); ErrorStatusReturn: ReleaseRemovalLock(pHandle); DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: -SMC_IOControl returning %d\n"),Status == ERROR_SUCCESS)); if (Status != ERROR_SUCCESS) { SetLastError(Status); } return (ERROR_SUCCESS == Status); }
BOOL NDAS_GetStatus(UNIT_DISK_LOCATION *pUnitDisk, PNDAS_STATUS pStatus) { BOOL bReturn = FALSE; IDE_COMMAND_IO cmd[2]; LONG lResult; HKEY hKeyNetDisks; HKEY hKey; UINT i; CHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name DWORD cbName; // size of name string FILETIME ftLastWriteTime; // last write time CHAR szAddress[MAX_VALUE_NAME], szAddress2[18]; UCHAR szSerial[MAX_VALUE_NAME]; DWORD dwType; DWORD dwSize; LPX_ADDRESS address; LANSCSI_PATH path; DISK_INFORMATION_BLOCK *pDiskInfoV1; DISK_INFORMATION_BLOCK_V2 *pDiskInfoV2; DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : %02X:%02X:%02X:%02X:%02X:%02X\n", (int)pUnitDisk->MACAddr[0], (int)pUnitDisk->MACAddr[1], (int)pUnitDisk->MACAddr[2], (int)pUnitDisk->MACAddr[3], (int)pUnitDisk->MACAddr[4], (int)pUnitDisk->MACAddr[5] )); ZeroMemory(&path, sizeof(LANSCSI_PATH)); CopyMemory(address.Node, pUnitDisk->MACAddr, 6); if(NULL == pStatus) goto out; ZeroMemory(pStatus, sizeof(NDAS_STATUS)); // Registry check start. // AING_TO_DO : use NDAS registry functions lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, KEY_NAME_NETDISKS, 0, KEY_READ, &hKeyNetDisks ); if(ERROR_SUCCESS != lResult) goto out; sprintf(szAddress2, "%02x:%02x:%02x:%02x:%02x:%02x", pUnitDisk->MACAddr[0], pUnitDisk->MACAddr[1], pUnitDisk->MACAddr[2], pUnitDisk->MACAddr[3], pUnitDisk->MACAddr[4], pUnitDisk->MACAddr[5]); i = 0; while(1) { cbName = MAX_KEY_LENGTH; lResult = RegEnumKeyEx( hKeyNetDisks, i++, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime); if(ERROR_SUCCESS != lResult) goto out; lResult = RegOpenKeyEx( hKeyNetDisks, achKey, 0, KEY_READ, &hKey ); if(ERROR_SUCCESS != lResult) goto out; dwSize = MAX_VALUE_NAME; lResult = RegQueryValueEx( hKey, "Address", 0, &dwType, szAddress, &dwSize); if(ERROR_SUCCESS != lResult) continue; if(stricmp(szAddress, szAddress2)) continue; pStatus->IsRegistered = 1; dwSize = MAX_VALUE_NAME; lResult = RegQueryValueEx( hKey, "SerialKey", 0, &dwType, szSerial, &dwSize); DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : lResult = %d szSerial = %x %x %x %x %x %x %x %x %x, %d\n", lResult, (int)szSerial[0], (int)szSerial[1], (int)szSerial[2], (int)szSerial[3], (int)szSerial[4], (int)szSerial[5], (int)szSerial[6], (int)szSerial[7], (int)szSerial[8], (szSerial[8] == 0xff) )); if(ERROR_SUCCESS == lResult && szSerial[8] == 0xff) { pStatus->IsRegisteredWritable = 1; } break; } // Registry check end. // Connect if(!MakeConnection(&address, &path) || (unsigned int)NULL == path.connsock) { DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : MakeConnection Failed\n")); goto out; } pStatus->IsAlive = 1; // Login // if we don't write, login read only path.iUserID = (pUnitDisk->SlotNumber +1); path.iCommandTag = 0; path.HPID = 0; path.iHeaderEncryptAlgo = 0; path.iDataEncryptAlgo = 0; NDAS_SetPassword(address.Node, &path.iPassword); path.iSessionPhase = LOGOUT_PHASE; if(Login(&path, LOGIN_TYPE_NORMAL)) { DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : Login Failed\n")); goto out; } if(GetDiskInfo(&path, pUnitDisk->SlotNumber)) { DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : GetDiskInfo Failed\n")); goto out; } if(Logout(&path)) { DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : Logout Failed\n")); goto out; } if(0 != Discovery(&path)) { DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : Discovery Failed\n")); goto out; } closesocket(path.connsock); pStatus->IsDiscovered = 1; pStatus->HWVersion = path.HWVersion; pStatus->HWProtoVersion = path.HWProtoVersion; pStatus->NrUserReadWrite = path.PerTarget[pUnitDisk->SlotNumber].NRRWHost; pStatus->NrUserReadOnly = path.PerTarget[pUnitDisk->SlotNumber].NRROHost; if(MEDIA_TYPE_BLOCK_DEVICE != path.PerTarget[pUnitDisk->SlotNumber].MediaType) { switch(path.PerTarget[pUnitDisk->SlotNumber].MediaType) { case MEDIA_TYPE_CDROM_DEVICE: pStatus->DiskType = DISK_TYPE_DVD; pStatus->IsSupported = 1; break; case MEDIA_TYPE_OPMEM_DEVICE: pStatus->DiskType = DISK_TYPE_MO; pStatus->IsSupported = 1; break; default: pStatus->IsSupported = 0; } DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : Packet type %d\n", path.PerTarget[pUnitDisk->SlotNumber].MediaType)); bReturn = TRUE; goto out; } cmd[0].command = WIN_READ; cmd[0].iSector = -1; pDiskInfoV1 = (PDISK_INFORMATION_BLOCK)cmd[0].data; cmd[1].command = WIN_READ; cmd[1].iSector = -2; pDiskInfoV2 = (PDISK_INFORMATION_BLOCK_V2)cmd[1].data; NDAS_IdeIO(pUnitDisk, 2, cmd, NULL); if(DISK_INFORMATION_SIGNATURE_V2 == pDiskInfoV2->Signature) { pStatus->MajorVersion = pDiskInfoV2->MajorVersion; pStatus->MinorVersion = pDiskInfoV2->MinorVersion; if(IS_NDAS_DIB_V2_VERSION_HIGH(*pDiskInfoV2)) goto out; pStatus->IsSupported = 1; pStatus->DiskType = (1 == pDiskInfoV2->nDiskCount) ? DISK_TYPE_NORMAL : (NMT_RAID1 == pDiskInfoV2->iMediaType) ? DISK_TYPE_BIND_RAID1 : (NMT_VDVD == pDiskInfoV2->iMediaType) ? DISK_TYPE_VDVD : DISK_TYPE_AGGREGATION; } else if(DISK_INFORMATION_SIGNATURE == pDiskInfoV1->Signature) { pStatus->MajorVersion = pDiskInfoV1->MajorVersion; pStatus->MinorVersion = pDiskInfoV1->MinorVersion; if(IS_WRONG_VERSION(*pDiskInfoV1)) goto out; pStatus->IsSupported = 1; pStatus->DiskType = (UNITDISK_TYPE_SINGLE == pDiskInfoV1->DiskType) ? DISK_TYPE_NORMAL : (UNITDISK_TYPE_AGGREGATION_FIRST == pDiskInfoV1->DiskType) ? DISK_TYPE_AGGREGATION : (UNITDISK_TYPE_AGGREGATION_SECOND == pDiskInfoV1->DiskType) ? DISK_TYPE_AGGREGATION : (UNITDISK_TYPE_AGGREGATION_THIRD == pDiskInfoV1->DiskType) ? DISK_TYPE_AGGREGATION : (UNITDISK_TYPE_AGGREGATION_FOURTH == pDiskInfoV1->DiskType) ? DISK_TYPE_AGGREGATION : (UNITDISK_TYPE_MIRROR_MASTER == pDiskInfoV1->DiskType) ? DISK_TYPE_BIND_RAID1 : (UNITDISK_TYPE_MIRROR_SLAVE == pDiskInfoV1->DiskType) ? DISK_TYPE_BIND_RAID1 : (UNITDISK_TYPE_VDVD == pDiskInfoV1->DiskType) ? DISK_TYPE_VDVD : 0; } else { pStatus->MajorVersion = 0; pStatus->MinorVersion = 0; pStatus->DiskType = DISK_TYPE_NORMAL; pStatus->IsSupported = 1; } bReturn = TRUE; out: if(path.connsock) closesocket(path.connsock); return bReturn; }
BOOL NDAS_SetBitmap(UNIT_DISK_LOCATION *pUnitDisk, UINT nCommand, IDE_COMMAND_IO *aCommands, LANSCSI_PATH *pPath) { BOOL bReturn = FALSE; LANSCSI_PATH path; LPX_ADDRESS address; IDE_COMMAND_IO *pCommand = NULL; unsigned _int8 response; int iResult; unsigned int i; ZeroMemory(&path, sizeof(LANSCSI_PATH)); CopyMemory(address.Node, pUnitDisk->MACAddr, 6); // Connect if(!MakeConnection(&address, &path) || (unsigned int)NULL == path.connsock) { goto out; } // Login path.iUserID = (pUnitDisk->SlotNumber +1) | (pUnitDisk->SlotNumber +1) << 16; path.iCommandTag = 0; path.HPID = 0; path.iHeaderEncryptAlgo = 0; path.iDataEncryptAlgo = 0; NDAS_SetPassword(address.Node, &path.iPassword); path.iSessionPhase = LOGOUT_PHASE; if(Login(&path, LOGIN_TYPE_NORMAL)) goto out; if(GetDiskInfo(&path, pUnitDisk->SlotNumber)) goto out; if(NULL != pPath) { CopyMemory(pPath, &path, sizeof(LANSCSI_PATH)); } for(i = 0; i < nCommand; i++) { pCommand = &aCommands[i]; iResult = IdeCommand( &path, pUnitDisk->SlotNumber, 0, pCommand->command, (pCommand->iSector < 0) ? path.PerTarget[pUnitDisk->SlotNumber].SectorCount + pCommand->iSector : pCommand->iSector, 1, 0, pCommand->data, &response); if(iResult || LANSCSI_RESPONSE_SUCCESS != response) goto out; } bReturn = TRUE; out: if(path.connsock) { if(LOGOUT_PHASE != path.iSessionPhase) { Logout(&path); } closesocket(path.connsock); path.connsock = (UINT)NULL; } return bReturn; }
BOOL NDAS_IdeIO(UNIT_DISK_LOCATION *pUnitDisk, UINT nCommand, IDE_COMMAND_IO *aCommands, LANSCSI_PATH *pPath) { BOOL bReturn = FALSE; LANSCSI_PATH path; LPX_ADDRESS address; IDE_COMMAND_IO *pCommand = NULL; _int8 data[512]; unsigned _int8 response; int iResult; unsigned int i; ZeroMemory(&path, sizeof(LANSCSI_PATH)); CopyMemory(address.Node, pUnitDisk->MACAddr, 6); // Connect if(!MakeConnection(&address, &path) || (unsigned int)NULL == path.connsock) { DebugPrint(1, ("[NDASOpLib] NDAS_IdeIO : MakeConnection Failed\n")); goto out; } // Login // if we don't write, login read only path.iUserID = (pUnitDisk->SlotNumber +1); for(i = 0; i < nCommand; i++) { if(WIN_WRITE == aCommands[i].command) { path.iUserID = (pUnitDisk->SlotNumber +1) | (pUnitDisk->SlotNumber +1) << 16; break; } } path.iCommandTag = 0; path.HPID = 0; path.iHeaderEncryptAlgo = 0; path.iDataEncryptAlgo = 0; NDAS_SetPassword(address.Node, &path.iPassword); path.iSessionPhase = LOGOUT_PHASE; if(Login(&path, LOGIN_TYPE_NORMAL)) { DebugPrint(1, ("[NDASOpLib] NDAS_IdeIO : Login Failed\n")); goto out; } if(GetDiskInfo(&path, pUnitDisk->SlotNumber)) { DebugPrint(1, ("[NDASOpLib] NDAS_IdeIO : GetDiskInfo Failed\n")); goto out; } if(NULL != pPath) { CopyMemory(pPath, &path, sizeof(LANSCSI_PATH)); } for(i = 0; i < nCommand; i++) { pCommand = &aCommands[i]; iResult = IdeCommand( &path, pUnitDisk->SlotNumber, 0, pCommand->command, (pCommand->iSector < 0) ? path.PerTarget[pUnitDisk->SlotNumber].SectorCount + pCommand->iSector : pCommand->iSector, 1, 0, (WIN_WRITE == pCommand->command) ? CopyMemory(data, pCommand->data, sizeof(pCommand->data)), data: pCommand->data, &response); if(iResult || LANSCSI_RESPONSE_SUCCESS != response) { DebugPrint(1, ("[NDASOpLib] NDAS_IdeIO : IdeCommand cmd : %d, #%d\n", pCommand->command, i)); goto out; } } bReturn = TRUE; out: if(path.connsock) { if(LOGOUT_PHASE != path.iSessionPhase) { Logout(&path); } closesocket(path.connsock); path.connsock = (UINT)NULL; } return bReturn; }
FS_i32 FS_FileCpy(const TCHAR*path1, const TCHAR*path2) //path1: souce file path2: destination file { FS_FILE *src; FS_FILE * dst; FS_i32 read_size,write_size; FS_i32 src_size, dst_size; struct stat buf; _DISK_INFO info; FS_i8 *buffer; if( !strcmp((const char *)path1, (const char *)path2) ) { FS_Debug("FSW_ERROR:can not copy a file to itself\r\n"); return 0; } if( -1 == FS_Stat( path1, &buf ) ) return 0; src_size = buf.st_size; if(GetDiskInfo(path2,&info)==-1) { FS_Debug("FSW_ERROR:getdiskinfo err\r\n"); return 0; } if(src_size > info.free_size) { FS_Debug("there is no enough space on the flash!\n\r"); return 0; } src = FS_FOpen(path1, FA_READ|FA_OPEN_EXISTING); if(0 == src) { FS_Debug("FSW_ERROR:cannot open the source file\r\n"); return 0; } dst = FS_FOpen(path2, FA_CREATE_ALWAYS|FA_WRITE); if(0 == dst) { FS_Debug("FSW_ERROR:cannot create the distance file\r\n"); FS_FClose(src); return 0; } buffer=Q_Mallco(COPY_FILE_BUFFER); do{ read_size = FS_FRead(buffer, COPY_FILE_BUFFER,1,src); write_size = FS_FWrite(buffer, read_size,1,dst); if(write_size < read_size) { FS_Debug("FSW_ERROR:file write error\r\n"); Q_Free(buffer); goto CP_FILE_ERROR; } }while(read_size == COPY_FILE_BUFFER); Q_Free(buffer); FS_FClose(src); FS_FClose(dst); if( -1 == FS_Stat( path2, &buf ) ) return 0; dst_size = buf.st_size; if(dst_size < src_size) { FS_Debug("there is an unkown flash operation during the copyfile!\n\r"); FS_Unlink(path2); return 0; } return 1; CP_FILE_ERROR: FS_FClose(src); FS_FClose(dst); return 0; }
BOOL CNdasDeviceComm::GetUnitDeviceInformation(PNDAS_UNITDEVICE_INFORMATION pUnitDevInfo) { _ASSERTE(m_bInitialized && "CNdasDeviceComm is not initialized"); _ASSERTE(pUnitDevInfo != NULL); INT iResult = GetDiskInfo(&m_lspath, m_dwUnitNo); if (0 != iResult) { // TODO: LANDISK_ERROR_BADKEY? DPError(_FT("GetDiskInfo failed with error %d\n"), iResult); return FALSE; } PTARGET_DATA pTargetData = &m_lspath.PerTarget[m_dwUnitNo]; pUnitDevInfo->bLBA = pTargetData->bLBA; pUnitDevInfo->bLBA48 = pTargetData->bLBA48; pUnitDevInfo->bPIO = pTargetData->bPIO; pUnitDevInfo->bDMA = pTargetData->bDma; pUnitDevInfo->bUDMA = pTargetData->bUDma; pUnitDevInfo->MediaType = pTargetData->MediaType; pUnitDevInfo->dwROHosts = pTargetData->NRROHost; pUnitDevInfo->dwRWHosts = pTargetData->NRRWHost; pUnitDevInfo->SectorCount = pTargetData->SectorCount; #ifdef UNICODE // // What if FwRev, Model, SerialNo is not null terminated? // -> solved by terminating null between fields _ASSERTE(sizeof(pUnitDevInfo->szModel) / sizeof(pUnitDevInfo->szModel[0]) == sizeof(pTargetData->Model)); _ASSERTE(sizeof(pUnitDevInfo->szSerialNo) / sizeof(pUnitDevInfo->szSerialNo[0]) == sizeof(pTargetData->SerialNo)); _ASSERTE(sizeof(pUnitDevInfo->szFwRev) / sizeof(pUnitDevInfo->szFwRev[0]) == sizeof(pTargetData->FwRev)); ::MultiByteToWideChar( CP_ACP, 0, pTargetData->Model, sizeof(pTargetData->Model), pUnitDevInfo->szModel, sizeof(pUnitDevInfo->szModel) / sizeof(pUnitDevInfo->szModel[0])); ::MultiByteToWideChar( CP_ACP, 0, pTargetData->SerialNo, sizeof(pTargetData->SerialNo), pUnitDevInfo->szSerialNo, sizeof(pUnitDevInfo->szSerialNo) / sizeof(pUnitDevInfo->szSerialNo[0])); ::MultiByteToWideChar( CP_ACP, 0, pTargetData->FwRev, sizeof(pTargetData->FwRev), pUnitDevInfo->szFwRev, sizeof(pUnitDevInfo->szFwRev) / sizeof(pUnitDevInfo->szFwRev[0])); #else _ASSERTE(sizeof(pUnitDevInfo->szModel) == sizeof(pTargetData->Model)); _ASSERTE(sizeof(pUnitDevInfo->szFwRev) == sizeof(pTargetData->FwRev)); _ASSERTE(sizeof(pUnitDevInfo->szSerialNo) == sizeof(pTargetData->SerialNo)); ::CopyMemory(pUnitDevInfo->szModel, pTargetData->Model, sizeof(pTargetData->Model)); ::CopyMemory(pUnitDevInfo->szFwRev, pTargetData->FwRev, sizeof(pTargetData->FwRev)); ::CopyMemory(pUnitDevInfo->szSerialNo, pTargetData->SerialNo, sizeof(pTargetData->SerialNo)); #endif DPInfo(_FT("Model : %s\n"), pUnitDevInfo->szModel); DPInfo(_FT("Serial No : %s\n"), pUnitDevInfo->szSerialNo); DPInfo(_FT("Firmware Rev : %s\n"), pUnitDevInfo->szFwRev); return TRUE; }