How Unrar Handles Legacy MS-DOS File Attributes

This article examines how the unrar extraction utility processes legacy MS-DOS file attributes preserved inside RAR archives. You will learn how the RAR file format stores these original FAT-based attributes, how modern Windows environments restore them natively, and the specific conversion rules unrar uses when translating legacy DOS flags into POSIX permissions on Unix-like operating systems.

Legacy DOS Attributes in the RAR Specification

The RAR format was originally designed during the MS-DOS era. As a result, older archive formats—primarily RAR 1.5 through RAR 4.x—store file metadata in a 32-bit integer that directly matches the standard MS-DOS FAT attribute byte:

  • Read-Only (0x01): Marks files as write-protected.
  • Hidden (0x02): Hides files from standard directory listings.
  • System (0x04): Identifies critical operating system files.
  • Directory (0x10): Flags an entry as a folder.
  • Archive (0x20): Used by backup software to detect modified files.

When creating an archive in a DOS or Windows environment, these flags are saved directly into the archive's file header. In the modern RAR 5.0 format, headers explicitly define the host operating system, but backward compatibility requires unrar to retain logic for parsing legacy DOS attribute fields.

Handling on Windows Operating Systems

When running unrar on Windows, handling legacy MS-DOS attributes is straightforward. Because modern Windows file systems (NTFS, FAT32, exFAT) inherit the DOS attribute model, unrar uses the standard Win32 API function SetFileAttributesW().

During extraction:

  1. unrar parses the attribute integer from the archive header.
  2. It strips internal-only flags and isolates the standard Win32 file flags (FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_SYSTEM, and FILE_ATTRIBUTE_ARCHIVE).
  3. After the file payload is written to disk, unrar applies the attributes directly to the file handle or file path.

If the file is marked Read-Only, unrar creates the file, writes the uncompressed content, and only sets the read-only attribute as the final step to prevent write-permission errors during extraction.

Handling on Unix, Linux, and macOS

POSIX systems do not have native equivalents for MS-DOS flags like Hidden, System, or Archive. When running unrar on a Unix-like platform, the extraction engine translates DOS attributes into standard POSIX permission bits (st_mode):

  • Read-Only: If the DOS Read-Only bit (0x01) is set, unrar strips the write bits (S_IWUSR, S_IWGRP, S_IWOTH) from the destination file permissions, effectively applying chmod a-w.
  • Writable Files: If the Read-Only bit is not set, unrar grants write access, typically defaulting to standard permissions (such as 0644 for files or 0755 for directories), modified by the user's current umask.
  • Hidden and System: unrar does not automatically prepend a period (.) to filenames marked as Hidden, because doing so would alter the file's canonical name. Instead, the Hidden and System flags are ignored during POSIX extraction.
  • Archive: The MS-DOS backup flag is entirely discarded, as it has no equivalent in standard POSIX file systems.

Preserving Attributes and Overwrite Behavior

When unrar encounters a file on disk that already carries a Read-Only attribute:

  • If the user specifies an overwrite command (such as -o+), unrar temporarily removes the existing file's read-only state, overwrites the data, and then reapplies the attributes specified in the archive header.
  • If the archive itself lacks POSIX permission metadata and only contains legacy DOS attributes, the utility's default behavior ensures files remain readable and executable according to standard system defaults, preventing inaccessible file states on non-DOS platforms.