Example #1
0
int
main(int argc, char *argv[])
{
	char *e, *gfarm_prefix;
	extern int optind;
	int c;

	e = gfarm_initialize(&argc, &argv);
	if (e != NULL) {
		print_errmsg(progname, e);
		exit(1);
	}
	if (!gfarm_is_active_file_system_node) {
		print_errmsg(progname, "not a filesystem node");
		exit(1);
	}
	while ((c = getopt(argc, argv, "ad")) != EOF) {
		switch (c) {
		case 'a':
			check_all = 1;
			break;
		case 'd':
			delete_invalid_file = 1;
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (*argv) {
		while (*argv)
			fixurl(*argv++);
		goto finish;
	}

	/* fix a whole spool directory. */
	if (chdir(gfarm_spool_root) == 0)
		gfarm_prefix = "gfarm:/";
	else
		gfarm_prefix = "gfarm:";

	fixdir(".", gfarm_prefix);

 finish:
	e = gfarm_terminate();
	if (e != NULL) {
		print_errmsg(progname, e);
		exit(1);
	}
	exit(0);
}
Example #2
0
static int
fixdir(char *dir, char *gfarm_prefix)
{
	DIR* dirp;
	struct dirent *dp;
	struct stat sb;
	char *dir1;

	if (stat(dir, &sb)) {
		perror(dir);
		return 1;
	}
	if (S_ISREG(sb.st_mode))
		return fixfrag(dir, gfarm_prefix);

	dirp = opendir(dir);
	if (dirp == NULL) {
		perror(dir);
		return 1;
	}

	if (strcmp(dir, ".") == 0)
		dir = ""; /* just a trick */

	while ((dp = readdir(dirp)) != NULL) {
		if (strcmp(dp->d_name, ".") == 0
		    || strcmp(dp->d_name, "..") == 0)
			continue;

		dir1 = malloc(strlen(dir) + strlen(dp->d_name) + 2);
		if (dir1 == NULL) {
			fputs("not enough memory", stderr);
			closedir(dirp);
			return 1;
		}
		strcpy(dir1, dir);
		if (strcmp(dir, ""))
			strcat(dir1, "/");
		strcat(dir1, dp->d_name);

		fixdir(dir1, gfarm_prefix);

		free(dir1);
	}
	closedir(dirp);
	if (dirp != NULL)
		return 1;

	return 0;
}
Example #3
0
int
main(int argc, char *argv[])
{
	char *e, *gfarm_prefix;
	extern int optind;
	int c;

	e = gfarm_initialize(&argc, &argv);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", progname, e);
	}

	while ((c = getopt(argc, argv, "ad")) != EOF) {
		switch (c) {
		case 'a':
			check_all = 1;
			break;
		case 'd':
			delete_invalid_file = 1;
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 0) {
		while (argc-- > 0 && fixurl(*argv++) == 0);
		goto finish;
	}

	/* fix a whole spool directory. */
	if (chdir(gfarm_spool_root) == 0)
		gfarm_prefix = "gfarm:/";
	else
		gfarm_prefix = "gfarm:";

	fixdir(".", gfarm_prefix);

 finish:
	e = gfarm_terminate();
	if (e != NULL) {
	    fprintf(stderr, "%s: %s\n", progname, e);
	}

	exit(0);
}
Example #4
0
static int
fixdir(char *dir, const char *gfarm_prefix)
{
	DIR* dirp;
	struct dirent *dp;
	struct stat sb;
	char *dir1;
	char *gfarm_url, *e;
	int is_directory;
	struct gfs_stat gs;

	if (lstat(dir, &sb)) {
		perror(dir);
		return (1);
	}
	if (S_ISREG(sb.st_mode))
		return (fixfrag(dir, gfarm_prefix));

	if (!S_ISDIR(sb.st_mode)) {
		print_errmsg(dir, NULL,
			"neither a regular file nor a directory");
		delete_invalid_file_or_directory(dir);
		return (1);
	}

	/* 'dir' is a directory */
	gfarm_url = append_prefix_pathname(gfarm_prefix, dir);
	if (gfarm_url == NULL) {
		print_errmsg(dir, NULL, "not enough memory");
		return (1);
	}

	e = gfs_stat(gfarm_url, &gs);
	if (e != NULL) {
		print_errmsg(gfarm_url, NULL, e);
		delete_invalid_file_or_directory(dir);
		free(gfarm_url);
		return (1);
	}
	is_directory = GFARM_S_ISDIR(gs.st_mode);
	gfs_stat_free(&gs);
	if (!is_directory) {
		print_errmsg(gfarm_url, NULL, "invalid directory");
		delete_invalid_file_or_directory(dir);
		free(gfarm_url);
		return (1);
	}
	free(gfarm_url);

	dirp = opendir(dir);
	if (dirp == NULL) {
		perror(dir);
		return (1);
	}

	if (strcmp(dir, ".") == 0)
		dir = ""; /* just a trick */

	while ((dp = readdir(dirp)) != NULL) {
		if (strcmp(dp->d_name, ".") == 0
		    || strcmp(dp->d_name, "..") == 0)
			continue;

		GFARM_MALLOC_ARRAY(dir1, strlen(dir) + strlen(dp->d_name) + 2);
		if (dir1 == NULL) {
			print_errmsg(dp->d_name, NULL, "not enough memory");
			closedir(dirp);
			return (1);
		}
		strcpy(dir1, dir);
		if (strcmp(dir, ""))
			strcat(dir1, "/");
		strcat(dir1, dp->d_name);

		fixdir(dir1, gfarm_prefix);

		free(dir1);
	}
	return (closedir(dirp));
}
Example #5
0
static void
fixurl(const char *gfarm_url)
{
	char *gfarm_file, *local_path, *e;
	struct stat sb;
	int len_path, is_invalid = 0, is_directory = 0;
	glob_t pglob;
	char **pathp, *pat;
	struct gfs_stat gs;

	e = gfarm_canonical_path(gfarm_url_prefix_skip(gfarm_url), &gfarm_file);
	if (e != NULL) {
		/*
		 * no path info, try to delete invalid physical files
		 * or directories
		 */
		e = gfarm_canonical_path_for_creation(
			gfarm_url_prefix_skip(gfarm_url), &gfarm_file);
		if (e != NULL) {
			/* in this case, give up searching invalid files */
			print_errmsg(gfarm_url, NULL, e);
			return;
		}
		is_invalid = 1;
	}
	else {
		/* check it is a directory or not */
		e = gfs_stat(gfarm_url, &gs);
		if (e != NULL) {
			if (e != GFARM_ERR_NO_FRAGMENT_INFORMATION) {
				/* maybe permission denied */
				print_errmsg(gfarm_url, NULL, e);
				goto error_gfarm_file;
			}
			/* no fragment information case */
		}
		else {
			is_directory = GFARM_S_ISDIR(gs.st_mode);
			gfs_stat_free(&gs);
		}
	}
	/*
	 * Check local_path; if it is invalid or not a directory,
	 * delete it.  Otherwise, check it recursively.
	 */
	e = gfarm_path_localize(gfarm_file, &local_path);
	if (e == NULL && stat(local_path, &sb) == 0) {
		if (is_invalid || !is_directory || !S_ISDIR(sb.st_mode)) {
			print_errmsg(local_path, NULL,
				"invalid file or directory");
			delete_invalid_file_or_directory(local_path);
		}
		else if (chdir(local_path) == 0)
			(void)fixdir(".", gfarm_url);
		/* continue */
	}
	if (e != NULL) {
		print_errmsg(gfarm_url, NULL, e);
		goto error_gfarm_file;
	}

	/* investigate file sections */
	len_path = strlen(local_path);
	GFARM_MALLOC_ARRAY(pat, len_path + 3);
	if (pat == NULL) {
		print_errmsg(gfarm_url, NULL, "not enough memory");
		free(local_path);
		goto error_gfarm_file;
	}
	strcpy(pat, local_path);
	strcat(pat, ":*");
	free(local_path);

	pglob.gl_offs = 0;
	glob(pat, GLOB_DOOFFS, NULL, &pglob);
	free(pat);
	
	pathp = pglob.gl_pathv;
	while (*pathp) {
		char *sec = &((*pathp)[len_path + 1]);

		if (is_invalid || is_directory) {
			print_errmsg(gfarm_url, sec, "invalid file");
			delete_invalid_file_or_directory(*pathp);
			++pathp;
			continue;
		}
		(void)fixfrag_i(gfarm_url, *pathp, gfarm_file, sec);

		++pathp;
	}
	globfree(&pglob);

 error_gfarm_file:
	free(gfarm_file);
	return;
}
Example #6
0
int32 func__loadimage(qbs *f,int32 bpp,int32 passed){
if (new_error) return 0;

static int32 isHardware;
isHardware=0; if (bpp==33){bpp=32; isHardware=1;}

//validate bpp
if (passed){
if ((bpp!=32)&&(bpp!=256)){error(5); return 0;}
}else{
if (write_page->text){error(5); return 0;}
bpp=-1;
}
if (!f->len) return -1;//return invalid handle if null length string
//load the file
static int32 fh,result;
static int64 lof;
fh=gfs_open(f,1,0,0);
if (fh<0) return -1;
lof=gfs_lof(fh);
static uint8* content;
content=(uint8*)malloc(lof); if (!content){gfs_close(fh); return -1;}
result=gfs_read(fh,-1,content,lof);
gfs_close(fh);
if (result<0){free(content); return -1;}

//Identify format:
 static int32 format;
format=0;

//'.png'
if (lof>=8){
if ((content[0]==0x89)&&(content[1]==0x50)&&(content[2]==0x4E)&&(content[3]==0x47)&&
    (content[4]==0x0D)&&(content[5]==0x0A)&&(content[6]==0x1A)&&(content[7]==0x0A))
    {format=2; goto got_format;}//PNG
}//8

//'.bmp'
if (lof>=6){
 if ((content[0]==0x42)&&(content[1]==0x4D)){
  if ( (*((int32*)(&content[2]))) == lof ){//length of file
   format=3; goto got_format;
  }
 }//BMP 
}//6

//'.jpg' The first two bytes of every JPEG stream are the Start Of Image (SOI) marker values FFh D8h
if (lof>=2){
if ((content[0]==0xFF)&&(content[1]==0xD8)){format=1; goto got_format;}//JP[E]G
}//2

//GIF is handled by our "other" library
//'.gif' "GIF"
//if (lof>=3){
//if ((content[0]==71)&&(content[1]==73)&&(content[2]==70)){format=4; goto got_format;}//GIF
//}//3

got_format:

static uint8 *pixels;
static int32 x,y;

if (format==0) pixels=image_decode_other(content,lof,&result,&x,&y);
if (format==1) pixels=image_decode_jpg(content,lof,&result,&x,&y);
if (format==2) pixels=image_decode_png(content,lof,&result,&x,&y);
if (format==3) pixels=image_decode_bmp(content,lof,&result,&x,&y);

free(content);
if (!(result&1)) return -1;

//...

static int32 i;
i=func__newimage(x,y,32,1);
if (i==-1){free(pixels); return -1;}
memcpy(img[-i].offset,pixels,x*y*4);
free(pixels);

if (isHardware){
 static int32 iHardware;
 iHardware=func__copyimage(i,33,1);
 sub__freeimage(i,1);
 i=iHardware;
}

return i;


#ifndef NO_S_D_L
static qbs *tqbs=NULL,*nullt=NULL;
static int32 i;
if (new_error) return 0;
//validate bpp
if (passed){
if ((bpp!=32)&&(bpp!=256)){error(5); return 0;}
}else{
if (write_page->text){error(5); return 0;}
bpp=-1;
}
if (!f->len) return -1;//return invalid handle if null length string
if (!tqbs) tqbs=qbs_new(0,0);
if (!nullt){nullt=qbs_new(1,0); nullt->chr[0]=0;}
qbs_set(tqbs,qbs_add(f,nullt));
i=imgload(fixdir(tqbs),bpp);
if (!i) return -1;//failed
return -i;
return -1;
#endif //NO_S_D_L

}
Example #7
0
static int
fixurl(char *gfarm_url)
{
	char *gfarm_file, *local_path, *e;
	char sec[GFARM_INT32STRLEN];
	struct stat sb;
	int rank;

	e = gfarm_url_make_path(gfarm_url, &gfarm_file);
	if (e != NULL) {
		fprintf(stderr, "%s on %s: %s\n", gfarm_url,
			gfarm_host_get_self_name(), e);
		return 1;
	}

	/* check whether gfarm_url is directory or not. */
	e = gfarm_path_localize(gfarm_file, &local_path);
	if (e == NULL && stat(local_path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
		int r = 1;
		if (chdir(local_path) == 0)
			r = fixdir(".", gfarm_url);
		free(gfarm_file);
		free(local_path);
		return (r);
	}
	if (e != NULL) {
		fprintf(stderr, "%s on %s: %s\n", gfarm_url,
			gfarm_host_get_self_name(), e);
		free(gfarm_file);
		return (1);
	}
	free(local_path);

	/* XXX - assume gfarm_url is a fragmented file. */
	e = gfs_pio_get_node_rank(&rank);
	if (e != NULL) {
		fprintf(stderr, "%s on %s: %s\n", gfarm_url,
			gfarm_host_get_self_name(), e);
		goto error_gfarm_file;
	}

	e = gfarm_path_localize_file_fragment(gfarm_file, rank, &local_path);
	if (e != NULL) {
		fprintf(stderr, "%s on %s: %s\n", gfarm_url,
			gfarm_host_get_self_name(), e);
		goto error_gfarm_file;
	}

	e = check_path_info(gfarm_file);
	if (e != NULL) {
		fprintf(stderr, "%s on %s: %s\n", gfarm_url,
			gfarm_host_get_self_name(), e);
		if (delete_invalid_file) {
			if (unlink(local_path) == 0)
				printf("%s on %s: deleted\n",
				       local_path, gfarm_host_get_self_name());
			else
				perror(local_path);
		}
		goto error_local_path;
	}

	sprintf(sec, "%d", rank);
	e = fixfrag_i(local_path, gfarm_file, sec);
	if (e != NULL && e != GFARM_ERR_ALREADY_EXISTS) {
		fprintf(stderr, "%s (%s) on %s: %s\n", gfarm_url, sec,
			gfarm_host_get_self_name(), e);
		if (delete_invalid_file) {
			if (unlink(local_path) == 0)
				printf("%s on %s: deleted\n",
				       local_path, gfarm_host_get_self_name());
			else
				perror(local_path);
		}
		goto error_local_path;
	}

	/* printf("%s (%s): fixed\n", gfarm_url, sec); */

	return (0);

 error_local_path:
	free(local_path);
 error_gfarm_file:
	free(gfarm_file);
	return (1);
}