This project provides a cross-platform C library, libimd, for reading, writing, and manipulating ImageDisk (.IMD) floppy disk image files. The ImageDisk format and original tools were created by Dave Dunfield to archive diskette images, particularly for classic computers, allowing for long-term storage and transfer via the internet.
The original MS-DOS version and further information can be found at Dave's Old Computers. This library aims to provide the core functionality for modern operating systems.
The functionality is primarily encapsulated in the following static libraries:
-
libimd(libimd.c,libimd.h): This is the fundamental library providing low-level functions for.IMDfile operations. It handles reading and writing of IMD file headers, comment blocks, and track data including sector maps and sector data records. It supports various data rates and encoding modes (FM/MFM).- Defines structures like
ImdTrackInfofor holding track details (mode, cylinder, head, sector count, sector size, maps, and data) andImdHeaderInfofor the file header. - Provides functions such as
imd_read_file_header,imd_read_comment_block,imd_load_track,imd_write_track_imd,imd_write_track_bin,imd_get_sector_size,imd_alloc_track_data, andimd_free_track_data. - Includes constants for sector sizes (128 to 8192 bytes), modes, and sector data record types (e.g., Normal, Compressed, Unavailable, Error flags).
- Defines structures like
-
libimdf(libimdf.c,libimdf.h): An in-memory ImageDisk file library built uponlibimd. It provides higher-level functions to open, access, and modify IMD image files by maintaining the entire image structure in memory.- Defines an opaque
ImdImageFilestructure to manage the in-memory image. - Offers functions like
imdf_open,imdf_close,imdf_get_header_info,imdf_get_comment,imdf_get_num_tracks,imdf_get_track_info,imdf_read_sector, andimdf_write_sector. - Manages write protection and geometry limits.
- Defines an opaque
-
libimdchk(libimdchk.c,libimdchk.h): A library for performing consistency checks on.IMDfiles.- Defines structures
ImdChkOptionsandImdChkResultsfor managing check parameters and storing outcomes. - Provides
imdchk_check_fileto validate aspects like header, comment termination, track readability, duplicate sector IDs, and invalid sector flags.
- Defines structures
The .IMD file format consists of:
- ASCII Header: Starts with "IMD v.vv: dd/mm/yyyy hh:mm:ss" (e.g., "IMD 1.18: 25/04/2024 15:30:00").
- ASCII Comment Block: Unlimited size, terminated by an
0x1A(EOF) character. - Track Data: A sequence of records for each track on the disk. Each track record includes:
- Mode Value (1 byte): Indicates data transfer rate and density (FM/MFM at 250/300/500 kbps).
- Cylinder (1 byte): Physical cylinder number.
- Head (1 byte): Physical head number (0 or 1). Upper bits indicate presence of optional Cylinder/Head maps.
- Number of Sectors (1 byte): Sectors in this track.
- Sector Size Code (1 byte): Code for sector size (0=128B, 1=256B, ..., 6=8192B). A value of 0xFF indicates variable sector sizes within the track.
- Sector Numbering Map (smap):
num_sectorsbytes, defining the logical ID for each physical sector. - Sector Cylinder Map (cmap) (optional):
num_sectorsbytes, if head bit 7 is set. Contains logical cylinder ID for each sector if different from physical. - Sector Head Map (hmap) (optional):
num_sectorsbytes, if head bit 6 is set. Contains logical head ID for each sector if different from physical. - Sector Data Records: One record per sector, indicating data status and the data itself:
0x00: Sector data unavailable.0x01: Normal data follows.0x02 xx: Compressed data; all bytes in sector have valuexx.0x03to0x08: Variations indicating Deleted Address Marks (DAM) and/or data errors, for normal or compressed data.
This project uses CMake as the build system. The CMakeLists.txt file defines the following libraries:
libimd(STATIC fromlibimd.c,libimd_utils.c)libimdf(STATIC fromlibimdf.c, depends onlibimd)libimdchk(STATIC fromlibimdchk.c, depends onlibimd)
Prerequisites:
- A C compiler (GCC, Clang, MSVC, etc.)
- CMake (version 3.24 or later specified)
Basic Build Steps (from project root):
mkdir build
cd build
cmake ..
cmake --build .This will compile the static libraries.
The original ImageDisk package by Dave Dunfield is provided with a free license for non-commercial use. The .IMD file format specification was placed into the public domain by its creator. This cross-platform library (libimd and related components) is available at www.github.com/hharte/libimd. Specific licensing for this port is an MIT license detailed in the LICENSE file within the repository.
- Original ImageDisk: Copyright 2005-2023 Dave Dunfield. All rights reserved.
- This cross-platform library (
libimd,libimdf,libimdchk): Copyright (c) 2025, Howard M. Harte.