NTFS signature is missing - c++

I have loaded NTFS-3G from here: https://github.com/vitalif/ntfs-3g into a VS2017 project, wanting to read NTFS USB stick drive. And when I debugging reading process, I saw that is not reading USB drive due to:
// bootsect.c
BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR* b)
{
u32 i;
BOOL ret = FALSE;
ntfs_log_debug("Beginning bootsector check.\n");
ntfs_log_debug("Checking OEMid, NTFS signature.\n");
if (b->oem_id != const_cpu_to_le64(0x202020205346544eULL)) // "NTFS "
{
ntfs_log_error("NTFS signature is missing.\n"); // <-- my code is running here ...
goto not_ntfs;
}
...
...
I run it this code on Win10 64bit/VS2017. And my USB stick are valid, I have tried several USB stick (all of them NTFS).
I read that vitalif/ntfs-3g has a OS limitation: Windows XP, ... and Windows 7 file systems ... that is why I suspect the cause of my failing reading process ...
I have seek it on github for another NTFS-3G project that support Win10, I didn't found it ... is there anywhere another version of NTFS-3G library that work on Win10 ? Or, could another cause for my failing ?
Any support will be wellcome, I am struggle for this issue for days and days ...

Related

Find out if file path is mapped / remote or local

Is it possible to find out if a drive path (e.g. P:/temp/foo) is local or remote?
Here ( CMD line to tell if a file/path is local or remote? ) it's shown for a cmd evaluation, but I am looking for a C++/Qt way.
Related to:
QDir::exists with mapped remote directory
How to perform Cross-Platform Asynchronous File I/O in C++
There's no way in Qt, at least up to Qt 5.5. QStorageInfo would be the closest fit, but there is no agreement about how such an API should look like (see the gigantic discussion that started in this thread; basically one risks to have Qt reporting misleading information).
So, for now, you're up to using native APIs. The aforementioned GetDriveType would be fine for Windows, but you're pretty much on your own on Linux and Mac.
you could use the GetDriveType function:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364939(v=vs.85).aspx
I recently filed a feature request about this exact question: https://bugreports.qt.io/browse/QTBUG-83321
A possible workaround emerged there. Using the following enum:
enum DeviceType {
Physical,
Other,
Unknown
};
I could reliably check a mount to be a local device or something else (possibly a net mount) using the following function on Linux, Windows and macOS:
DeviceType deviceType(const QStorageInfo &volume) const
{
#ifdef Q_OS_LINUX
if (QString::fromLatin1(volume.device()).startsWith(QLatin1String("/"))) {
return DeviceType::Physical;
} else {
return DeviceType::Other;
}
#endif
#ifdef Q_OS_WIN
if (QString::fromLatin1(volume.device()).startsWith(QLatin1String("\\\\?\\Volume"))) {
return DeviceType::Physical;
} else {
return DeviceType::Other;
}
#endif
#ifdef Q_OS_MACOS
if (! QString::fromLatin1(volume.device()).startsWith(QLatin1String("//"))) {
return DeviceType::Physical;
} else {
return DeviceType::Other;
}
#endif
return DeviceType::Unknown;
}

Unable to connect to Microsoft Access Database (C++)

I've been going trough tons of articles and forums about this and I still have not found my solution. Even though there are several posts of this on this website aswell.
They state these things as answers:
Install this: http://www.microsoft.com/en-us/download/details.aspx?id=13255
I'm unable to install the x86 version, becouse I have office x64 2010. I did however installed the x64 version of that package.
Install this http://www.microsoft.com/en-us/download/details.aspx?id=23734
I've tried it, no results.
Make sure you application is targeted correctly (i.e. x86)
I'm 100% sure my application is 32 bit.
My work environment is as follows:
Visual Studio 2012 professional
Coding language is C++
Microsoft Office 2010
Windows 8 x64
This is the code that I'm using:
class Credential
{
public:
TCHAR CredentialID[3];
TCHAR CredentialName[255];
BEGIN_COLUMN_MAP(Credential)
COLUMN_ENTRY(1, CredentialID)
COLUMN_ENTRY(2, CredentialName)
END_COLUMN_MAP()
};
and this:
try
{
CDataSource ds;
CSession session;
ATL::CCommand<CAccessor<Credential>> cust;
HRESULT hr = CoInitialize(0);
if(FAILED(hr))
{
Console_Output("Can't start COM!?\n");
return;
}
hr = ds.OpenFromInitializationString(L"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=MPFDatabase.accdb;");
Console_Output("%d\n", hr);
if(FAILED(hr))
{
Console_Output("Can't open Nwind\n");
return;
}
hr = session.Open(ds);
if(FAILED(hr))
{
Console_Output("Can't open Nwind SESSION\n");
ds.Close();
return;
}
TCHAR mySQL[] = "SELECT * FROM Credential";
hr = cust.Open(session, mySQL);
if(FAILED(hr))
{
Console_Output("Can't open Nwind TABLE\n");
session.Close();
ds.Close();
return;
}
while(cust.MoveNext() == S_OK)
{
Console_Output("%s -- %s\n", cust.CredentialID, cust.CredentialName);
}
cust.Close();
session.Close();
ds.Close();
}
catch(std::exception &Ex)
{
Console_Output("ex: %s\n", Ex.what());
}
I get to the point where it calls ds.OpenFromInitializationString but then it either stops my application without any notification whatsoever (no exception too). Or I get to the point where it would print in my console "Can't open Nwind\n".
These 2 results depend on what I've installed of the suggested answers.
I've tried absolute and relative paths for my Data Source.
I'm 100% sure it is not locked or something similar. I've created the database myself and it consists of only 2 tables, nothing special.
If I list my providers in windows powershell I get these providers:
SQLOLEDB
MSQLAP
MSQLAP
MSDataShape
SQLNCLI11
Microsoft.ACE.OLEDB.12.0
ADsDSOObject
SQLNCLI11 Enumerator
Windows Search Data Source
MSDASQL
MSDASQL Enumerator
SQLOLEDB Enumerator
MSDAOSP
So the ace engine is indeed installed as you can see.
EDIT:
Forgot to mention that it is concerning a local accdb file made in ms access 2010 on my computer. In case that wasn't clear.
As Gord has said. . .
How do you have a 32 bit application running on a 64 bit machine? First thing is to try to get those in sync.
I had a similar problem with access (but the application type was setup properly for me and I was in c#) so I will mention the three things that had an affect relating to the compatability problem as we had the same error message.
Goto the properties tab under Build. Then change Platform Target from the default Any CPU to x64 or x86. For me this was not optional it must be set to the right one when I deployed, but it worked fine under any CPU when I was debugging locally.
I also had to install the AccessDataBaseEngine_x64 which it sounds like you have already.
The next thing to check is your connection string.
For me my local was x86 and my server was x64.
For me both of these two worked with some playing around on this Jet and ACE settings:
string connectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\your pathj\Database.accdb;";
string connectionString = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\your path\Database.accdb;Jet OLEDB:Database Password=password";
and I passed the connectionString instead of putting it into the field directly.
Hope this helps.
If you have the 64-bit version of the Access Database Engine -- a.k.a. "ACE" -- installed (as part of 64-bit Office 2010) and you are 100% sure that your application is running as 32-bit then I'm 100% sure that it won't work. 32-bit applications cannot use the 64-bit ACE driver, and 64-bit applications cannot use the 32-bit ACE driver. So, your choices are:
configure your application to run as 64-bit and use the existing 64-bit ACE driver, or
replace the 64-bit version of Office with the 32-bit version and run your application as 32-bit.

C++ - Can't open file from network path in Windows

I'm having problems using native C++ to open a file located on a network drive on a Windows box. My code works fine if the file is local, but fails if the file is on a network share. I can read the file from Windows explorer perfectly fine.
ifstream ifs(cFilename);
if(ifs.is_open())
{
// Read file here. (This never works for a network path)
}
I've also tried this:
struct stat sb;
if (stat(cFilename, &sb) == 0)
{
// Read file here. (This never works for a network path)
}
My path is formatted correctly (e.g. "\\server\filename.ext"), but I still can't open it. Any ideas?
If the name is in the form \\server\filename, then it seems that might not be correct. I believe that typically it needs a share name as well:
\\server\share\filename
Also, make sure that in the code, you escape the backslashes (e.g., \\\\server\\share\\filename).

64 bit windows file opening

I'm trying to use a dialog box to open a file in my program. This works perfectly on a 32 bit system, but when I try to use it on 64 bit it is unable to open the file. I've figured out that if the file trying to be opened is in the same directory as my program, it works fine. Trying to open a file from another folder, however, doesn't work at all.
So, I tried to copy the file to the program folder. This also works fine on 32 bit but doesn't work at all on a 64 system. Any thoughts why?
char cwdl[500];
getcwd(cwdl,500);
string mystring = string(cwdl);
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, "All Files (*.*)|*.*||", this);
fileDlg.m_ofn.lpstrTitle = "Select New File";
if( fileDlg.DoModal() == IDOK)
{
CString newFile= fileDlg.GetFileName();
mystring+="\\"+newFile;
const char * newLoc = mystring.c_str();
CopyFile(newFile,newLoc,true);
this is just a snippet of the code.
UAC and file system redirection are related yet different.
User account control is a permissions based security to prevent unauthorized users from changing your file system or executing applications which may affect other users. The prompt allows you to override the security by providing administrator privileges temporarily if that was your intent.
File system redirection is to allow backwards compatibility with 32bit applications by having a mirrored 32bit system folders and registry. In fact if the action causes UAC to kick in redirection does not occur it will always try to use the 64bit version of the file in that case. Unless you specify the redirection directory explicitly or run the 32bit application with administrator privileges to bypass UAC.
Ok that said you are using a relative path so it will look for the file in the current directory for the process. If it's compiled as 32 bit process running it on systems with different architectures may not behave as expected due to aforementioned redirection.
You can use GetCurrentDirectory windows API to see what directory the current process is using and verify it is what you expected. If not you have a few options.
The easiest would be to use fully qualified file paths.
You could also have two builds one targeted for each architecture you intend to deploy on. After all if you're on a 64bit system you might as well deploy 64bit applications.
A more involved option would be to subclass CFileDialog and disable redirection by calling Wow64DisableWow64FsRedirection in the constructor and Wow64RevertWow64FsRedirection in the desctructor. However this is meant to be a system setting so you may get new problems by forcing your 32bit application on 64bit windows.
There are probably plenty of other options as well since there is usually many ways to skin a cat. However the first step is to put some debug code in place and verify or eliminate redirection as a culprit with GetCurrentDirectory
Maybe it's just me, but I'm seeing a strange result: in 64-bit mode, the first four bytes of the buffer used to store the location of the path, are filled with zeros.
char wk[_MAX_PATH];
char *ret = _getcwd(wk, _MAX_PATH); // wk = "\0\0\0\0C:\\MyFolder\\..."
// ret = "C:\\MyFolder\\..."
The return value OTOH is correct. "ret" points to wk + 4;
In 32-bit mode, there are no leading zeros, the path starts at the first byte. Note: this is a Multi-byte app, not Unicode.
I'm using Visual Studio 2010 (10.0.40219.1 SP1Rel).
Anyway, if you're getting the same result, that would explain why your example doesn't work. You would have to say (in 64-bit mode only):
string mystring = string(cwdl + 4); // 64-bit only
Weird or What?
Edit: Seems to be an alignment problem. Works OK if the _getcwd is in a separate function.

How to set and read pins on the parallel port from C++?

I am helping a friend to finish a final year project in which he has this circuit that we want to switch on and off using a C++ program.
I initially thought it would be easy, but I have failed to implement this program.
The main problem is that
Windows XP and above don't allow direct access to hardware so some websites are suggesting that I need to write a driver or find a driver.
I have also looked at some projects online but they seem to work for Windows XP but fail to work for Windows 7.
Also, most projects were written in VB or C# which I am not familiar with.
Question:
Is there a suitable driver that works for Windows XP and Windows 7, and if yes how can I use it in my code? (code snippets would be appreciated)
Is there a cross platform way of dealing communicating with parallel ports?
Have a look at codeproject: here, here and here. You'll find treasures.
The 1st link works for Windows 7 - both 32 bit and 64 bit.
You shouldn't need to write a driver or anything -- you just call CreateFile with a filename like "LPT1" to open up a handle to the parallel port, and then you can use WriteFile to write data to it. For example:
HANDLE parallelPort = CreateFile("LPT1", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if(parallelPort == INVALID_HANDLE_VALUE)
{
// handle error
}
...
// Write the string "foobar" (and its null terminator) to the parallel port.
// Error checking omitted for expository purposes.
const char *data = "foobar";
WriteFile(parallelPort, data, strlen(data)+1, NULL, NULL);
...
CloseHandle(parallelPort);