Thread: help formating old floppies

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    44

    help formating old floppies

    i have an whole bunch of old floppy discs with RAW format on them and i want to format them to ntfs or fat but windows wont for some reason so i am venturing to create my own formating program what i need to know is how to write to specific memory and how to put the ntfs or fat format on these floppies. thank you in advanced

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    It seems you are wanting to a lot of OS-centered programming. You can only format the disk if you know how to put the FAT file system on the disk. NTFS AFAIK will not work on floppies.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    44
    how do you put FAT format on a floppy i checked wotsit.com but it had nothing on FAT do you know any other places that would tell me how

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by kwm32
    how do you put FAT format on a floppy i checked wotsit.com but it had nothing on FAT do you know any other places that would tell me how
    There is probably a reason that Windows can't format your floppies. Are they standard 31/2" 1.44MB disks?

    Anyway, probably the easiest way to do this would be to copy the raw contents of an existing, just formatted, floppy to a file. Then copy that file to the disk that you want to format.

    You will end up with more than one disk with the same volume id but I don't think that will be a problem. If it works you can always reformat them with Windows.

    Code:
    // Note: You may need admin priviliges to get raw access to A:
    
    hDrive = CreateFile(TEXT("\\.\A:"),GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
    
    ReadFile(hDrive, ...); // into buffer
    WriteFile(hFile, ...); // from buffer
    You would then reverse that to write the file to the floppy to be formatted.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    OK, I was bored. You don't need admin priviliges. I could only test on a formatted floppy(where it worked without a hitch) as I don't have an unformatted one available. However, assuming the disk is viable, it should work.

    If you really want info on the FAT format check http://www.pjrc.com/tech/8051/ide/fat32.html. Note that floppy disks are FAT12.

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <tchar.h>
    
    /* NOTE: This program is for NT/2000/XP only. */
    
    VOID WinError(LPCTSTR szMsg)
    {
    	_tprintf(_T("%s\nError Code: %d\n"), szMsg, GetLastError());
    	exit(GetLastError());
    }
    
    
    BOOL DoesFileExist(LPCTSTR szFile)
    {
    	return (GetFileAttributes(szFile) != INVALID_FILE_ATTRIBUTES);
    }
    
    
    INT CreateImageFromFloppy(LPCTSTR szFile)
    {
    	HANDLE hDrive, hFile;
    	BOOL   bRet;
    	DWORD  dwRead, dwWritten;
    	BYTE   buf[16384];
    
    	SetLastError(ERROR_SUCCESS);
    
    	hDrive = CreateFile(TEXT("\\\\.\\A:"), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
    	                    NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
    
    	if (hDrive != INVALID_HANDLE_VALUE)
    	{
    		hFile = CreateFile(szFile, GENERIC_WRITE, 0,
    		                   NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		if (hFile != INVALID_HANDLE_VALUE)
    		{
    			do
    			{
    				bRet = ReadFile(hDrive, buf, sizeof(buf), &dwRead, NULL);
    
    				if (!bRet)
    				{
    					WinError(TEXT("Failed while reading from disk."));
    					break;
    				}
    
    				bRet = WriteFile(hFile, buf, dwRead, &dwWritten, NULL);
    
    				if (!bRet)
    				{
    					WinError(TEXT("Failed while writing to image file."));
    					break;
    				}
    
    			} while (dwRead != 0);
    
    			CloseHandle(hFile);
    		}
    		else
    		{
    			WinError(TEXT("Failed to open image file."));
    		}
    
    		CloseHandle(hDrive);
    	}
    	else
    	{
    		WinError(TEXT("Failed to open floppy drive."));
    	}
    
    	return GetLastError();
    }
    
    
    INT CreateFloppyFromImage(LPCTSTR szFile)
    {
    	HANDLE hDrive, hFile;
    	BOOL   bRet;
    	DWORD  dwRead, dwWritten;
    	BYTE   buf[16384];
    
    	SetLastError(ERROR_SUCCESS);
    
    	hDrive = CreateFile(TEXT("\\\\.\\A:"), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
    	                    NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
    
    	if (hDrive != INVALID_HANDLE_VALUE)
    	{
    		hFile = CreateFile(szFile, GENERIC_READ, 0,
    		                   NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		if (hFile != INVALID_HANDLE_VALUE)
    		{
    			do
    			{
    				bRet = ReadFile(hFile, buf, sizeof(buf), &dwRead, NULL);
    
    				if (!bRet)
    				{
    					WinError(TEXT("Failed while reading from image file."));
    					break;
    				}
    
    				bRet = WriteFile(hDrive, buf, dwRead, &dwWritten, NULL);
    
    				if (!bRet)
    				{
    					WinError(TEXT("Failed while writing to disk."));
    					break;
    				}
    
    			} while (dwRead != 0);
    
    			CloseHandle(hFile);
    		}
    		else
    		{
    			WinError(TEXT("Failed to open image file."));
    		}
    
    		CloseHandle(hDrive);
    	}
    	else
    	{
    		WinError(TEXT("Failed to open floppy drive."));
    	}
    
    	return GetLastError();
    }
    
    
    int main(int argc, char * argv[])
    {
    	if (!DoesFileExist(TEXT("floppy.img")))
    	{
    		printf("Please insert source floppy and press ENTER...\n");
    		getchar();
    
    		CreateImageFromFloppy(TEXT("floppy.img"));
    	}
    
    	printf("Please insert target floppy and press ENTER...\n");
    	getchar();
    
    	CreateFloppyFromImage(TEXT("floppy.img"));
    
    	printf("Press ENTER to continue...\n");
    	getchar();
    	return 0;
    }
    P.S What has this got to do with networking anyway?

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    18
    This is also a "device communication" forum.

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    OK, for completeness I "unformatted" a floppy using this program:

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <tchar.h>
    
    /* NOTE: This program is NT/2000/XP only. */
    
    VOID WinError(LPCTSTR szMsg)
    {
    	_tprintf(_T("%s\nError Code: %d\n"), szMsg, GetLastError());
    	exit(GetLastError());
    }
    
    
    INT UnformatFloppy(VOID)
    {
    	HANDLE hDrive;
    	BOOL   bRet;
    	DWORD  dwWritten;
    	BYTE   buf[16384] = { 0 };
    
    	SetLastError(ERROR_SUCCESS);
    
    	hDrive = CreateFile(TEXT("\\\\.\\A:"), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
    	                    NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
    
    	if (hDrive != INVALID_HANDLE_VALUE)
    	{
    		do
    		{
    			bRet = WriteFile(hDrive, buf, sizeof(buf), &dwWritten, NULL);
    
    			if (!bRet)
    			{
    				WinError(TEXT("Failed while writing to disk."));
    				break;
    			}
    		} while (dwWritten != 0);
    
    		CloseHandle(hDrive);
    	}
    	else
    	{
    		WinError(TEXT("Failed to open floppy drive."));
    	}
    
    	return GetLastError();
    }
    
    
    int main(int argc, char * argv[])
    {
    	printf("Please insert floppy to unformat and press ENTER...\n");
    	getchar();
    
    	UnformatFloppy();
    
    	printf("Press ENTER to continue...\n");
    	getchar();
    	return 0;
    }
    and reformatted it with the program I posted above and it worked perfectly.

    >>This is also a "device communication" forum.<<

    Thanks. I forgot that.

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    So kwm32, did it work?

    (kwm32 has PMs turned off)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printf formating!
    By kamoda_pawel in forum C Programming
    Replies: 2
    Last Post: 01-18-2007, 06:40 AM
  2. cin and formating
    By Hexxx in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2004, 01:11 PM
  3. scanf and formating data
    By xddxogm3 in forum C Programming
    Replies: 23
    Last Post: 04-16-2004, 03:50 PM
  4. Need help formating Win XP
    By gqchynaboy in forum Tech Board
    Replies: 6
    Last Post: 11-13-2003, 01:42 PM
  5. screen formating
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-15-2001, 12:04 PM