#include <dos.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
  unsigned mcb_seg;
  void far *dev_cb;
  void far *file_tab;
  void far *clock_dr;
  void far *con_dr;
  unsigned max_btbl;
  void far *disk_buf;
  void far *drv_info;
  void far *fcb_tabl;
  unsigned fcb_size;
  unsigned char num_bdev;
  unsigned char lastdriv;
} CVT;
typedef CVT far* LPCVT;

typedef struct _DDCB_
{
  unsigned char drv_num;
  unsigned char drv_numd;
  unsigned sec_size;
  unsigned char clu_size;
  unsigned char clu_base;
  unsigned boot_siz;
  unsigned char fat_num;
  unsigned max_dir;
  unsigned data_sec;
  unsigned hi_clust;
  unsigned char fat_size;
  char reserv1;
  unsigned root_sec;
  void far *drv_addr;
  unsigned char media;
  unsigned char acc_flag;
  struct _DDCB_ far *next;
  unsigned reserv2;
  unsigned built;
} DDCB;
typedef DDCB far* LPDDCB;

typedef struct
{
  char path[64];
  unsigned reserv1;
  unsigned reserv2;
  unsigned char reserv3;
  LPDDCB   ddcb;
  unsigned cdir_clu;
  unsigned reserv4;
  unsigned reserv5;
  unsigned reserv6;
  unsigned char reserv7[7];
} DINFO;
typedef DINFO far* LPDINFO;

void main(void);

void main(void)
{
  union REGS   regs;
  struct SREGS sregs;
  LPCVT        lpCVT;
  LPDINFO      lpDINFO;
  unsigned i,j,k;

  printf("Информация о дисковых устройствах\n"
   "(C) Фролов А.В., 1995\n"
   "---------------------------------\n");

  // Получаем адрес векторной таблицы связи
  regs.h.ah = 0x52;
  intdosx(&regs, &regs, &sregs);

  // Передвигаем указатель на поле msb_seg
  lpCVT = (LPCVT)MK_FP(sregs.es, regs.x.bx - 2);

  // Адрес таблицы дисковых устройств
  lpDINFO = (LPDINFO)lpCVT->drv_info;

  // Количество дисковых устройств
  i = lpCVT->num_bdev;

  for(j=0; j<i; j++)
  {
    printf("Адрес: %Fp, путь: %Fs\n"
      "Первый кластер каталога: %d\n\n",
      lpDINFO, lpDINFO->path, lpDINFO->cdir_clu);

    lpDINFO = lpDINFO + 1;
  }
}

