CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: MSDN documentation unclear ?

  1. #1
    Join Date
    Jan 2009
    Posts
    336

    MSDN documentation unclear ?

    I am trying to read directories from an EXFAT USB drive. And for this task, I have found here a good documentation: https://docs.microsoft.com/en-us/win...-specification

    But seem that is unclear somehow, at least to me.

    I have successfully read - Main and Backup Boot Sector Structure Table (https://docs.microsoft.com/en-us/win...ctor-structure), value by value.

    And then, I have read - Cluster Heap Structure Table (https://docs.microsoft.com/en-us/win...heap-structure)


    Code:
    	const int nSize = dwSectorSize * 1 << nSectorsPerClusterShift;
    	const int nCount = nClusterCount + 1;
    	LONGLONG llPos = nClusterHeapOffset;
    	LONGLONG nLimit = nClusterHeapOffset + ((nClusterCount - 1) * nSize);
    
    	for (int i = 0; i < nCount; ++i)
    	{
    		file.Seek(llPos, CFile::begin);
    		arrByte.RemoveAll();
    		arrByte.SetSize(nSize);
    		UINT nRet = file.Read(arrByte.GetData(), arrByte.GetSize());
    
    		llPos += nSize;
    		if (llPos > nLimit)
    			break;
    	}
    and for every cluster from cluster heap, I retrieved a CByteArray of 32768 bytes. Fine by now. Now, there is another part: Directory Structure Table (https://docs.microsoft.com/en-us/win...tory-structure)

    Here I am stuck. I guess I can read the directory (or files) from this cluster, one by one. Theoretically, I should read every cluster from 32 to 32 bytes, according Directory Structure Table, which gave me 1024 (32768 / 32). But in this cluster, I don't know how to consider those bytes in order to have a directory (or file). More over, I don't know how to compute N (for DirectoryEntry[N1]).

    The documentation says: N, the number of DirectoryEntry fields, is the size, in bytes, of the cluster chain which contains the given directory, divided by the size of a DirectoryEntry field, 32 bytes.

    From documentation: A cluster chain is a series of clusters which provides space for recording the contents of files, directories, and other file system structures.

    Now, how is: "cluster chain which contains the given directory" ? Can you help me a little bit ? I am stuck here for a while, and I don't know how to move on ...

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: MSDN documentation unclear ?

    Why can't you just use the assigned drive letter when the USB drive is plugged in and the the usual FindFirst/FindNext WIN32 API's or C++17 directory_iterator()?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: MSDN documentation unclear ?

    If you really need to do this the hard way, have a look at https://rshullic.wordpress.com/2010/...ory-structure/ which contains sample c code to do this.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

  4. #4
    Join Date
    Jan 2009
    Posts
    336

    Re: MSDN documentation unclear ?

    Quote Originally Posted by 2kaud View Post
    Why can't you just use the assigned drive letter when the USB drive is plugged in and the the usual FindFirst/FindNext WIN32 API's or C++17 directory_iterator()?
    In the end, I intend to read even the deleted files/directory, and FindFirst/FindNext doesn't have such feature, as far as I know.

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: MSDN documentation unclear ?

    Quote Originally Posted by mesajflaviu View Post
    In the end, I intend to read even the deleted files/directory, and FindFirst/FindNext doesn't have such feature, as far as I know.
    Ah. No, FindFirst() et al doesn't provide info on deleted items. Then the example in my post #3 could be useful.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

  6. #6
    Join Date
    Jan 2009
    Posts
    336

    Re: MSDN documentation unclear ?

    Quote Originally Posted by 2kaud View Post
    Ah. No, FindFirst() et al doesn't provide info on deleted items. Then the example in my post #3 could be useful.
    Yes, that's right, look very promising that post ... thank you !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)