DOSLFNBK v 1.6 - Backs up/restores Win95 long filenames in DOS Copyright (c) 1995,1996 D.J. Murdoch. 0. Contents of this file 1. Syntax 2. Description 3. Details 4. Memory Limitations 5. Safety 6. Recovery from Total Disk Failure 7. License 8. Release History 9. Acknowledgments 1. Syntax: DOSLFNBK drive:directory [options] will back up all the long filename records in the named directory and subdirectories of it to a file called BACKUP.LFN. Options: /f filename Back up to this file instead (default .LFN extension) /force Force DOSLFNBK to go ahead without asking questions, even when it may be unsafe /l List contents of backup file /nr No recursive: don't do subdirectories /nt Don't restore times from LFN backup /p Prompt before each filename restore (ignored during saves) /r Restore from existing backup /s directory Skip directory /v Give running status report /d filename Write a detailed debugging log to filename Examples: For recovery from a total disk failure, see section 6 below. To back up every long filename on the disk into BACKUP.LFN: doslfnbk c:\ To restore just the Windows directory and subdirectories: doslfnbk c:\windows /r To restore just the root directory, but no subdirectories: doslfnbk c:\ /r /nr To backup everything except the MS Internet Explorer cache and history directories: doslfnbk c:\ /s \progra~1\micros~1\cache /s \progra~1\micros~1\history To backup the current directory and subdirectories: doslfnbk . To restore the "Program Files" directory name and its subdirectories, you need two runs: doslfnbk c:\PROGRA~1 /r doslfnbk c:\ /r /p /nr On the second run, you'll be prompted for each name to restore; just say yes when you see "Program Files". To see what filenames in the "Program Files" directory and its subdirectories are in the current BACKUP.LFN file: doslfnbk c:\PROGRA~1 /l 2. Description: Microsoft's Windows 95 introduces long filenames (LFNs), and they are mostly compatible with old software. However, there are some problems. Old backup programs don't recognize LFNs, so they don't get properly backed up. Worse, the Win95 backup program doesn't support a lot of common backup hardware (e.g. Colorado Memory Systems tape drives using accelerator cards) and won't run in DOS mode, so recovery from a catastrophic disk failure can be really difficult. To address this problem, Microsoft put a program called LFNBK on the Win95 CD ROM to back up your LFNs. However, it's very inconvenient to use. It requires changes to your Control Panel settings before and after use, and it works by stripping all the LFNs off your disk --- so you need to restore them again after you've done your backup to tape. It will only run after Win95 has booted, so again you've got big problems after a catastrophic disk failure. If you've got a program that is completely incompatible with LFNs then you might want to use LFNBK, but for routine system backups it's too much of a pain. I wrote DOSLFNBK to address these problems. It runs in any version of DOS that can see your disk, and can both backup and restore your files there. During backup, it makes no changes to the names, so you can routinely run it just before a tape backup and not have to undo the damage afterwards. It also allows partial backups and partial restores; I'm pretty sure LFNBK is an all-or-nothing affair. The downside of DOSLFNBK is that it has to work on the disk below the file system level. This means that it needs to lock the disk to make sure no other programs are writing to the disk while it is running. This may cause errors in the other programs; I recommend shutting them down before running DOSLFNBK, or running it in a single-tasking DOS session. 3. Details: Contents of this section: - what DOSLFNBK does - how to specify which directory to back up - existing long filenames - date information - changed files - file attributes - the /v verbose option and the /d debug option - running in Windows - the /force option to ignore warnings - the /s option to skip directories - large directories - the LOCK and UNLOCK commands - DOSLFNBK, disk defragmenters and directory sort utilities - DOSLFNBK and XCOPY - exit codes When doing a backup, DOSLFNBK reads the directories on the disk and writes copies of all of the LFN records to the binary BACKUP.LFN file (or whatever file you specify with /f). If you use the /nr option, it will work only on the specified directory; otherwise, it saves those entries as well as everything in any subdirectory below it. Relative directory specifications are supported, and DOSLFNBK understands SUBST to some extent. (I believe it's possible with a complicated network of SUBST, JOIN, etc. to confuse it; don't do that!) The directory name itself won't be backed up or restored; only the files and subdirectories within it. There is no way to specify a subset of the files; you have to use the /p prompting option if you want this. The original drive letter is not stored in BACKUP.LFN, so you can use DOSLFNBK to save the long filenames on one drive, use a DOS utility to move them to another drive, and then restore the filenames there. You must restore to the same full path as was originally backed up; you can't graft a subdirectory branch onto a new tree. DOSLFNBK will normally not overwrite an existing LFN with a different one; you should rename the file to its 8.3 alias before running if you want to restore an old name, or run with the /p option for individual prompting. Normally, DOSLFNBK will restore the backed up date information, since older DOS versions and DOS utilities probably don't save this properly. You can override this behaviour by using the /nt switch. If during a restore, DOSLFNBK detects that the file size has changed, you'll be prompted as to whether you want to restore the LFN or not. If you choose to restore it, the date information will *not* be restored, as it is probably incorrect. During a restore, the file attributes of the file on the disk will be kept. To show you the progress of a run, DOSLFNBK prints a dot for about every 10 directories examined or (in /v mode) prints the directory and file names. If it stops printing for more than a few seconds, something is probably wrong. Try running again with the /d debug log option, and if it stops again, please email me (dmurdoch@mast.queensu.ca) a copy of your log, along with a description of your system. I'm very interested in making DOSLFNBK as bug-free as possible. The /force option tells DOSLFNBK to go ahead without stopping for several different warnings (e.g. overwriting the backup file). Use it in a batch file only when you're sure you always want it to go ahead. The /s option tells DOSLFNBK to skip the back up or restore of a particular directory. This is meant as a workaround for the memory limitations in DOSLFNBK that are described in section 4 below. You can use /s as often as necessary to skip multiple directories--the only limit is the command line length. Note that the directory name must be specified using the short aliases, e.g. "\PROGRA~1" instead of "\Program files". Relative directory paths using "." and ".." are not supported. Previous versions of DOSLFNBK used the DOS LOCK and UNLOCK commands to lock the disk and prevent errors during restores. The current version does this internally. If you have an old batch file that runs LOCK, you'll get warning messages: "Unable to lock drive X:". Just remove LOCK from the batch file and the warnings will go away. There is one bug in Win95 that the internal locking shows up: if you try to restore LFNs to a disk that has any open files on it while in a DOS window, the window will suddenly switch to full screen. I don't know of any way to prevent this. You may be tempted to use an older DOS-based disk defragger or directory sort utility that doesn't understand long filenames, and then use DOSLFNBK to restore the long filenames. DON'T DO THIS! It is extremely likely to cause errors to your directory structure which can't be repaired except by hours and hours of work. The problem is that these programs usually leave a few files with wrong but apparently correct long filenames. You'll find that 99 percent of your disk is restored, but some small number of files are not. It is extremely difficult and time consuming to find and repair these files. If you want to use these DOS-based programs, you should remove all long filenames first (e.g. using LFNBK, or by restoring from tape in DOS). A better solution is to use Win95 compatible versions of these utilities. (Win95 comes with a defragger, and there are shareware directory sort utilities available, including mine, available in ftp://garbo.uwasa.fi/pc/dirutil as lfnsrt??.zip.) I have received several messages from people who have tried to use XCOPY and DOSLFNBK to back up their disk to a network drive or elsewhere, and then found on restore that Win95 won't boot properly. I don't know what is going wrong in these situations, but as far as I can tell it's either a bug in XCOPY, or people aren't using the right combination of options when they run it. If someone has the time to figure out exactly what is going wrong, I'd appreciate being told. In the meantime I don't recommend using XCOPY for backups. When a run is successful, DOSLFNBK exits with ERRORLEVEL 0. When something goes wrong, it prints an error message and exits with a higher errorlevel. The currently defined error levels are: 99 - Syntax error 98 - Disk init error 97 - Disk read error 96 - Disk write error 95 - Disk directory error 94 - Directory init error 92 - Disk lock error 91 - Internal error 89 - Memory error 88 - Multitasker error 87 - Overwrite error 86 - Debug error 85 - Backup read error 84 - Backup write error 83 - Backup open error 82 - Backup close error 81 - Some directories were skipped because of low memory 4. Memory Limitations: When running, DOSLFNBK keeps copies of several directories in memory at once. It is written as a real mode DOS program and keeps all of this data in the low 640K of memory. This means that in a typical DOS session with 500K of memory available, DOSLFNBK will run out of memory when about 15,000 directory entries are in memory. On a restore, up to 3 copies of each directory entry may be in memory at once, limiting DOSLFNBK to disks with fewer than 5000 directory entries in any branch of the directory tree. (The total number of files on the disk doesn't matter; what matters is the number of entries in a directory, its parent, grandparent etc., back to the root.) When I wrote DOSLFNBK, I thought disks approaching this limit were very unusual. However, it *is* possible to have such a disk, and here's how to find out if you do: Run your backup with the /V verbose option. At the end, it will print a message something like Used 255K; restore will require about 264K in DOS session. If the amount of memory estimated for the restore is more than you have available (as reported by the DOS MEM command), you might have problems. You might not; the number reported is usually an overestimate. If it ever turns out that you do run out of memory during a restore, you can still restore the LFNs by breaking up the restore operation into several steps, restoring different parts of your subdirectory tree separately. In the worst case (more than 5000 entries in a single subdirectory), you may have to temporarily move files out of the directory and restore the LFNs a few thousand (!!) at a time. Since the original release, it has become clear that there are some common situations leading to very large directories. The Microsoft Plus! package includes one, and WWW browsers often create them while maintaining caches or history lists. Unfortunately, the current version of DOSLFNBK doesn't handle these very well; it just skips these directories and prints a warning message and sets an error level on exit. I have added the /s option to allow you to skip particular directories during the backup or restore operation. A better solution that allows all directories to be backed up is in the works. 5. Safety: DOSLFNBK works with your disk at a level below the file system, so if things go wrong during an LFN restore, it's conceivable that you could lose whole files or directories. I've tried to make it as safe as I can, but you should follow some simple precautions: - Run Scandisk before DOSLFNBK and get it to fix any errors. In particular, if you've run other low level software (e.g. a defragger or a directory sorter) that may have messed up the LFNs, run Scandisk first. Better still: don't use that old defragger/directory sorter, because Scandisk may not be able to repair all the damage it does. - Don't turn off or reboot your PC in the middle of a DOSLFNBK run. If there's a power failure or (horrors!) a bug in DOSLFNBK forces you to reboot, then Scandisk should be able to repair much of the damage. You may lose some filenames, but Scandisk should be able to recover the files themselves. - If you hit Ctrl-Break or Ctrl-C during a DOSLFNBK restore, it shouldn't do any damage other than giving you only a partial restore of your LFNs --- but this is *not* a well-tested feature, and there may be conditions under which you'll suffer worse damage. Again, Scandisk should be able to repair most of it. - DOSLFNBK was written for version 4.00.950 of Windows 95 (the August 1995 release). It hasn't been tested on the earlier beta test versions, or any versions later than the January 96 fix pack (version 4.00.950a). If the VFAT file structure isn't what DOSLFNBK is written for, it could do some real damage. In particular, it will *not* work on a VFAT32 disk. A beta tester has told me that it refuses to run on the current beta version of VFAT32, but the final release of VFAT32 is not out yet, so I don't know what will happen with it. - This is the third release of DOSLFNBK to the public. There may still be special conditions on your system that it doesn't handle. If you can, try it out when you've got a good second backup to make sure it works. If it doesn't, *please* send me details, and I'll attempt to fix it. 6. Recovery from total disk failure: If your boot disk fails, or you decide to repartition it, then you may need to do a full restore from a backup tape. Unfortunately, the Win95 backup program provides *no way* to do this without re-installing Win95 from the original disks or CD ROM. From reports I've heard, the same is true of the just-released Win95 version of Colorado Memory System's backup program and some other commercial backup programs. However, if you have a reliable DOS-based backup program, DOSLFNBK will let you do a complete restore from a backup. I've only had to do this once, so these instructions aren't guaranteed to cover everything for every system, but they worked on mine. ADVANCE PREPARATIONS: Before your disk fails (i.e. right now! :-), you need to prepare the following: 1. A Win95 startup disk. If you didn't create one when you installed Win95, start the Add/Remove Programs option in Control Panel, and click the Startup Disk tab. Then click the Create Disk button, and follow the instructions on-screen. 2. A copy of your DOS-based backup/restore program on a floppy disk. It may require EMS memory; if so, you should put HIMEM.SYS and EMM386.EXE on your startup disk, and load them via CONFIG.SYS. 3. If you use Drivespace disk compression, then you should also make sure that the MINI.CAB file from the installation disks or the CD ROM is in your Windows directory on the hard disk. 4. A full backup of your disk(s). Just before creating this, run DOSLFNBK to save all of your long filenames. You'll need to create one backup file for each disk. It's fine to leave this on the hard disk so that it ends up on the backup; you don't need to have it on floppy disk. WHEN YOUR DISK FAILS: Depending on the reason for your disk failure, you may be able to skip some of the early steps here. Read them over, and figure out where to start. If you have to, you can start again, so the only thing you lose by starting too far down is time. 1. Make any necessary repairs to your hardware. 2. Boot from your Startup disk, and use FDISK to partition your disk. Use "FORMAT c: /s" to reformat the disk and transfer the system files to it. 3. (Optional) Transfer your tape backup software to your hard disk. 4. If you're not planning to use Drivespace, you can skip down to step 8. 5. If you want to compress your drive, you need to restore enough of Win95 to run Drivespace. Don't restore the whole disk; you might not have room for it. For most people, restoring the files in the root directory and the files in the Windows directory should be enough. If you have any essential drivers in other directories, you'll need to restore them too. Finally, you should restore DOSLFNBK and the data file(s) containing the backed up long filenames. IMPORTANT: You should not overwrite IO.SYS, but you *should* overwrite MSDOS.SYS. It is a hidden read-only file in your root directory. A good way is to erase MSDOS.SYS before starting the restore (use ATTRIB from the Startup disk to remove the System, Hidden, Read-only attributes), and then tell your restore program not to overwrite existing files. Restore all those files now. 6. Restore the long filenames by running DOSLFNBK c:\ /R /V /F backupfilename 7. Remove the Startup disk, and reboot your system. You may get some errors about missing drivers (e.g. no sound card drivers), but things should basically work. Run DriveSpace to compress your drives the way you want. 8. Reboot your system in DOS mode or from the Startup disk. 9. Restore all rest of the files on all of your disks from the backup now. See the "IMPORTANT" note in step 5 about MSDOS.SYS and IO.SYS. 10. Restore all the rest of your long filenames by running DOSLFNBK c:\ /R /V /F backupfilename and if you've also got a D: partition, DOSLFNBK d:\ /R /V /F backupfilename You may get messages about some long filenames already existing from your first restore; don't worry about those. 11. Some restore programs set the archive bit on all restored files; you might want to turn it off (since you've still got those files backed up) at this point. Reboot your system, and things should be back as they were when you did your backup! 7. License: DOSLFNBK is *not* public domain software, but you may use it at no charge. You may distribute unmodified copies of the complete DOSLFNBK package, provided your total charge is no more than $1. The total cost of a compilation (e.g. a CD ROM) including DOSLFNBK must be no more than $1 per package in the compilation. DOSLFNBK was written in Borland Pascal 7.01, using the excellent Object Professional library from TurboPower Software. You can obtain the source code (including an object-oriented low-level disk access unit and a huge memory support unit, but not OPro) by sending a cheque or money order for $50 (in Canadian or US dollars, or the UKP equivalent of $50US) to: Duncan Murdoch 337 Willingdon Ave. Kingston, Ontario, Canada. K7L 4J3 Note: I will be going overseas from August 1996 to June 1997. During this time I will still fill orders, but there are almost certain to be delays. You can also order source code from the Public (software) Library (PsL) using MC, Visa, AmEx, or Discover card: - by calling 800-242-4775 (US only) - by calling 713-524-6394 - by faxing your order to 713-524-6398 - by sending your order by Compuserve to 71355,470. - by sending your order by Internet to 71355.470@compuserve.com PsL only accepts payment in US dollars. Please give PsL your name exactly as it appears on the card, and tell them your card's expiry date. DOSLFNBK is PsL product #14247. The PsL numbers are for ordering only. I *cannot* be reached at the PsL numbers. To contact me for information about dealer pricing, volume discounts, site licensing, the status of shipment of the product, the latest version number or for technical information write to me at the address above or at the email address below. I'd especially like to hear bug reports and suggestions for improvements. Internet: dmurdoch@mast.queensu.ca 8. Release history: 0.0 - first beta test version 0.1 - kept file attributes of existing file during restore. 0.2 - made messages more informative; fixed bug in handling erased file entries; added check of overwrite of backup file; changed default name of backup file to BACKUP.LFN and made LFN the default backup extension; added /P option. 0.3 - fixed memory leak that caused run-time error 203 on large restore 0.4 - added check for successful write of backup file, added /force option. 0.5 - added report of memory use, /d option, many debugging messages 0.6 - cleaned up messages and debug log, removed disk size restriction, added progress dots for non-verbose runs. 1.0 - first public release --- same as 0.6 1.1 - unauthorized release 1.2 - documentation changes and addition of /s option 1.3 - improved memory management, stopped use of obsolete DOS service 1C, speeded up directory expansion on restore 1.4 - added /L option, support for relative path on command line, internal drive locking, support for SUBST etc. Changed exit codes to be compatible with LFNSORT. 1.5 - public release, same as 1.4c 1.6 - fixed bug in handling volume labels 9. Acknowledgments DOSLFNBK was written based on the information in Robert Hummel's article on Win95 long filenames in the June/July 1995 issue of PC Techniques Magazine. Thanks are due to the beta testers, who suggested many improvements, and several of whom were put to considerable inconvenience by early versions that messed up their disks. M. Guffey made a lot of useful suggestions for improvements to the documentation.