<commit_before>/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <<EMAIL>> wrote this file.  As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return.   <NAME>
 * ----------------------------------------------------------------------------
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/disklabel.h>
#include <sys/diskslice.h>
#include <sys/diskmbr.h>
#include <paths.h>
#include "libdisk.h"

/* XXX: A lot of hardcoded 512s probably should be foo->sector_size;
        I'm not sure which, so I leave it like it worked before. --schweikh */
static int
Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, const struct chunk *c1)
{
	struct disklabel *dl;
	int i;
	void *p;
	u_char buf[BBSIZE];
	u_long *lp, sum;

	for(i = 0; i < BBSIZE/512; i++) {
		p = read_block(fd, i + c1->offset, 512);
		memcpy(buf + 512 * i, p, 512);
		free(p);
	}
	if(new->boot1)
		memcpy(buf + 512, new->boot1, BBSIZE-512);

	dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
	Fill_Disklabel(dl, new, old, c1);

	/*
	 * Tell SRM where the bootstrap is.
	 */
	lp = (u_long *)buf;
	lp[60] = 15;
	lp[61] = 1;
	lp[62] = 0;

	/*
	 * Generate the bootblock checksum for the SRM console.
	 */
	for (lp = (u_long *)buf, i = 0, sum = 0; i < 63; i++)
	    sum += lp[i];
	lp[63] = sum;

	for(i=0;i<BBSIZE/512;i++) {
		write_block(fd, i + c1->offset, buf + 512 * i, 512);
	}

	return 0;
}



int
Write_Disk(const struct disk *d1)
{
	int fd;
	struct disk *old = 0;
	struct chunk *c1;
	int ret = 0;
	char device[64];
	u_char *mbr;
	struct dos_partition *dp,work[NDOSPART];
	int s[4];

	strcpy(device,_PATH_DEV);
        strcat(device,d1->name);


        fd = open(device,O_RDWR);
        if (fd < 0)
                return 1;

	memset(s,0,sizeof s);
	mbr = read_block(fd, 0, d1->sector_size);
	dp = (struct dos_partition*)(mbr + DOSPARTOFF);
	memcpy(work, dp, sizeof work);
	dp = work;
	free(mbr);
	for (c1 = d1->chunks->part; c1; c1 = c1->next) {
		if (c1->type == unused) continue;
		if (!strcmp(c1->name, "X")) continue;
		if (c1->type == freebsd)
			ret += Write_FreeBSD(fd, d1, old, c1);
<commit_msg>Untested alpha disk writer.<commit_after>/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <<EMAIL>> wrote this file.  As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return.   <NAME>
 * ----------------------------------------------------------------------------
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/disklabel.h>
#include <sys/diskslice.h>
#include <sys/diskmbr.h>
#include <paths.h>
#include "libdisk.h"

/* XXX: A lot of hardcoded 512s probably should be foo->sector_size;
        I'm not sure which, so I leave it like it worked before. --schweikh */
static int
Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, const struct chunk *c1)
{
	struct disklabel *dl;
	int i;
	void *p;
	u_char buf[BBSIZE];
	u_long *lp, sum;

	for(i = 0; i < BBSIZE/512; i++) {
		p = read_block(fd, i + c1->offset, 512);
		memcpy(buf + 512 * i, p, 512);
		free(p);
	}
	if(new->boot1)
		memcpy(buf + 512, new->boot1, BBSIZE-512);

	dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
	Fill_Disklabel(dl, new, old, c1);

	/*
	 * Tell SRM where the bootstrap is.
	 */
	lp = (u_long *)buf;
	lp[60] = 15;
	lp[61] = 1;
	lp[62] = 0;

	/*
	 * Generate the bootblock checksum for the SRM console.
	 */
	for (lp = (u_long *)buf, i = 0, sum = 0; i < 63; i++)
	    sum += lp[i];
	lp[63] = sum;

	for(i=0;i<BBSIZE/512;i++) {
		write_block(fd, i + c1->offset, buf + 512 * i, 512);
	}

	return 0;
}



int
Write_Disk(const struct disk *d1)
{
	int fd;
	struct disk *old = 0;
	struct chunk *c1;
	int ret = 0;
	char device[64];
	u_char *mbr;
	struct dos_partition *dp,work[NDOSPART];
	int s[4];

	strcpy(device,_PATH_DEV);
        strcat(device,d1->name);


        fd = open(device,O_RDWR);
        if (fd < 0)
                return 1;

	memset(s,0,sizeof s);
	mbr = read_block(fd, 0, d1->sector_size);
	dp = (struct dos_partition*)(mbr + DOSPARTOFF);
	memcpy(work, dp, sizeof work);
	dp = work;
	free(mbr);
	for (c1 = d1->chunks->part->part; c1; c1 = c1->next) {
		if (c1->type == unused) continue;
		if (!strcmp(c1->name, "X")) continue;
		if (c1->type == freebsd)
			ret += Write_FreeBSD(fd, d1, old, c1);

{'fraction_non_alphanumeric': 0.21769662921348315, 'fraction_numerical': 0.03330658105939005, 'mean_word_length': 2.5811781609195403, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1439977', 'n_tokens_mistral': 2092, 'n_tokens_neox': 1910, 'n_words': 567}