コード例 #1
0
ファイル: lmessage.c プロジェクト: BackupTheBerlios/hsc-svn
VOID hsc_message(HSCPRC * hp, HSCMSG_ID msg_id, const char *format,...)
{
    HSCMSG_CLASS msg_class = hsc_get_msg_class(hp, msg_id);
    HSCMSG_ID msg_id_unmasked = msg_id & MASK_MESSAGE;
    INFILE *msg_inpf = NULL;
    STRPTR msg_fname = "unknown";
    ULONG msg_x = 0;
    ULONG msg_y = 0;
    BOOL disp_msg = really_display_message(hp, msg_id);         /* display message? */

    if (disp_msg)
    {
        va_list ap;

        /* increase message-counter */
        hp->msg_count++;

        /* set fatal-flag, if this is a fatal message */
        if (msg_id > MSG_FATAL)
        {
            hp->fatal = TRUE;
        }

        /* clear message buffer */
        clr_estr(hp->curr_msg);

        /* create message string */
        va_start(ap, format);
        while (format[0])
        {
            if (format[0] == '%')
            {
                STRPTR s = NULL;
                HSCTAG *tag = NULL;
                HSCTAG *lazy = NULL;
                HSCATTR *attr = NULL;
                HSCENT *ent = NULL;

                format++;
                switch (format[0])
                {

                case 'd':
                    /*
                     * append decimal number
                     */
                    app_estr(hp->curr_msg,
                             long2str(va_arg(ap, LONG)));
                    break;

                case 'q':
                    /*
                     * append quoted string
                     */
                    s = va_arg(ap, STRPTR);

                    app_estrch(hp->curr_msg, '`');
                    while (s[0])
                    {
                        switch (s[0])
                        {

                        case '\n':
                            app_estr(hp->curr_msg, "\\n");
                            break;
                        case '\"':
                            app_estr(hp->curr_msg, "\\\"");
                            break;
                        default:
                            if (s[0] < ' ')
                            {
                                app_estrch(hp->curr_msg, '\\');
                                app_estr(hp->curr_msg,
                                         long2str((LONG) s[0]));
                                app_estrch(hp->curr_msg, ';');
                            }
                            else
                                app_estrch(hp->curr_msg, s[0]);
                        }
                        s++;    /* process next char */
                    }
                    app_estrch(hp->curr_msg, '\'');

                    break;

                case 's':
                    /*
                     * append simple string
                     */
                    app_estr(hp->curr_msg, va_arg(ap, STRPTR));
                    break;

                case 'T':
                    /* append tag-pointer */
                    tag = va_arg(ap, HSCTAG *);
                    msg_tag(hp->curr_msg, tag->name);
                    break;

                case 't':
                    /* append tag */
                    msg_tag(hp->curr_msg, va_arg(ap, STRPTR));
                    break;

                case 'C':
                    /* append end tag-pointer */
                    tag = va_arg(ap, HSCTAG *);
                    msg_endtag(hp->curr_msg, tag->name);
                    break;

                case 'c':
                    /* append end tag */
                    msg_endtag(hp->curr_msg, va_arg(ap, STRPTR));
                    break;

                case 'A':
                    /* append attribute-pointer */
                    attr = va_arg(ap, HSCATTR *);
                    msg_attr(hp->curr_msg, attr->name);
                    break;

                case 'a':
                    /* append attribute */
                    msg_attr(hp->curr_msg, va_arg(ap, STRPTR));
                    break;

                case 'E':
                    /* append entity-pointer */
                    ent = va_arg(ap, HSCENT *);
                    msg_entity(hp->curr_msg, ent->name);
                    break;

                case 'e':
                    /* append entity */
                    msg_entity(hp->curr_msg, va_arg(ap, STRPTR));
                    break;

                case 'i':
                    /* append ID */
                    msg_idname(hp->curr_msg, va_arg(ap, STRPTR));
                    break;

                case 'j':
                    /* append jerk/prostitute */
                    if (hp->prostitute)
                    {
                        app_estr(hp->curr_msg, "prostitutes");
                    }
                    else
                    {
                        app_estr(hp->curr_msg, "jerks");
                    }
                    break;

                case 'L':
                    /* append var-list-pointer */
                    lazy = va_arg(ap, HSCTAG *);
                    msg_lazy(hp->curr_msg, lazy->name);
                    break;

                case 'l':
                    /* append var-list */
                    msg_lazy(hp->curr_msg, va_arg(ap, STRPTR));
                    break;

                default:
                    /*
                     * append unknown
                     */
                    app_estrch(hp->curr_msg, '%');
                    if (format[0] && (format[0] != '%'))
                    {
                        app_estrch(hp->curr_msg, '%');
                        format--;
                    }
                    break;
                }
            }
            else
            {
                app_estrch(hp->curr_msg, format[0]);
            }

            if (format[0])
            {
                format++;
            }
        }
コード例 #2
0
ファイル: dry.c プロジェクト: Zealsathish/snapraid
static int state_dry_process(struct snapraid_state* state, struct snapraid_parity_handle** parity, block_off_t blockstart, block_off_t blockmax)
{
	struct snapraid_handle* handle;
	unsigned diskmax;
	block_off_t i;
	unsigned j;
	void* buffer_alloc;
	unsigned char* buffer_aligned;
	int ret;
	data_off_t countsize;
	block_off_t countpos;
	block_off_t countmax;
	unsigned error;
	unsigned l;

	handle = handle_map(state, &diskmax);

	buffer_aligned = malloc_nofail_align(state->block_size, &buffer_alloc);

	error = 0;

	/* drop until now */
	state_usage_waste(state);

	countmax = blockmax - blockstart;
	countsize = 0;
	countpos = 0;
	state_progress_begin(state, blockstart, blockmax, countmax);
	for (i = blockstart; i < blockmax; ++i) {
		/* for each disk, process the block */
		for (j = 0; j < diskmax; ++j) {
			int read_size;
			struct snapraid_block* block = BLOCK_EMPTY;
			struct snapraid_disk* disk = handle[j].disk;

			if (!disk) {
				/* if no disk, nothing to do */
				continue;
			}

			block = disk_block_get(disk, i);

			if (!block_has_file(block)) {
				/* if no file, nothing to do */
				continue;
			}

			/* until now is CPU */
			state_usage_cpu(state);

			/* if the file is closed or different than the current one */
			if (handle[j].file == 0 || handle[j].file != block_file_get(block)) {
				struct snapraid_file* file = handle[j].file;
				ret = handle_close(&handle[j]);
				if (ret == -1) {
					/* LCOV_EXCL_START */
					msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
					msg_error("DANGER! Unexpected close error in a data disk, it isn't possible to dry.\n");
					msg_error("Stopping at block %u\n", i);
					++error;
					goto bail;
					/* LCOV_EXCL_STOP */
				}

				/* open the file only for reading */
				ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_error);
				if (ret == -1) {
					/* LCOV_EXCL_START */
					msg_error("DANGER! Unexpected open error in a data disk, it isn't possible to dry.\n");
					msg_error("Stopping at block %u\n", i);
					++error;
					goto bail;
					/* LCOV_EXCL_STOP */
				}
			}

			/* read from the file */
			read_size = handle_read(&handle[j], block, buffer_aligned, state->block_size, msg_warning);
			if (read_size == -1) {
				msg_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(block_file_get(block)->sub), block_file_pos(block));
				++error;
				continue;
			}

			/* until now is disk */
			state_usage_disk(state, disk);

			countsize += read_size;
		}

		/* read the parity */
		for (l = 0; l < state->level; ++l) {
			if (parity[l]) {
				/* until now is CPU */
				state_usage_cpu(state);

				ret = parity_read(parity[l], i, buffer_aligned, state->block_size, msg_warning);
				if (ret == -1) {
					msg_tag("parity_error:%u:%s: Read error\n", i, lev_config_name(l));
					++error;
				}

				/* until now is parity */
				state_usage_parity(state, l);
			}
		}

		/* count the number of processed block */
		++countpos;

		/* progress */
		if (state_progress(state, i, countpos, countmax, countsize)) {
			/* LCOV_EXCL_START */
			break;
			/* LCOV_EXCL_STOP */
		}
	}

	state_progress_end(state, countpos, countmax, countsize);

	state_usage_print(state);

bail:
	/* close all the files left open */
	for (j = 0; j < diskmax; ++j) {
		struct snapraid_file* file = handle[j].file;
		struct snapraid_disk* disk = handle[j].disk;
		ret = handle_close(&handle[j]);
		if (ret == -1) {
			/* LCOV_EXCL_START */
			msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno));
			msg_error("DANGER! Unexpected close error in a data disk.\n");
			++error;
			/* continue, as we are already exiting */
			/* LCOV_EXCL_STOP */
		}
	}

	if (error) {
		msg_status("\n");
		msg_status("%8u errors\n", error);
	} else {
		msg_status("Everything OK\n");
	}

	if (error)
		msg_error("DANGER! Unexpected errors!\n");

	free(handle);
	free(buffer_alloc);

	if (error != 0)
		return -1;
	return 0;
}