English 中文(简体)
如何丢弃国家食品安全局的Bitmap档案
原标题:How to dump the NTFS $Bitmap file

For a project, I want to get the list of all free/used clusters on an NTFS partition. For this i have to dump the $Bitmap file and parse its contents.

网上只有很少的APIC和实例,但似乎没有工作。 是否有简单的方法/代码样本,仅复制Bitmap在其他地方的档案。

使用FSCTL_GET_VOLUME_BITMAP 唯一的方式? 理想的做法是,我想在C#中这样做。

问题回答

NFI.EXE(被使用)是“支持工具”的一部分,可以列举所有非关税壁垒分割项目。 它还可能能够放弃Bitmap的内容。

“entergraph

你当然要走一条方便的道路,而不是试图直接读到<条码>。 当然,如果有人为你做过,你就不必这样做。 由此可见,一个MSDN博客已经为你写了一点小 wrap:

整个类别是300条以上的法典,因此,我赢得一席之地,但这里的职能是掌握批号:

    /// <summary>
    /// Get cluster usage for a device
    /// </summary>
    /// <param name="DeviceName">use "c:"</param>
    /// <returns>a bitarray for each cluster</returns>
    static public BitArray GetVolumeMap(string DeviceName)
    {
        IntPtr pAlloc = IntPtr.Zero;
        IntPtr hDevice = IntPtr.Zero;

        try
        {
            hDevice = OpenVolume(DeviceName);

            Int64 i64 = 0;

            GCHandle handle = GCHandle.Alloc(i64, GCHandleType.Pinned);
            IntPtr p = handle.AddrOfPinnedObject();

            // alloc off more than enough for my machine
            // 64 megs == 67108864 bytes == 536870912 bits == cluster count
            // NTFS 4k clusters == 2147483648 k of storage == 2097152 megs == 2048 gig disk storage
            uint q = 1024 * 1024 * 64; // 1024 bytes == 1k * 1024 == 1 meg * 64 == 64 megs

            uint size = 0;
            pAlloc = Marshal.AllocHGlobal((int)q);
            IntPtr pDest = pAlloc;

            bool fResult = DeviceIoControl(
                hDevice,
                FSConstants.FSCTL_GET_VOLUME_BITMAP,
                p,
                (uint)Marshal.SizeOf(i64),
                pDest,
                q,
                ref size,
                IntPtr.Zero);

            if (!fResult)
            {
                throw new Exception(Marshal.GetLastWin32Error().ToString());
            }
            handle.Free();

            /*
            object returned was...
      typedef struct 
      {
       LARGE_INTEGER StartingLcn;
       LARGE_INTEGER BitmapSize;
       BYTE Buffer[1];
      } VOLUME_BITMAP_BUFFER, *PVOLUME_BITMAP_BUFFER;
            */
            Int64 StartingLcn = (Int64)Marshal.PtrToStructure(pDest, typeof(Int64));

            Debug.Assert(StartingLcn == 0);

            pDest = (IntPtr)((Int64)pDest + 8);
            Int64 BitmapSize = (Int64)Marshal.PtrToStructure(pDest, typeof(Int64));

            Int32 byteSize = (int)(BitmapSize / 8);
            byteSize++; // round up - even with no remainder

            IntPtr BitmapBegin = (IntPtr)((Int64)pDest + 8);

            byte[] byteArr = new byte[byteSize];

            Marshal.Copy(BitmapBegin, byteArr, 0, (Int32)byteSize);

            BitArray retVal = new BitArray(byteArr);
            retVal.Length = (int)BitmapSize; // truncate to exact cluster count
            return retVal;
        }
        finally
        {
            CloseHandle(hDevice);
            hDevice = IntPtr.Zero;

            Marshal.FreeHGlobal(pAlloc);
            pAlloc = IntPtr.Zero;
        }
    }




相关问题
What encoding are filenames in NTFS stored as?

I m just getting started on some programming to handle filenames with non-english names on a WinXP system. I ve done some recommended reading on unicode and I think I get the basic idea, but some ...

NTFS Alternate Data Streams - Good or bad Idea?

I would like to store some Application-Related Metadata for Files, and NTFS Alternate Data Streams (AltDS) would allow me to store this metadata directly on the files rather than in a separate ...

Is there any length-limits of file path in NTFS?

Why can not I create a deep path whose characters in path is more than 255 in NTFS File System? It seems a limits of FAT32, but also exist in NTFS? Can anyone provide some documents? Many Thanks!

Searching files in NTFS

We have a fairly large disk array with roughly 2-3 million XML files on it. The disk is formatted with NTFS and we would like to search the filesystem using wildcards. So something like * ...

How can I query NTFS disk quotas in C#?

I need to be able to find, for all users on a given remote machine, those users disk quotas and actual disk usage. I need to be able to do this reporting in a C# application. (Well, technically a DLL ...

热门标签