예제 #1
0
int hitbuffer_inc(hitbuffer *hb, Z32 *hit) {
	hb->freq += 1LLU; //LLU for 64-bit.  OSX 10.5 is VERY finicky about this.
	int result;
	if (hb->freq < PHILO_INDEX_CUTOFF) {
		add_to_dir(hb, hit, 1);
//		fprintf(stderr, "added hit for %s...\n", hb->word);
	}
	else if (hb->freq == PHILO_INDEX_CUTOFF) {
			//when the frequency reaches 10, we start using a block-header layout.
			//each "hit" in the directory corresponds to a large, compressed block of hits.
			//by comparing the directory headers to the query, the search engine skips blocks if possible.

			result = add_to_block(hb,&(hb->dir[1*hb->db->dbspec->fields]),PHILO_INDEX_CUTOFF - 2);
			if (result == PHILO_BLOCK_FULL) {
				fprintf(stderr, "you can't fit PHILO_INDEX_CUTOFF hits into a block!  adjust your block size, or your index cutoff.\n");	
			}

			hb->dir_length = 1LLU;
			hb->type = 1;
			result = add_to_block(hb,hit,1);
//			fprintf(stderr, "clearing dir.  started new block for %s...\n", hb->word);
	}
	if (hb->freq > PHILO_INDEX_CUTOFF) {
		result = add_to_block(hb,hit,1);
		if (result == PHILO_BLOCK_FULL) {
			// IF the block add failed,
			write_blk(hb); //write the full block out, start a new one,
			add_to_dir(hb,hit,1); //then push the current hit onto the directory.
//			fprintf(stderr, "started new block for %s...\n", hb->word);
		}
	}		
	return 0;
}
예제 #2
0
int hitbuffer_finish(hitbuffer *hb) {
	if (!strcmp(hb->word, "")) {
		return 0;
	}
	if (hb->type == 0) {	
	  //		fprintf(stderr, "%s: %d\n", hb->word, (int)hb->freq);
		write_dir(hb);
	}
	else if (hb->type == 1) {
	  //	fprintf(stderr, "%s: %d [%d blocks]\n", hb->word, (int)hb->freq, (int)hb->dir_length);
		write_dir(hb);
		write_blk(hb);
	}
	return 0;
}
예제 #3
0
파일: write.c 프로젝트: KerLiu/firekylin
int sys_write(int fd, char *buf, size_t size)
{
	struct file *file;
	struct inode *inode;
	int res;

	if (fd > NR_OPEN || !(file = (CURRENT_TASK() )->file[fd]))
		return -EBADF;
	if (!(file->f_mode & O_WRITE))
		return -EBADF;

	inode = idup(file->f_inode);
	if (file->f_mode & O_APPEND)
		file->f_pos = inode->i_size;
	switch (inode->i_mode & S_IFMT) {
		case S_IFREG:
			res = write_file(inode, buf, file->f_pos, size);
			break;
		case S_IFDIR:
			res = -EISDIR;
			break;
		case S_IFCHR:
			res = write_char(inode->i_rdev, buf, file->f_pos,
					size);
			break;
		case S_IFBLK:
			res = write_blk(inode->i_rdev, buf, file->f_pos,
					size);
			break;
		case S_IFIFO:
			res= write_pipe(inode,buf,size);
			break;
		default:
			res = -EIO;
	}

	if (res > 0)
		file->f_pos += res;
	if(file->f_pos>inode->i_size)
		inode->i_size=file->f_pos;

	iput(inode);
	return res;
}
예제 #4
0
static int request_code_segment(struct ft1000_usb *ft1000dev, u16 **s_file,
		 u8 **c_file, const u8 *endpoint, bool boot_case)
{
	long word_length;
	int status = 0;

	/*DEBUG("FT1000:REQUEST_CODE_SEGMENT\n");i*/
	word_length = get_request_value(ft1000dev);
	/*DEBUG("FT1000:word_length = 0x%x\n", (int)word_length); */
	/*NdisMSleep (100); */
	if (word_length > MAX_LENGTH) {
		DEBUG("FT1000:download:Download error: Max length exceeded\n");
		return STATUS_FAILURE;
	}
	if ((word_length * 2 + (long)c_file) > (long)endpoint) {
		/* Error, beyond boot code range.*/
		DEBUG("FT1000:download:Download error: Requested len=%d exceeds BOOT code boundary.\n", (int)word_length);
		return STATUS_FAILURE;
	}
	if (word_length & 0x1)
		word_length++;
	word_length = word_length / 2;

	if (boot_case) {
		status = write_blk(ft1000dev, s_file, c_file, word_length);
		/*DEBUG("write_blk returned %d\n", status); */
	} else {
		write_blk_fifo(ft1000dev, s_file, c_file, word_length);
		if (ft1000dev->usbboot == 0)
			ft1000dev->usbboot++;
		if (ft1000dev->usbboot == 1)
			ft1000_write_dpram16(ft1000dev,
					DWNLD_MAG1_PS_HDR_LOC, 0, 0);
	}
	return status;
}
예제 #5
0
u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
		u32 FileLength)
{
	u16 status = STATUS_SUCCESS;
	u32 state;
	u16 handshake;
	struct pseudo_hdr *pseudo_header;
	u16 pseudo_header_len;
	long word_length;
	u16 request;
	u16 temp;
	u16 tempword;

	struct dsp_file_hdr *file_hdr;
	struct dsp_image_info *dsp_img_info = NULL;
	long requested_version;
	bool correct_version;
	struct drv_msg *mailbox_data;
	u16 *data = NULL;
	u16 *s_file = NULL;
	u8 *c_file = NULL;
	u8 *boot_end = NULL, *code_end = NULL;
	int image;
	long loader_code_address, loader_code_size = 0;
	long run_address = 0, run_size = 0;

	u32 templong;
	u32 image_chksum = 0;

	u16 dpram = 0;
	u8 *pbuffer;
	struct prov_record *pprov_record;
	struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);

	DEBUG("Entered   scram_dnldr...\n");

	pft1000info->fcodeldr = 0;
	pft1000info->usbboot = 0;
	pft1000info->dspalive = 0xffff;

	//
	// Get version id of file, at first 4 bytes of file, for newer files.
	//

	state = STATE_START_DWNLD;

	file_hdr = (struct dsp_file_hdr *)pFileStart;

	ft1000_write_register(ft1000dev, 0x800, FT1000_REG_MAG_WATERMARK);

	s_file = (u16 *) (pFileStart + file_hdr->loader_offset);
	c_file = (u8 *) (pFileStart + file_hdr->loader_offset);

	boot_end = (u8 *) (pFileStart + file_hdr->loader_code_end);

	loader_code_address = file_hdr->loader_code_address;
	loader_code_size = file_hdr->loader_code_size;
	correct_version = FALSE;

	while ((status == STATUS_SUCCESS) && (state != STATE_DONE_FILE)) {
		switch (state) {
		case STATE_START_DWNLD:
			DEBUG("FT1000:STATE_START_DWNLD\n");
			if (pft1000info->usbboot)
				handshake =
				    get_handshake_usb(ft1000dev,
						      HANDSHAKE_DSP_BL_READY);
			else
				handshake =
				    get_handshake(ft1000dev,
						  HANDSHAKE_DSP_BL_READY);

			if (handshake == HANDSHAKE_DSP_BL_READY) {
				DEBUG
				    ("scram_dnldr: handshake is HANDSHAKE_DSP_BL_READY, call put_handshake(HANDSHAKE_DRIVER_READY)\n");
				put_handshake(ft1000dev,
					      HANDSHAKE_DRIVER_READY);
			} else {
				DEBUG
				    ("FT1000:download:Download error: Handshake failed\n");
				status = STATUS_FAILURE;
			}

			state = STATE_BOOT_DWNLD;

			break;

		case STATE_BOOT_DWNLD:
			DEBUG("FT1000:STATE_BOOT_DWNLD\n");
			pft1000info->bootmode = 1;
			handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST);
			if (handshake == HANDSHAKE_REQUEST) {
				/*
				 * Get type associated with the request.
				 */
				request = get_request_type(ft1000dev);
				switch (request) {
				case REQUEST_RUN_ADDRESS:
					DEBUG("FT1000:REQUEST_RUN_ADDRESS\n");
					put_request_value(ft1000dev,
							  loader_code_address);
					break;
				case REQUEST_CODE_LENGTH:
					DEBUG("FT1000:REQUEST_CODE_LENGTH\n");
					put_request_value(ft1000dev,
							  loader_code_size);
					break;
				case REQUEST_DONE_BL:
					DEBUG("FT1000:REQUEST_DONE_BL\n");
					/* Reposition ptrs to beginning of code section */
					s_file = (u16 *) (boot_end);
					c_file = (u8 *) (boot_end);
					//DEBUG("FT1000:download:s_file = 0x%8x\n", (int)s_file);
					//DEBUG("FT1000:download:c_file = 0x%8x\n", (int)c_file);
					state = STATE_CODE_DWNLD;
					pft1000info->fcodeldr = 1;
					break;
				case REQUEST_CODE_SEGMENT:
					//DEBUG("FT1000:REQUEST_CODE_SEGMENT\n");
					word_length =
					    get_request_value(ft1000dev);
					//DEBUG("FT1000:word_length = 0x%x\n", (int)word_length);
					//NdisMSleep (100);
					if (word_length > MAX_LENGTH) {
						DEBUG
						    ("FT1000:download:Download error: Max length exceeded\n");
						status = STATUS_FAILURE;
						break;
					}
					if ((word_length * 2 + c_file) >
					    boot_end) {
						/*
						 * Error, beyond boot code range.
						 */
						DEBUG
						    ("FT1000:download:Download error: Requested len=%d exceeds BOOT code boundary.\n",
						     (int)word_length);
						status = STATUS_FAILURE;
						break;
					}
					/*
					 * Position ASIC DPRAM auto-increment pointer.
					 */
					dpram = (u16) DWNLD_MAG1_PS_HDR_LOC;
					if (word_length & 0x1)
						word_length++;
					word_length = word_length / 2;

					status =
					    write_blk(ft1000dev, &s_file,
						      &c_file, word_length);
					//DEBUG("write_blk returned %d\n", status);
					break;
				default:
					DEBUG
					    ("FT1000:download:Download error: Bad request type=%d in BOOT download state.\n",
					     request);
					status = STATUS_FAILURE;
					break;
				}
				if (pft1000info->usbboot)
					put_handshake_usb(ft1000dev,
							  HANDSHAKE_RESPONSE);
				else
					put_handshake(ft1000dev,
						      HANDSHAKE_RESPONSE);
			} else {
				DEBUG
				    ("FT1000:download:Download error: Handshake failed\n");
				status = STATUS_FAILURE;
			}

			break;

		case STATE_CODE_DWNLD:
			//DEBUG("FT1000:STATE_CODE_DWNLD\n");
			pft1000info->bootmode = 0;
			if (pft1000info->usbboot)
				handshake =
				    get_handshake_usb(ft1000dev,
						      HANDSHAKE_REQUEST);
			else
				handshake =
				    get_handshake(ft1000dev, HANDSHAKE_REQUEST);
			if (handshake == HANDSHAKE_REQUEST) {
				/*
				 * Get type associated with the request.
				 */
				if (pft1000info->usbboot)
					request =
					    get_request_type_usb(ft1000dev);
				else
					request = get_request_type(ft1000dev);
				switch (request) {
				case REQUEST_FILE_CHECKSUM:
					DEBUG
					    ("FT1000:download:image_chksum = 0x%8x\n",
					     image_chksum);
					put_request_value(ft1000dev,
							  image_chksum);
					break;
				case REQUEST_RUN_ADDRESS:
					DEBUG
					    ("FT1000:download:  REQUEST_RUN_ADDRESS\n");
					if (correct_version) {
						DEBUG
						    ("FT1000:download:run_address = 0x%8x\n",
						     (int)run_address);
						put_request_value(ft1000dev,
								  run_address);
					} else {
						DEBUG
						    ("FT1000:download:Download error: Got Run address request before image offset request.\n");
						status = STATUS_FAILURE;
						break;
					}
					break;
				case REQUEST_CODE_LENGTH:
					DEBUG
					    ("FT1000:download:REQUEST_CODE_LENGTH\n");
					if (correct_version) {
						DEBUG
						    ("FT1000:download:run_size = 0x%8x\n",
						     (int)run_size);
						put_request_value(ft1000dev,
								  run_size);
					} else {
						DEBUG
						    ("FT1000:download:Download error: Got Size request before image offset request.\n");
						status = STATUS_FAILURE;
						break;
					}
					break;
				case REQUEST_DONE_CL:
					pft1000info->usbboot = 3;
					/* Reposition ptrs to beginning of provisioning section */
					s_file =
					    (u16 *) (pFileStart +
						     file_hdr->commands_offset);
					c_file =
					    (u8 *) (pFileStart +
						    file_hdr->commands_offset);
					state = STATE_DONE_DWNLD;
					break;
				case REQUEST_CODE_SEGMENT:
					//DEBUG("FT1000:download: REQUEST_CODE_SEGMENT - CODELOADER\n");
					if (!correct_version) {
						DEBUG
						    ("FT1000:download:Download error: Got Code Segment request before image offset request.\n");
						status = STATUS_FAILURE;
						break;
					}

					word_length =
					    get_request_value(ft1000dev);
					//DEBUG("FT1000:download:word_length = %d\n", (int)word_length);
					if (word_length > MAX_LENGTH) {
						DEBUG
						    ("FT1000:download:Download error: Max length exceeded\n");
						status = STATUS_FAILURE;
						break;
					}
					if ((word_length * 2 + c_file) >
					    code_end) {
						/*
						 * Error, beyond boot code range.
						 */
						DEBUG
						    ("FT1000:download:Download error: Requested len=%d exceeds DSP code boundary.\n",
						     (int)word_length);
						status = STATUS_FAILURE;
						break;
					}
					/*
					 * Position ASIC DPRAM auto-increment pointer.
					 */
					dpram = (u16) DWNLD_MAG1_PS_HDR_LOC;
					if (word_length & 0x1)
						word_length++;
					word_length = word_length / 2;

					write_blk_fifo(ft1000dev, &s_file,
						       &c_file, word_length);
					if (pft1000info->usbboot == 0)
						pft1000info->usbboot++;
					if (pft1000info->usbboot == 1) {
						tempword = 0;
						ft1000_write_dpram16(ft1000dev,
								     DWNLD_MAG1_PS_HDR_LOC,
								     tempword,
								     0);
					}

					break;

				case REQUEST_MAILBOX_DATA:
					DEBUG
					    ("FT1000:download: REQUEST_MAILBOX_DATA\n");
					// Convert length from byte count to word count. Make sure we round up.
					word_length =
					    (long)(pft1000info->DSPInfoBlklen +
						   1) / 2;
					put_request_value(ft1000dev,
							  word_length);
					mailbox_data =
					    (struct drv_msg *)&(pft1000info->
								DSPInfoBlk[0]);
					/*
					 * Position ASIC DPRAM auto-increment pointer.
					 */

					data = (u16 *) & mailbox_data->data[0];
					dpram = (u16) DWNLD_MAG1_PS_HDR_LOC;
					if (word_length & 0x1)
						word_length++;

					word_length = (word_length / 2);

					for (; word_length > 0; word_length--) {	/* In words */

						templong = *data++;
						templong |= (*data++ << 16);
						status =
						    fix_ft1000_write_dpram32
						    (ft1000dev, dpram++,
						     (u8 *) & templong);

					}
					break;

				case REQUEST_VERSION_INFO:
					DEBUG
					    ("FT1000:download:REQUEST_VERSION_INFO\n");
					word_length =
					    file_hdr->version_data_size;
					put_request_value(ft1000dev,
							  word_length);
					/*
					 * Position ASIC DPRAM auto-increment pointer.
					 */

					s_file =
					    (u16 *) (pFileStart +
						     file_hdr->
						     version_data_offset);

					dpram = (u16) DWNLD_MAG1_PS_HDR_LOC;
					if (word_length & 0x1)
						word_length++;

					word_length = (word_length / 2);

					for (; word_length > 0; word_length--) {	/* In words */

						templong = ntohs(*s_file++);
						temp = ntohs(*s_file++);
						templong |= (temp << 16);
						status =
						    fix_ft1000_write_dpram32
						    (ft1000dev, dpram++,
						     (u8 *) & templong);

					}
					break;

				case REQUEST_CODE_BY_VERSION:
					DEBUG
					    ("FT1000:download:REQUEST_CODE_BY_VERSION\n");
					correct_version = FALSE;
					requested_version =
					    get_request_value(ft1000dev);

					dsp_img_info =
					    (struct dsp_image_info *)(pFileStart
								      +
								      sizeof
								      (struct
								       dsp_file_hdr));

					for (image = 0;
					     image < file_hdr->nDspImages;
					     image++) {

						if (dsp_img_info->version ==
						    requested_version) {
							correct_version = TRUE;
							DEBUG
							    ("FT1000:download: correct_version is TRUE\n");
							s_file =
							    (u16 *) (pFileStart
								     +
								     dsp_img_info->
								     begin_offset);
							c_file =
							    (u8 *) (pFileStart +
								    dsp_img_info->
								    begin_offset);
							code_end =
							    (u8 *) (pFileStart +
								    dsp_img_info->
								    end_offset);
							run_address =
							    dsp_img_info->
							    run_address;
							run_size =
							    dsp_img_info->
							    image_size;
							image_chksum =
							    (u32) dsp_img_info->
							    checksum;
							break;
						}
						dsp_img_info++;

					}	//end of for

					if (!correct_version) {
						/*
						 * Error, beyond boot code range.
						 */
						DEBUG
						    ("FT1000:download:Download error: Bad Version Request = 0x%x.\n",
						     (int)requested_version);
						status = STATUS_FAILURE;
						break;
					}
					break;

				default:
					DEBUG
					    ("FT1000:download:Download error: Bad request type=%d in CODE download state.\n",
					     request);
					status = STATUS_FAILURE;
					break;
				}
				if (pft1000info->usbboot)
					put_handshake_usb(ft1000dev,
							  HANDSHAKE_RESPONSE);
				else
					put_handshake(ft1000dev,
						      HANDSHAKE_RESPONSE);
			} else {
				DEBUG
				    ("FT1000:download:Download error: Handshake failed\n");
				status = STATUS_FAILURE;
			}

			break;

		case STATE_DONE_DWNLD:
			DEBUG("FT1000:download:Code loader is done...\n");
			state = STATE_SECTION_PROV;
			break;

		case STATE_SECTION_PROV:
			DEBUG("FT1000:download:STATE_SECTION_PROV\n");
			pseudo_header = (struct pseudo_hdr *)c_file;

			if (pseudo_header->checksum ==
			    hdr_checksum(pseudo_header)) {
				if (pseudo_header->portdest !=
				    0x80 /* Dsp OAM */ ) {
					state = STATE_DONE_PROV;
					break;
				}
				pseudo_header_len = ntohs(pseudo_header->length);	/* Byte length for PROV records */

				// Get buffer for provisioning data
				pbuffer =
				    kmalloc((pseudo_header_len +
					     sizeof(struct pseudo_hdr)),
					    GFP_ATOMIC);
				if (pbuffer) {
					memcpy(pbuffer, (void *)c_file,
					       (u32) (pseudo_header_len +
						      sizeof(struct
							     pseudo_hdr)));
					// link provisioning data
					pprov_record =
					    kmalloc(sizeof(struct prov_record),
						    GFP_ATOMIC);
					if (pprov_record) {
						pprov_record->pprov_data =
						    pbuffer;
						list_add_tail(&pprov_record->
							      list,
							      &pft1000info->
							      prov_list);
						// Move to next entry if available
						c_file =
						    (u8 *) ((unsigned long)
							    c_file +
							    (u32) ((pseudo_header_len + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr));
						if ((unsigned long)(c_file) -
						    (unsigned long)(pFileStart)
						    >=
						    (unsigned long)FileLength) {
							state = STATE_DONE_FILE;
						}
					} else {
						kfree(pbuffer);
						status = STATUS_FAILURE;
					}
				} else {
					status = STATUS_FAILURE;
				}
			} else {
				/* Checksum did not compute */
				status = STATUS_FAILURE;
			}
			DEBUG
			    ("ft1000:download: after STATE_SECTION_PROV, state = %d, status= %d\n",
			     state, status);
			break;

		case STATE_DONE_PROV:
			DEBUG("FT1000:download:STATE_DONE_PROV\n");
			state = STATE_DONE_FILE;
			break;

		default:
			status = STATUS_FAILURE;
			break;
		}		/* End Switch */

		if (status != STATUS_SUCCESS) {
			break;
		}

/****
      // Check if Card is present
      status = Harley_Read_Register(&temp, FT1000_REG_SUP_IMASK);
      if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0x0000) ) {
          break;
      }

      status = Harley_Read_Register(&temp, FT1000_REG_ASIC_ID);
      if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0xffff) ) {
          break;
      }
****/

	}			/* End while */

	DEBUG("Download exiting with status = 0x%8x\n", status);
	ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
			      FT1000_REG_DOORBELL);

	return status;
}
예제 #6
0
파일: utils2.c 프로젝트: rroart/freevms
void create_ods2(FILE *fout, char *volname, int volsize)
{
    unsigned char out_line[512];
    int i;
    struct _hm2 *pHM2$;
    struct _fh2 *pFH2;
    struct FM2_C_FORMAT2 *pFM2;
    struct _fi2*pFI2;

//volume name and size
    strcpy(volnam, volname);
    volumesize=volsize;

//cluster size...
    if (volumesize<=50000)
        clustersize=1;
    else
    {
        clustersize = roundup( ((double) volumesize)/(255 * 4096));
        if (clustersize<3) clustersize=3;
    }
    clustersize=17;
//maxfiles
    maxfiles=volumesize/((clustersize+1)*2);
    if (maxfiles>(volumesize/(clustersize+1))) maxfiles=volumesize/(clustersize+1);
//indefilesize
    indexfilesize=((4*clustersize)+roundup(((double) maxfiles)/4096)+16);
    diffsizeindexf=indexfilesize;
    indexfilesize=clustersize*roundup((double) indexfilesize/clustersize);
    diffsizeindexf=indexfilesize-diffsizeindexf;
//
    printf("Initialize device Version 0.2b\n");
    printf("Volume Size %d Cluster %d Maxfiles %d\n", volumesize, clustersize, maxfiles);
    printf("Indexfile size %d\n", indexfilesize);

//Cluster 1, 2 and 3

    //Boot Block: don't know what to do, just put all to 0
    for(i=0; i<512; i++) out_line[i]=0;
    write_blk(out_line, fout, "Boot block");

    //Home Block: construct
    pHM2$ = (struct _hm2 *) out_line;
    pHM2$->hm2$l_homelbn=1;
    pHM2$->hm2$w_homevbn=2;
    pHM2$->hm2$l_alhomelbn=clustersize*2;
    pHM2$->hm2$w_alhomevbn=clustersize*2+1;
    pHM2$->hm2$l_altidxlbn=clustersize*3;
    pHM2$->hm2$w_altidxvbn=clustersize*3+1;
    pHM2$->hm2$w_struclev=2*256+1;
    pHM2$->hm2$w_cluster=clustersize;
    pHM2$->hm2$w_ibmapvbn=VMSWORD(clustersize*4+1);
    pHM2$->hm2$l_ibmaplbn=VMSLONG(clustersize*4);
    ibmaplbn=pHM2$->hm2$l_ibmaplbn;
    pHM2$->hm2$l_maxfiles=(maxfiles);
    pHM2$->hm2$w_ibmapsize=VMSWORD(roundup( ( (double) pHM2$->hm2$l_maxfiles)/4096 ));
    ibmapsize=pHM2$->hm2$w_ibmapsize;
    pHM2$->hm2$w_resfiles=10;
    do_checksum_count(out_line,(short *)&pHM2$->hm2$w_checksum1-(short*)pHM2$);
    pHM2$->hm2$w_extend=clustersize;
    strcpy(pHM2$->hm2$t_strucname,"            ");
    strcpy(pHM2$->hm2$t_volname , volnam);
    strcpy(pHM2$->hm2$t_ownername, owner);
    strcpy(pHM2$->hm2$t_format,   "DECFILE11B  ");
    do_checksum(out_line);
    write_blk(out_line, fout, "first home Block\0"); //write first home block

    for(i=0; i<3*clustersize-2; i++) //fill the rest of the cluster and the next two clusters
    {
        pHM2$->hm2$l_homelbn=2+i;
        pHM2$->hm2$w_homevbn=3+i;
        write_blk(out_line, fout, "\0");
    }

// Cluster 4
    //Backup Index File Header
    for(i=0; i<512; i++) out_line[i]=0; //clear all

    //index file header:
    // header area
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=1;
    pFH2->fh2$w_fid.fid$w_seq=1;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"INDEXF.SYS;1");
    // map area
    pFM2 = (struct FM2_C_FORMAT2 *) (out_line+(2*pFH2->fh2$b_mpoffset));
    pFM2->fm2$w_word0=(ibmaplbn+ibmapsize)-1+16384; //Add 16384 for format type
    pFM2->fm2$v_count2=0;
    pFM2++;
    pFM2->fm2$w_word0=16-1+16384;
    pFM2->fm2$v_count2=ibmaplbn+ibmapsize;
    pFM2++;
#if 0
    pFM2->fm2$w_word0=indexfilesize-(pHM2$->hm2$l_ibmaplbn+pHM2$->hm2$w_ibmapsize+16)-1+16384;
    pFM2->fm2$v_count2=pHM2$->hm2$l_ibmaplbn+pHM2$->hm2$w_ibmapsize;
#endif
    pFH2->fh2$b_map_inuse=2*2;
    //file attribs
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=512;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(indexfilesize-diffsizeindexf);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(indexfilesize-diffsizeindexf+1); //not sure
    pFH2->fh2$w_recattr.fat$w_maxrec=512;
    do_checksum(out_line);
    write_blk(out_line, fout, "Backup Indexfile header"); //write down index file header

    // (the rest of the cluster is not used)
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    for(i=0; i<clustersize-1; i++) write_blk(out_line, fout, "\0");

// index file bitmap
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    int j = roundup(((double) maxfiles)/4096); //nbr of blocks in IFB
    out_line[0]=(unsigned char) 255;
    out_line[1]=(unsigned char) 1;   //files with number 1 to 9 reserved
    write_blk(out_line, fout, "Indexfile bitmap");
    for(i=0; i<512; i++) out_line[i]=0;  //clear all
    for(i=0; i<j-1; i++) write_blk(out_line, fout, "\0"); //rest of bitmap index

//index file header: Yeah once again !!!
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=VMSWORD(1);
    pFH2->fh2$w_fid.fid$w_seq=VMSWORD(1);
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"INDEXF.SYS;1");
    // map area
    pFM2 = (struct FM2_C_FORMAT2 *) (out_line+(2*pFH2->fh2$b_mpoffset));
    pFM2->fm2$w_word0=(ibmaplbn+ibmapsize)-1+16384; //Add 16384 for format type
    pFM2->fm2$v_count2=0;
    pFM2++;
    pFM2->fm2$w_word0=16-1+16384;
    pFM2->fm2$v_count2=ibmaplbn+ibmapsize;
    pFM2++;
#if 0
    pFM2->fm2$w_word0=indexfilesize-(pHM2$->hm2$l_ibmaplbn+pHM2$->hm2$w_ibmapsize+16)-1+16384;
    pFM2->fm2$v_count2=pHM2$->hm2$l_ibmaplbn+pHM2$->hm2$w_ibmapsize;
#endif
    pFH2->fh2$b_map_inuse=2*2;
    //file attribs
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=VMSWORD(512);
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(indexfilesize);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(indexfilesize-diffsizeindexf+1); //not sure
    pFH2->fh2$l_highwater=VMSLONG(indexfilesize+1);
    pFH2->fh2$w_recattr.fat$w_maxrec=VMSWORD(512);
    do_checksum(out_line);
    write_blk(out_line, fout, "Index file header"); //write down index file header

// header area 2.2 BITMAP.SYS;1
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    //pFH2->fh2$l_filechar[0]=128;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=2;
    pFH2->fh2$w_fid.fid$w_seq=2;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"BITMAP.SYS;1");
    // map area
    pFM2 = (struct FM2_C_FORMAT2 *) (out_line+(2*pFH2->fh2$b_mpoffset));
    storagebitmapsize=roundup( ( (double) (volumesize/clustersize))/4096);
    bitmapfilesize=clustersize*(roundup(((double) (storagebitmapsize+1))/clustersize));
    diffsizebitmap=bitmapfilesize-1-storagebitmapsize;
    pFM2->fm2$w_word0=bitmapfilesize-1+16384;
    pFM2->fm2$v_count2=(indexfilesize+clustersize);
    pFH2->fh2$b_map_inuse=2;
    //file attribs
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=512;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(bitmapfilesize);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(bitmapfilesize-diffsizebitmap+1);
    pFH2->fh2$l_highwater=VMSLONG(bitmapfilesize);
    pFH2->fh2$w_recattr.fat$w_maxrec=512;
    do_checksum(out_line);
    write_blk(out_line, fout, "bitmap.sys header"); //write down bitmap file header

// header area 3.3 BADBLK.SYS;1
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=3;
    pFH2->fh2$w_fid.fid$w_seq=3;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"BADBLK.SYS;1");
    // no map area
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=512;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(0);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(1);
    pFH2->fh2$l_highwater=VMSSWAP(1);
    pFH2->fh2$w_recattr.fat$w_maxrec=512;
    do_checksum(out_line);
    write_blk(out_line, fout, "badblk.sys header"); //write down file header

// header area 4.4 000000.DIR;1
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$l_filechar=128+256*32; // directory flags
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=4;
    pFH2->fh2$w_fid.fid$w_seq=4;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"000000.DIR;1");
    // map area
    pFM2 = (struct FM2_C_FORMAT2 *) (out_line+(2*pFH2->fh2$b_mpoffset));
    pFM2->fm2$w_word0=(clustersize-1)+16384;
    pFM2->fm2$v_count2=indexfilesize;
    pFH2->fh2$b_map_inuse=2; //3;
    pFH2->fh2$w_recattr.fat$b_rtype=2;
    pFH2->fh2$w_recattr.fat$b_rattrib=8;
    pFH2->fh2$w_recattr.fat$w_rsize=512;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(clustersize);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(2);
    pFH2->fh2$l_highwater=VMSSWAP(clustersize);
    pFH2->fh2$w_recattr.fat$w_maxrec=512;
    // seems .dir does not use this? pFH2->fh2$w_recattr.fat$w_ffbyte=216;
    do_checksum(out_line);
    write_blk(out_line, fout, "000000.dir header"); //write down file header

// header area 5.5 CORIMG.SYS;1
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=5;
    pFH2->fh2$w_fid.fid$w_seq=5;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"CORIMG.SYS;1");
    // no map area
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=512;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(0);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(1);
    pFH2->fh2$w_recattr.fat$w_maxrec=512;
    do_checksum(out_line);
    write_blk(out_line, fout, "corimg.sys header"); //write down file header

// header area 6.6 VOLSET.SYS;1
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=6;
    pFH2->fh2$w_fid.fid$w_seq=6;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"VOLSET.SYS;1");
    // no map area
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=64;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(0);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(1);
    pFH2->fh2$w_recattr.fat$w_maxrec=64;
    do_checksum(out_line);
    write_blk(out_line, fout, "volset.sys header"); //write down file header

// header area 7.7 CONTIN.SYS;1
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=7;
    pFH2->fh2$w_fid.fid$w_seq=7;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"CONTIN.SYS;1");
    // no map area
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=512;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(0);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(1);
    pFH2->fh2$w_recattr.fat$w_maxrec=512;
    do_checksum(out_line);
    write_blk(out_line, fout, "contin.sys header"); //write down file header

// header area 8.8 BACKUP.SYS;1
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=8;
    pFH2->fh2$w_fid.fid$w_seq=8;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"BACKUP.SYS;1");
    // no map area
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=64;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(0);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(1);
    pFH2->fh2$w_recattr.fat$w_maxrec=64;
    do_checksum(out_line);
    write_blk(out_line, fout, "backup.sys header"); //write down file header

// header area 9.9 BADLOG.SYS;1
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pFH2 = (struct _fh2 *) out_line;
    pFH2->fh2$b_idoffset=40;
    pFH2->fh2$b_mpoffset=100;
    pFH2->fh2$b_acoffset=255;
    pFH2->fh2$b_rsoffset=255;
    pFH2->fh2$w_seg_num=0;
    pFH2->fh2$w_struclev=2*256+1;
    pFH2->fh2$w_fid.fid$w_num=9;
    pFH2->fh2$w_fid.fid$w_seq=9;
    pFH2->fh2$w_fid.fid$b_rvn=0;
    pFH2->fh2$w_backlink.fid$w_num=4;
    pFH2->fh2$w_backlink.fid$w_seq=4;
    pFH2->fh2$w_backlink.fid$b_rvn=0;
    // identification area
    pFI2 = (struct _fi2*) (out_line+2*pFH2->fh2$b_idoffset);
    strcpy(pFI2->fi2$t_filename,"BADLOG.SYS;1");
    // no map area
    pFH2->fh2$w_recattr.fat$b_rtype=1;
    pFH2->fh2$w_recattr.fat$w_rsize=16;
    pFH2->fh2$w_recattr.fat$l_hiblk=VMSSWAP(0);
    pFH2->fh2$w_recattr.fat$l_efblk=VMSSWAP(1);
    pFH2->fh2$w_recattr.fat$w_maxrec=16;
    do_checksum(out_line);
    write_blk(out_line, fout, "badlog.sys header"); //write down file header

    for(i=0; i<512; i++) out_line[i]=0; //clear all

    for(i=0; i<7; i++) write_blk(out_line, fout, ""); // complete 16 file headers
    for(i=0; i<diffsizeindexf; i++) write_blk(out_line, fout, ""); // write until next cluster !

// All Above IS actually the INDEXF.SYS. Now:
// create 000000.DIR, files are in alphabetical order
    int pos=0;
    struct _dir  *pDIR;
    struct _dir1 *pDIR1;
    for(i=0; i<512; i++) out_line[i]=0; //clear all

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"000000.DIR");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=4;
    pDIR1->dir$fid.fid$w_seq=4;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"BACKUP.SYS");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=8;
    pDIR1->dir$fid.fid$w_seq=8;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"BADBLK.SYS");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=3;
    pDIR1->dir$fid.fid$w_seq=3;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"BADLOG.SYS");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=9;
    pDIR1->dir$fid.fid$w_seq=9;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"BITMAP.SYS");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=2;
    pDIR1->dir$fid.fid$w_seq=2;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"CONTIN.SYS");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=7;
    pDIR1->dir$fid.fid$w_seq=7;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"CORIMG.SYS");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=5;
    pDIR1->dir$fid.fid$w_seq=5;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"INDEXF.SYS");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=1;
    pDIR1->dir$fid.fid$w_seq=1;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    pDIR = (struct _dir *) (out_line+pos);
    pDIR1 = (struct _dir1 *) (out_line+pos+16);
    pDIR->dir$w_size=22;
    pos=pos+24;
    strcpy(pDIR->dir$t_name,"VOLSET.SYS");
    pDIR->dir$b_namecount=10;
    pDIR1->dir$fid.fid$w_num=6;
    pDIR1->dir$fid.fid$w_seq=6;
    pDIR->dir$w_verlimit=1;
    pDIR->dir$b_flags=0;
    pDIR1->dir$w_version=1;
    pDIR1->dir$fid.fid$b_rvn=0;
    pDIR1->dir$fid.fid$b_nmx=0;

    out_line[pos]=255;
    out_line[pos+1]=255; // (-1) word

    write_blk(out_line, fout, "directory file"); //write directory file - only one record, but one cluster is used
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    for(i=0; i<clustersize-1; i++) write_blk(out_line, fout, "");

// create BITMAP.SYS
    //write storage control block
    struct _scbdef *pSCB;
    for(i=0; i<512; i++) out_line[i]=0; //clear all
    pSCB = (struct _scbdef *) out_line;
    pSCB->scb$w_struclev=2*256+1;
    pSCB->scb$w_cluster=clustersize;
    pSCB->scb$l_volsize=volumesize;
    pSCB->scb$l_blksize=16065;
    pSCB->scb$l_sectors=63;
    pSCB->scb$l_tracks=255;
    pSCB->scb$l_cylinders=4998;
    do_checksum(out_line);
    write_blk(out_line, fout, "bitmap.sys SCB"); //write storage control block, some missing information...

    //storage bitmap

    // nbr of clusters on volume = volumesize/clustersize, at worse we loose clustersize-1 blocks
    int nbrcluster=volumesize/clustersize;

    // nbr of blocks in storage bitmap = roundup( ( (double) (volumesize/clustersize))/4096);
    //storagebitmapsize=roundup( ( (double) (volumesize/clustersize))/4096);
    for(i=0; i<512; i++) out_line[i]=255; //make all 512 first clusters free

    //(indexfilesize/clustersize+bitmapfilesize/clustersize+clustersize) clusters will be used.
    // indexf.sys + bitmap.sys + 000000.dir
    //It cannot be more that 512, and don't ask me why...
    int usedclusters=(indexfilesize/clustersize)+(bitmapfilesize/clustersize)+1;
    j=0;
    while(j<usedclusters)
    {
        out_line[j/8] = out_line[j/8] << 1;
        j++;
    }
    if (storagebitmapsize > 1)
    {
        write_blk(out_line, fout, "storage bitmap");

        for(i=0; i<512; i++) out_line[i]=255; //make rest of clusters free, except last one
        for(i=0; i<storagebitmapsize-2; i++) write_blk(out_line, fout, "");
    }
    j=(storagebitmapsize*4096)-nbrcluster;  //last block, some cluster bits are unusable
    i=0;
    while(i<j)
    {
        out_line[511-(i/8)] = out_line[511-(i/8)] >> 1;
        i++;
    }
    if (storagebitmapsize > 1)
        write_blk(out_line, fout, "");
    else
        write_blk(out_line, fout, "storage bitmap");
    for(i=0; i<512; i++) out_line[i]=0;
    for(i=0; i<diffsizebitmap; i++) write_blk(out_line, fout, ""); // write until next cluster !

    for(i=0; i<512; i++) out_line[i]=0;
    printf("Clearing %d blocks\n",volumesize-(usedclusters*clustersize));
    for(i=0; i<volumesize-(usedclusters*clustersize); i++) write_blk(out_line, fout, "");
}