【问题标题】:PrepareTape fails in my c++ codePrepareTape 在我的 C++ 代码中失败
【发布时间】:2016-11-15 23:00:10
【问题描述】:

我用Firestreamer 创建了一个虚拟磁带库。我用 C++ 编写了一个将文件复制到该虚拟磁带的代码。但是当我尝试使用PrepareTape windows 功能准备磁带时,它失败了。下面是我调用 PrepareTape windows 函数的代码的一部分。

                /*Tape Handle*/
                LPCWSTR tapeName = L"\\\\.\\Tape1";
                HANDLE tapeHandle = CreateFile(tapeName,
                    /*GENERIC_READ | GENERIC_WRITE*/  GENERIC_ALL,
                    0,
                    0,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_ARCHIVE | FILE_FLAG_BACKUP_SEMANTICS,
                    0);
                if (tapeHandle == NULL)
                {
                    cout << "ERROR::Unable To Open  handle for the tape in this machine the error is ::" << GetLastError() << endl;
                }
                else
                {
                    wcout << "The Handle for the tape :" << tapeName << " is created successfully" << endl;
                }
                /*Prepare Tape*/
                DWORD prepareTApeSuccess = PrepareTape(
                    tapeHandle,
                    TAPE_LOAD,
                    TRUE
                    );

                if (prepareTApeSuccess == NO_ERROR)
                {
                    cout << "Prepare Tape successsfully executed" << endl;
                }
                else
                {
                    cout << "Prepare Tape Failed with the error :" << prepareTApeSuccess << endl;
                }
                if (!CloseHandle(tapeHandle))
                {
                    cout << "Close handle for the file is failed with thie error" << GetLastError() << endl;
                }

输出

The Handle for the tape :\\.\Tape1 is created successfully
Prepare Tape Failed with the error :1

但其余的,即其他磁带功能在相同的句柄下工作正常。我尝试使用 GetTapeStatus 函数获取磁带的状态。磁带设备已准备好接受适当的磁带访问命令而不返回错误,返回值为 NO_ERROR。

提前致谢

【问题讨论】:

    标签: c++ windows backup virtual


    【解决方案1】:

    在准备磁带函数中考虑第三个参数,如果该参数为TRUE,函数立即返回。如果为 FALSE,则函数在操作完成之前不会返回。我已将其更改为 false,我的问题已解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 2015-12-30
      • 2011-01-22
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      相关资源
      最近更新 更多