/*

sectbl.c -- control()の下請け;セクタテーブルの処理

*/

#include<stdio.h>
#include<dos.h>
#include<malloc.h>
#include"dmove86.h"

void		freesectbl(sectbl)
struct SECTBL	*sectbl;
{
	struct SECTBL	*tblfree;

	while (sectbl != NULL)
	{
		tblfree = sectbl;
		farfree(tblfree->buf);
		sectbl = tblfree->next;
		free(tblfree);
	}
}

extern	struct DPB	Dpb;
extern	int		Drive;

void		writedir(sectbl,dirtbl)
struct SECTBL	*sectbl;
struct DIRENTRY	far **dirtbl;
{
	struct DIRENTRY	far *buftop =
			(struct DIRENTRY far *)farmalloc(Dpb.seclen);
	struct DIRENTRY	far *buf;
	int		i;
	unsigned	n;

	if	(buftop == NULL)
	{
		dm_errmes("メモリ不足で書き込めません");
		goto ENDWRITING;
	}

	while	(sectbl != NULL)
	{
		buf = buftop;

		for	(i=0 ; i<DIRSEC ; i++)
			*(buf++) = **(dirtbl++);	/* 構造体のコピー */

		if	((n=wrabssec(buftop, sectbl->num, Drive)) & 0x100)
		{
			dm_errmes("書き込みエラーです");
			goto ENDWRITING;
		}

		sectbl = sectbl->next;

	}
ENDWRITING:;
	farfree(buftop);
}

