<commit_before>#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "fs.h"

int main(int argc, char *argv[])
{
	struct ghostfs *gfs;
	int ret;

	if (argc < 2) {
		printf("usage: ghost <file> <cmd> {args}\n");
		return 1;
	}

	if (argc == 3 && argv[2][0] == 'f') {
		ret = ghostfs_format(argv[1]);
		if (ret < 0)
			goto failed;
		return 0;
	}

	ret = ghostfs_mount(&gfs, argv[1]);
	if (ret < 0)
		goto failed;

	printf("cluster count = %d\n", ghostfs_cluster_count(gfs));

	if (argc < 3)
		return 0;

	switch (argv[2][0]) {
	case 'c':
		if (argc != 4) {
			printf("create: missing filename\n");
			return 1;
		}
		ret = ghostfs_create(gfs, argv[3]);
		if (ret < 0)
			goto failed;
		break;
	case 'd':
		if (argc != 4) {
			printf("mkdir: missing filename\n");
			return 1;
		}
		ret = ghostfs_mkdir(gfs, argv[3]);
		if (ret < 0)
			goto failed;
		break;
	case 'r':
		if (argc != 4) {
			printf("unlink: missing filename\n");
			return 1;
		}
		ret = ghostfs_unlink(gfs, argv[3]);
		if (ret < 0)
			goto failed;
		break;
	case 'R':
		if (argc != 4) {
			printf("rmdir: missing filename\n");
			return 1;
		}
		ret = ghostfs_rmdir(gfs, argv[3]);
		if (ret < 0)
			goto failed;
		break;
	case 't':
		if (argc != 5) {
			printf("truncate: missing filename and size\n");
			return 1;
		}
		ret = ghostfs_truncate(gfs, argv[3], atol(argv[4]));
		if (ret < 0)
			goto failed;
		break;
	case '?':
		ghostfs_debug(gfs);<commit_msg>ghost: Add write test<commit_after>#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "fs.h"

int main(int argc, char *argv[])
{
	struct ghostfs *gfs;
	int ret;

	if (argc < 2) {
		printf("usage: ghost <file> <cmd> {args}\n");
		return 1;
	}

	if (argc == 3 && argv[2][0] == 'f') {
		ret = ghostfs_format(argv[1]);
		if (ret < 0)
			goto failed;
		return 0;
	}

	ret = ghostfs_mount(&gfs, argv[1]);
	if (ret < 0)
		goto failed;

	printf("cluster count = %d\n", ghostfs_cluster_count(gfs));

	if (argc < 3)
		return 0;

	switch (argv[2][0]) {
	case 'c':
		if (argc != 4) {
			printf("create: missing filename\n");
			return 1;
		}
		ret = ghostfs_create(gfs, argv[3]);
		if (ret < 0)
			goto failed;
		break;
	case 'd':
		if (argc != 4) {
			printf("mkdir: missing filename\n");
			return 1;
		}
		ret = ghostfs_mkdir(gfs, argv[3]);
		if (ret < 0)
			goto failed;
		break;
	case 'r':
		if (argc != 4) {
			printf("unlink: missing filename\n");
			return 1;
		}
		ret = ghostfs_unlink(gfs, argv[3]);
		if (ret < 0)
			goto failed;
		break;
	case 'R':
		if (argc != 4) {
			printf("rmdir: missing filename\n");
			return 1;
		}
		ret = ghostfs_rmdir(gfs, argv[3]);
		if (ret < 0)
			goto failed;
		break;
	case 't':
		if (argc != 5) {
			printf("truncate: missing filename and size\n");
			return 1;
		}
		ret = ghostfs_truncate(gfs, argv[3], atol(argv[4]));
		if (ret < 0)
			goto failed;
		break;
	case '1': {
		struct ghostfs_entry *e;

		if (argc != 5) {
			printf("write test: missing filename and offset\n");
			return 1;
		}

		ret = ghostfs_open(gfs, argv[3], &e);
		if (ret < 0)
			goto failed;

		ret = ghostfs_write(gfs, e, "Hello World!", 12, atol(argv[4]));
		if (ret < 0)
			goto failed;

		ghostfs_release(gfs, e);
		break;
	}
	case '?':
		ghostfs_debug(gfs);
{'fraction_non_alphanumeric': 0.1831422373721723, 'fraction_numerical': 0.024480942051440968, 'mean_word_length': 3.065491183879093, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 13, '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': '541564', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1359, 'n_words': 364}