int thesmurFS_truncate(const char* path, off_t size) {
    char* physical_path;
    char* path_copy;
    int r;
    if(get_physical_path(path, &physical_path) == -1) {
        //emergency_output("ENOMEM");
        return -errno;
    }
    //emergency_output("truncating:");
    //emergency_output(path);
    //emergency_output_plus_n("new size", size);
    r = truncate(physical_path, size);
    //emergency_output_plus_n("truncate returns", r);
    if(r == -1) {
        return -errno;
        //emergency_output_plus_n("truncate errno", errno);
        //emergency_output("-----truncate");
    }
    //emergency_output("-----truncate");
    
    //emergency_output("truncate - update hash");
    //emergency_output(physical_path);
    path_copy = calloc(strlen(physical_path)+1, sizeof(char));
    memcpy(path_copy, physical_path, strlen(physical_path)+1);
    update_hash_file(path_copy);
    make_parent_dir(path_copy);
    update_hash_folder(path_copy, 1);
    free(path_copy);
    
    return r;
}
int thesmurFS_create(const char* path, mode_t mod, struct fuse_file_info* fi) {
    char* physical_path;
    char* path_copy;
    int fd;
    //emergency_output("create");
    if(get_physical_path(path, &physical_path) == -1) {
        //emergency_output("ENOMEM");
        return -errno;
    }
    fd = creat(physical_path, mod);
    if(fd<0)
        return -errno;
    fi->fh = fd;
    
    //emergency_output("create - update hash");
    //emergency_output(physical_path);
    path_copy = calloc(strlen(physical_path)+1, sizeof(char));
    memcpy(path_copy, physical_path, strlen(physical_path)+1);
    update_hash_file(path_copy);
    make_parent_dir(path_copy);
    update_hash_folder(path_copy, 1);
    free(path_copy);
    
    return 0;
}
Exemple #3
0
/**
 * Callback function to process a file found while recursively traversing
 * a directory.
 *
 * @param filepath path to the file
 * @param type file attributes
 * @param data the paramater specified, when calling find_file(). It shall be
 *             non-zero for printing SFV header, zero for actual processing.
 */
static int find_file_callback(const char* filepath, int type, void* data)
{
	int res = 0;
	if( !(type & FIND_IFDIR) ) {
		if(data) {
			if(!file_mask_match(opt.files_accept, filepath)) return 0;
			if(filepath[0] == '.' && IS_PATH_SEPARATOR(filepath[1])) filepath += 2;
			/* TODO: get size, fill file struct */
			print_sfv_header_line(rhash_data.out, filepath, filepath);
			/* rhash_data.total_size += file.size */
		} else {
			/* only check an update modes use crc_accept mask */
			file_mask_array* masks = (opt.mode & (MODE_CHECK | MODE_UPDATE) ?
				opt.crc_accept : opt.files_accept);
			if(!file_mask_match(masks, filepath)) return 0;

			if(opt.mode & (MODE_CHECK | MODE_CHECK_EMBEDDED)) {
				res = check_hash_file(filepath, 1);
			} else {
				if(opt.mode & MODE_UPDATE) {
					res = update_hash_file(filepath);
				} else {
					/* default mode: calculate hash */
					if(filepath[0] == '.' && IS_PATH_SEPARATOR(filepath[1])) filepath += 2;
					res = calculate_and_print_sums(rhash_data.out, filepath, filepath, NULL);
					rhash_data.processed++;
				}
			}
		}
	}
	if(res < 0) rhash_data.error_flag = 1;
	return 1;
}
Exemple #4
0
/**
 * Hash, check or update files according to work mode.
 */
static void process_files(void)
{
	timedelta_t timer;
	struct rsh_stat_struct stat_buf;
	int i;
	rhash_timer_start(&timer);
	rhash_data.processed = 0;

	/* process filenames */
	for(i = 0; i < opt.n_files; i++) {
		int res = 0;
		char* filepath = opt.files[i];
		stat_buf.st_mode = 0;

		if(!IS_DASH_STR(filepath) && rsh_stat(filepath, &stat_buf) < 0) {
			log_file_error(filepath);
			continue;
		}
		if(opt.flags & OPT_RECURSIVE) {
			if(S_ISDIR(stat_buf.st_mode)) {
				find_file(filepath, find_file_callback, 0, opt.find_max_depth, NULL);
				continue;
			}
		} else {
			if(S_ISDIR(stat_buf.st_mode)){
				if(opt.flags & OPT_VERBOSE){
					log_warning(_("%s: is a directory\n"), filepath);
				}
				continue;
			}
		}

		if(opt.mode & (MODE_CHECK | MODE_CHECK_EMBEDDED)) {
			res = check_hash_file(filepath, 0);
		} else if(opt.mode & MODE_UPDATE) {
			res = update_hash_file(filepath);
		} else {
			res = calculate_and_print_sums(rhash_data.out, filepath, filepath, &stat_buf);
			rhash_data.processed++;
		}
		if(res < 0) rhash_data.error_flag = 1;
	}

	if((opt.mode & MODE_CHECK_EMBEDDED) && rhash_data.processed > 1) {
		print_check_stats();
	}

	if((opt.flags & OPT_SPEED) && !(opt.mode&(MODE_CHECK | MODE_UPDATE)) &&
		rhash_data.processed > 1) {
			double time = rhash_timer_stop(&timer);
			print_time_stats(time, rhash_data.total_size, 1);
	}
}
int thesmurFS_mknod(const char* path, mode_t mod, dev_t dev) {
    char* physical_path;
    int r;
    //emergency_output("mknod");
    if(get_physical_path(path, &physical_path) == -1) {
        //emergency_output("ENOMEM");
        return -errno;
    }
    r = mknod(physical_path, mod, dev);
    if(r<0)
        return -errno;
    update_hash_file(physical_path);
    return r;
}
Exemple #6
0
/**
 * Callback function to process files while recursively traversing a directory.
 * It hashes, checks or updates a file according to the current work mode.
 *
 * @param file the file to process
 * @param preprocess non-zero when preprocessing files, zero for actual processing.
 */
static int find_file_callback(file_t* file, int preprocess)
{
	int res = 0;
	assert(!FILE_ISDIR(file));
	assert(opt.search_data);

	if (rhash_data.interrupted) {
		opt.search_data->options |= FIND_CANCEL;
		return 0;
	}

	if (preprocess) {
		if (!file_mask_match(opt.files_accept, file->path) || must_skip_file(file)) {
			return 0;
		}

		if (opt.fmt & FMT_SFV) {
			print_sfv_header_line(rhash_data.out, file, 0);
		}

		rhash_data.batch_size += file->size;
	} else {
		int not_root = !(file->mode & FILE_IFROOT);

		if (not_root) {
			/* only check and update modes use the crc_accept mask */
			file_mask_array* masks = (opt.mode & (MODE_CHECK | MODE_UPDATE) ?
				opt.crc_accept : opt.files_accept);
			if (!file_mask_match(masks, file->path)) return 0;
		}
		if (must_skip_file(file)) return 0;

		if (opt.mode & (MODE_CHECK | MODE_CHECK_EMBEDDED)) {
			res = check_hash_file(file, not_root);
		} else {
			if (opt.mode & MODE_UPDATE) {
				res = update_hash_file(file);
			} else {
				/* default mode: calculate hash */
				const char* print_path = file->path;
				if (print_path[0] == '.' && IS_PATH_SEPARATOR(print_path[1])) print_path += 2;
				res = calculate_and_print_sums(rhash_data.out, file, print_path);
				if (rhash_data.interrupted) return 0;
				rhash_data.processed++;
			}
		}
	}
	if (res < 0) rhash_data.error_flag = 1;
	return 1;
}
int thesmurFS_release(const char* path, struct fuse_file_info *fi) {
    char* path_copy;
    int r;
    //emergency_output("release");
    //get_physical_path(path, &physical_path);
    r = close(fi->fh);
    if(r == -1)
        return -errno;
    
    
    get_physical_path(path, &path_copy);
    //emergency_output("release - update hash");
    //emergency_output(path_copy);
    update_hash_file(path_copy);
    make_parent_dir(path_copy);
    update_hash_folder(path_copy, 1);
    free(path_copy);
    
    return r;
}