Beispiel #1
0
        public override StorApiStatus IsWriteCacheOn(ref bool on)
        {
            StorApiStatus storApiStatus = StorApiStatusEnum.STOR_NO_ERROR;
            byte          b             = 0;

            MvApi.MvApi.HD_Config_Request hd_Config_Request = default(MvApi.MvApi.HD_Config_Request);
            hd_Config_Request.header.Init();
            hd_Config_Request.header.requestType       = 2;
            hd_Config_Request.header.startingIndexOrId = this.mvid;
            hd_Config_Request.header.numRequested      = 1;
            lock (MarvellUtil.mvApiLock)
            {
                try
                {
                    b = MvApi.MvApi.MV_PD_GetConfig(((MarvellController)this.controller).AdapterId, ref hd_Config_Request);
                }
                catch (Exception ex)
                {
                    Logger.Warn("IsWriteCacheOn MV_PD_GetConfig exception: {0}", new object[]
                    {
                        ex
                    });
                    return(StorApiStatusEnum.STOR_API_ERROR);
                }
            }
            if (b == 0)
            {
                if (hd_Config_Request.header.numReturned != 1)
                {
                    b = 55;
                }
                else
                {
                    on = (hd_Config_Request.hdConfig[0].WriteCacheOn != 0);
                }
            }
            return(MarvellUtil.ToStorApiStatus(b));
        }
Beispiel #2
0
        public override StorApiStatus SetWriteCache(bool on)
        {
            StorApiStatus storApiStatus = StorApiStatusEnum.STOR_NO_ERROR;
            byte          b             = 0;

            MvApi.MvApi.HD_Config_Request hd_Config_Request = default(MvApi.MvApi.HD_Config_Request);
            hd_Config_Request.header.Init();
            hd_Config_Request.header.requestType       = 2;
            hd_Config_Request.header.startingIndexOrId = this.mvid;
            hd_Config_Request.header.numRequested      = 1;
            lock (MarvellUtil.mvApiLock)
            {
                try
                {
                    b = MvApi.MvApi.MV_PD_GetConfig(((MarvellController)this.controller).AdapterId, ref hd_Config_Request);
                }
                catch (Exception ex)
                {
                    Logger.Warn("SetWriteCache MV_PD_GetConfig exception: {0}", new object[]
                    {
                        ex
                    });
                    return(StorApiStatusEnum.STOR_API_ERROR);
                }
            }
            if (b == 0)
            {
                if (hd_Config_Request.header.numReturned != 1)
                {
                    b = 55;
                }
                else
                {
                    bool writeCacheOn = hd_Config_Request.hdConfig[0].WriteCacheOn != 0;
                    if (writeCacheOn != on)
                    {
                        hd_Config_Request.hdConfig[0].WriteCacheOn = (byte)((!on) ? 0 : 1);
                        IntPtr intPtr = StorHelper.AllocateIntPtr <MvApi.MvApi.HD_Config>(hd_Config_Request.hdConfig[0]);
                        if (intPtr != IntPtr.Zero)
                        {
                            lock (MarvellUtil.mvApiLock)
                            {
                                try
                                {
                                    b = MvApi.MvApi.MV_PD_SetConfig(((MarvellController)this.controller).AdapterId, this.mvid, intPtr);
                                }
                                catch (Exception ex2)
                                {
                                    StorHelper.FreeIntPtr(intPtr);
                                    Logger.Warn("MV_PD_SetConfig exception: {0}", new object[]
                                    {
                                        ex2
                                    });
                                    return(StorApiStatusEnum.STOR_API_ERROR);
                                }
                            }
                            StorHelper.FreeIntPtr(intPtr);
                        }
                    }
                }
            }
            return(MarvellUtil.ToStorApiStatus(b));
        }
        protected MarvellDrive MakeDrive(MvApi.MvApi.HD_Info hdInfo)
        {
            byte          b            = 0;
            StorApiStatus a            = StorApiStatusEnum.STOR_NO_ERROR;
            MarvellDrive  marvellDrive = new MarvellDrive(hdInfo.Link.Self.DevID, this);

            marvellDrive.Port           = this.GetDrivePort(hdInfo);
            marvellDrive.Model          = MarvellUtil.GetApiString(hdInfo.Model, 40);
            marvellDrive.Serial         = MarvellUtil.GetApiString(hdInfo.SerialNo, 20);
            marvellDrive.Revision       = MarvellUtil.GetApiString(hdInfo.FWVersion, 8);
            marvellDrive.SectorSize     = (ulong)((hdInfo.BlockSize == 0u) ? 512u : hdInfo.BlockSize);
            marvellDrive.SectorCount    = hdInfo.Size.ToUlong() * 1024UL / marvellDrive.SectorSize;
            marvellDrive.IsSmartEnabled = false;
            marvellDrive.IsSystem       = false;
            marvellDrive.Status         = DriveStatus.DRIVE_UNKNOWN;
            marvellDrive.Domain         = DriveDomain.DRIVE_DOMAIN_UNKNOWN;
            short[] id = new short[]
            {
                hdInfo.Link.Self.DevID
            };
            lock (MarvellUtil.mvApiLock)
            {
                try
                {
                    b = MvApi.MvApi.MV_DiskHasOS(this.AdapterId, 1, 1, id);
                }
                catch (Exception ex)
                {
                    Logger.Warn("MV_DiskHasOS exception: {0}", new object[]
                    {
                        ex
                    });
                    throw ex;
                }
            }
            if (b == 159)
            {
                marvellDrive.IsSystem = true;
            }
            MvApi.MvApi.HD_Config_Request hd_Config_Request = default(MvApi.MvApi.HD_Config_Request);
            hd_Config_Request.header.Init();
            hd_Config_Request.header.requestType       = 2;
            hd_Config_Request.header.startingIndexOrId = hdInfo.Link.Self.DevID;
            hd_Config_Request.header.numRequested      = 1;
            lock (MarvellUtil.mvApiLock)
            {
                try
                {
                    b = MvApi.MvApi.MV_PD_GetConfig(this.AdapterId, ref hd_Config_Request);
                }
                catch (Exception ex2)
                {
                    Logger.Warn("MV_PD_GetConfig exception: {0}", new object[]
                    {
                        ex2
                    });
                    throw ex2;
                }
            }
            marvellDrive.IsSmartEnabled = (hd_Config_Request.hdConfig[0].SMARTOn == 1);
            if (!marvellDrive.IsSmartEnabled)
            {
                a = marvellDrive.EnableSmart();
                if (a == StorApiStatusEnum.STOR_NO_ERROR)
                {
                    marvellDrive.IsSmartEnabled = true;
                }
            }
            return(marvellDrive);
        }