Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7964803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:59:12+00:00 2026-06-04T05:59:12+00:00

I am actually trying to extract a Fat Disk Image with DiskUtils but I

  • 0

I am actually trying to extract a Fat Disk Image with DiskUtils but I am not getting the correct file names…

I get “\TURNER~3\TOPPER~1.P~1” in place of “\TURNEROVER\TOPPERSHEATH.PPTX”

FatFileSystem FatImg = new FatFileSystem(MS); //MS = Fat Image MemoryStream
foreach(DiscDirectoryInfo Di in FatImg.Root.GetDirectories())
{
    foreach(DiscFileInfo Fi in Di.GetFiles())
    {
        Stream St = Fi.OpenRead(); // Correct Stream
        string FName = Fi.Name; //Wrong Name
    }
}

This is because DiscUtils does not support LFN [Long File Names]…

So I am looking for a perfect library to extract these files befor i try to make one myself…

Is there any way I can Extract it [maybe by DiscUtils] without FileName Errors…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:59:15+00:00Added an answer on June 4, 2026 at 5:59 am

    Here is some modifications that you can add to DiscUtils to support FAT LFNs:

    First, make these changes to the Fat\Directory.cs file, like this (you need to add the _lfns variable, the GetLfnChunk function, and modify the existing LoadEntries function to add the lines marked with //+++ below):

    internal Dictionary<string, string> _lfns = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
    
    private static string GetLfnChunk(byte[] buffer)
    {
        // see http://home.teleport.com/~brainy/lfn.htm
        // NOTE: we assume ordinals are ok here.
        char[] chars = new char[13];
        chars[0] = (char)(256 * buffer[2] + buffer[1]);
        chars[1] = (char)(256 * buffer[4] + buffer[3]);
        chars[2] = (char)(256 * buffer[6] + buffer[5]);
        chars[3] = (char)(256 * buffer[8] + buffer[7]);
        chars[4] = (char)(256 * buffer[10] + buffer[9]);
    
        chars[5] = (char)(256 * buffer[15] + buffer[14]);
        chars[6] = (char)(256 * buffer[17] + buffer[16]);
        chars[7] = (char)(256 * buffer[19] + buffer[18]);
        chars[8] = (char)(256 * buffer[21] + buffer[20]);
        chars[9] = (char)(256 * buffer[23] + buffer[22]);
        chars[10] = (char)(256 * buffer[25] + buffer[24]);
    
        chars[11] = (char)(256 * buffer[29] + buffer[28]);
        chars[12] = (char)(256 * buffer[31] + buffer[30]);
        string chunk = new string(chars);
        int zero = chunk.IndexOf('\0');
        return zero >= 0 ? chunk.Substring(0, zero) : chunk;
    }
    
    private void LoadEntries()
    {
        _entries = new Dictionary<long, DirectoryEntry>();
        _freeEntries = new List<long>();
    
        _selfEntryLocation = -1;
        _parentEntryLocation = -1;
    
        string lfn = null;  //+++
        while (_dirStream.Position < _dirStream.Length)
        {
            long streamPos = _dirStream.Position;
            DirectoryEntry entry = new DirectoryEntry(_fileSystem.FatOptions, _dirStream);
    
            if (entry.Attributes == (FatAttributes.ReadOnly | FatAttributes.Hidden | FatAttributes.System | FatAttributes.VolumeId))
            {
                // Long File Name entry
                _dirStream.Position = streamPos;  //+++
                lfn = GetLfnChunk(Utilities.ReadFully(_dirStream, 32)) + lfn;  //+++
            }
            else if (entry.Name.IsDeleted())
            {
                // E5 = Free Entry
                _freeEntries.Add(streamPos);
                lfn = null; //+++
            }
            else if (entry.Name == FileName.SelfEntryName)
            {
                _selfEntry = entry;
                _selfEntryLocation = streamPos;
                lfn = null; //+++
            }
            else if (entry.Name == FileName.ParentEntryName)
            {
                _parentEntry = entry;
                _parentEntryLocation = streamPos;
                lfn = null; //+++
            }
            else if (entry.Name == FileName.Null)
            {
                // Free Entry, no more entries available
                _endOfEntries = streamPos;
                lfn = null; //+++
                break;
            }
            else
            {
                if (lfn != null) //+++
                { //+++
                    _lfns.Add(entry.Name.GetDisplayName(_fileSystem.FatOptions.FileNameEncoding), lfn); //+++
                } //+++
                _entries.Add(streamPos, entry);
                lfn = null; //+++
            }
        }
    }
    

    Second, add these two public functions to the Fat\FatFileSystem.cs file. They will be the new APIs to query on LFNs:

    /// <summary>
    /// Gets the long name of a given file.
    /// </summary>
    /// <param name="shortFullPath">The short full path to the file. Input path segments must be short names.</param>
    /// <returns>The corresponding long file name.</returns>
    public string GetLongFileName(string shortFullPath)
    {
        if (shortFullPath == null)
            throw new ArgumentNullException("shortFullPath");
    
        string dirPath = Path.GetDirectoryName(shortFullPath);
        string fileName = Path.GetFileName(shortFullPath);
        Directory dir = GetDirectory(dirPath);
        if (dir == null)
            return fileName;
    
        string lfn;
        if (dir._lfns.TryGetValue(Path.GetFileName(shortFullPath), out lfn))
            return lfn;
    
        return fileName;
    }
    
    /// <summary>
    /// Gets the long path to a given file.
    /// </summary>
    /// <param name="shortFullPath">The short full path to the file. Input path segments must be short names.</param>
    /// <returns>The corresponding long file path to the file or null if not found.</returns>
    public string GetLongFilePath(string shortFullPath)
    {
        if (shortFullPath == null)
            throw new ArgumentNullException("shortFullPath");
    
        string path = null;
        string current = null;
        foreach (string segment in shortFullPath.Split(Path.DirectorySeparatorChar))
        {
            if (current == null)
            {
                current = segment;
                path = GetLongFileName(current);
            }
            else
            {
                current = Path.Combine(current, segment);
                path = Path.Combine(path, GetLongFileName(current));
            }
        }
        return path;
    }
    

    And that’s it. Now, youll be able to dump a whole FAT disk recursively like this, for example:

    static void Main(string[] args)
    {
        using (FileStream fs = File.Open("fat.ima", FileMode.Open))
        {
            using (FatFileSystem floppy = new FatFileSystem(fs))
            {
                Dump(floppy.Root);
            }
        }
    }
    
    static void Dump(DiscDirectoryInfo di)
    {
        foreach (DiscDirectoryInfo subdi in di.GetDirectories())
        {
            Dump(subdi);
        }
        foreach (DiscFileInfo fi in di.GetFiles())
        {
            Console.WriteLine(fi.FullName);
            // get LFN name
            Console.WriteLine(" " + ((FatFileSystem)di.FileSystem).GetLongFileName(fi.FullName));
    
    
            // get LFN-ed full path
            Console.WriteLine(" " + ((FatFileSystem)di.FileSystem).GetLongFilePath(fi.FullName));
        }
    }
    

    Use at your own risks! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to prevent A HREF from actually opening the link, but to execute
I was trying out the following code which actually saves the pdf file to
I'm actually trying doing this in Java, but I'm in the process of teaching
I'm actually trying load image based on its screen size. Code seems to be
I’m trying to extract the name and satelite coordinations from a XML file and
What I'm actually trying to do is put a WebKitView into a ScreenSaver (which
I am actually trying to change the color index for the first word with
I'm actually trying to fix this issue where my projects are always out of
is there similar syntax to php's $$variable in python? what I am actually trying
Actually I'm trying to implement an ontouchlistener into my android (1.5) application. therefore i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.