示例#1
0
static void MakeFiles(void)
{
    /* Variety of sizes to test file transfer ability
	Files get created in test directory  */

    static char *fsize[] = {"10", "235", "1310", "14235", "100234", "1048576"};
    static char *fname[sizeof(fsize)/sizeof(char *)];
    int i;

    SysFileCount = sizeof(fname)/sizeof(char *);

    for (i = 0; i < SysFileCount; i++)
	{
	fname[i] = (char *)malloc(1+strlen(MakeName(fsize[i])));
	strcpy(fname[i], MakeName(fsize[i]));
	if (mkfile(fname[i], atoi(fsize[i])) < 0) exit(-1);
	}

    SysFiles = fname;
}
示例#2
0
void Shell::select(const std::string& exec, size_t argc, const std::string* argv)
{
	if(exec == "open")
		open(argc, argv);
	else if(exec == "seek")
		seek(argc, argv);
	else if(exec == "tell")
		tell(argc, argv);
	else if(exec == "write")
		write(argc, argv);
	else if(exec == "read")
		read(argc, argv);
	else if(exec == "close")
		close(argc, argv);
	else if(exec == "useradd")
		useradd(argc, argv);
	else if(exec == "chpsd")
		chpsd(argc, argv);
	else if(exec == "cd")
		cd(argc, argv);
	else if(exec == "mkdir")
		mkdir(argc, argv);
	else if(exec == "mkfile")
		mkfile(argc, argv);
	else if(exec == "rm")
		rm(argc, argv);
	else if(exec == "cat")
		cat(argc, argv);
	else if(exec == "ls")
		ls(argc, argv);
	else if(exec == "chmod")
		chmod(argc, argv);
	else if(exec == "see")
		see(argc, argv);
	else if(exec == "ocp")
		ocp(argc, argv);
	else
		runshell(exec, argc, argv);
}
示例#3
0
文件: sync.c 项目: atikinn/db165
static inline
void persist_data(void *data, size_t num_elems, size_t elsz, const char *path) {
    size_t sz = num_elems * elsz;

    int fd = mkfile(sz, path);
    if (fd == -1) return;

    int *map = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    close(fd);

    if (map == MAP_FAILED) {
	perror("Error mmapping the file");
	return;
    }

    memcpy(map, data, sz);

    if (munmap(map, sz) == -1) {
	perror("Error un-mmapping the file");
	return;
    }

    return;
}
示例#4
0
int mq_open(const char *name, int oflag)
{
    if (oflag & O_CREAT)
        mkfile(name, 0, S_IMSGQ);
    return open(name, 0);
}
示例#5
0
int mkfifo(const char *pathname, int mode)
{
    mkfile(pathname, mode, S_IFIFO);
    return 0;
}
示例#6
0
文件: main.c 项目: 8l/mc
int main(int argc, char **argv)
{
	char buf[1024];
	Stab *globls;
	Optctx ctx;
	size_t i;

	outfile = NULL;

	optinit(&ctx, "cd:?hSo:I:9G:", argv, argc);
	asmsyntax = Defaultasm;
	while (!optdone(&ctx)) {
		switch (optnext(&ctx)) {
		case 'o':
			outfile = ctx.optarg;
			break;
		case 'S':
			writeasm = 1;
			break;
		case '?':
		case 'h':
			usage(argv[0]);
			exit(0);
			break;
		case 'c':
			extracheck = 1;
			break;
		case 'd':
			while (ctx.optarg && *ctx.optarg)
				debugopt[*ctx.optarg++ & 0x7f]++;
			break;
		case '9':
			asmsyntax = Plan9;
			break;
		case 'G':
			if (!strcmp(ctx.optarg, "e"))
				asmsyntax = Gnugaself;
			else if (!strcmp(ctx.optarg, "m"))
				asmsyntax = Gnugasmacho;
			else
				die("unknown gnu syntax flavor");
			break;
		case 'I':
			lappend(&incpaths, &nincpaths, ctx.optarg);
			break;
		default:
			usage(argv[0]);
			exit(0);
			break;
		}
	}

	lappend(&incpaths, &nincpaths, Instroot "/lib/myr");

	if (ctx.nargs == 0) {
		fprintf(stderr, "No input files given\n");
		exit(1);
	}
	else if (ctx.nargs > 1)
		outfile = NULL;

	for (i = 0; i < ctx.nargs; i++) {
		globls = mkstab(0);
		tyinit(globls);
		tokinit(ctx.args[i]);
		file = mkfile(ctx.args[i]);
		file->file.globls = globls;
		yyparse();

		/* before we do anything to the parse */
		if (debugopt['T'])
			dump(file, stdout);
		infer(file);
		if (hasmain(file))
			geninit(file);
		tagexports(file, 0);
		/* after all type inference */
		if (debugopt['t'])
			dump(file, stdout);

		if (writeasm) {
			if (outfile != NULL)
				swapout(buf, sizeof buf, ".s");
			else
				swapsuffix(buf, sizeof buf, ctx.args[i], ".myr", ".s");
		} else {
			gentempfile(buf, sizeof buf, ctx.args[i], ".s");
		}
		genuse(ctx.args[i]);
		gen(file, buf);
		assemble(buf, ctx.args[i]);
	}

	return 0;
}
示例#7
0
int PrintRar(const char * buf)
{
//406  1999-10-12 01:27   rxLib567/RX/RxNews.txt
//  0  2005-04-27 12:07   rxLib567/RX/Units/
	static gchar * last;
	if(CountReadStrings==0)
	{
		if(buf[0]=='-')
		{
			last=0;
			CountReadStrings=3;
		}
		return 0;
	}

	CountReadStrings++;

	if(buf[0]=='-') return 1;

	if((CountReadStrings&3)==0)
	{
		if(last) g_free(last);
		last=g_strdup(buf);
//printf("0:%s\n",buf);
		return 0;
	} else 
        if((CountReadStrings&3)==1)
	{
	}
	else
	{
		CountReadStrings++;
		return 0;
	}

	long int size;
	gchar * right;
	gchar * name=last;
	while(*name==0x20) name++; 
        struct tm ltm;

	gchar * p=(gchar*)buf;
	char str[strlen(buf)+1];
	sscanf(p," %s ",str);
	sscanf(p," %ld ",&size);
	p=strstr(p,"%");
	p+=1;
//	printf("%s %ld %s\n",name,size,p);
	int y,m,d,h,mn;
//	sscanf(p," %d-%d-%d ",&d,&m,&y);
	sscanf(p," %d-%d-%d %d:%d",&d,&m,&y,&h,&mn);

	ltm.tm_year=y;
	if(ltm.tm_year<50) ltm.tm_year+=100;
	ltm.tm_mon=m-1;
	ltm.tm_mday=d;
	ltm.tm_hour=h;
	ltm.tm_min=mn;
	ltm.tm_sec=0;

//	printf("'%s' %ld %d-%d-%d %d:%d\n",name,size,ltm.tm_year,ltm.tm_mon,ltm.tm_mday,h,mn);
	if(name[0]=='*')
	{
		RarPassword=1;
	}	

	gchar * fullname;
	if( (RarPassword==1) && (name[0]!='*') )    fullname=g_strdup_printf("%s/*%s/",DestDir,name);
	else fullname=g_build_filename(DestDir,name,NULL);

	time_t ut=mktime(&ltm);
	struct utimbuf times;
	times.actime = ut;
        times.modtime = ut;

	if(!size) 
	{
		CreateDirInDir(fullname);
	} else
	{
		mkfile(fullname,size);
	        utime(fullname, &times );
	}

	return 0;
} 
示例#8
0
int PrintTar(const char * buf)
{
	long int size;
	gchar * right;
	gchar * name;
        struct tm ltm;

	gchar * p=(gchar*)buf;
	char str[strlen(buf)+1];

	sscanf(p,"%s",str);
	right=g_strdup(str);

	p=strstr(p,str);
	p+=strlen(str);
	sscanf(p,"%s",str); //owner/group

	p=strstr(p,str);
	p+=strlen(str);
	sscanf(p,"%s",str);
	sscanf(p,"%ld",&size);

	p=strstr(p,str);//date
	p+=strlen(str);
	sscanf(p," %s ",str);
	int y,m,d,h;
	sscanf(p," %d-%d-%d ",&y,&m,&d);
	ltm.tm_year=y-1900;
	ltm.tm_mon=m-1;
	ltm.tm_mday=d;

	p=strstr(p,str);//time
	p+=strlen(str);
	sscanf(p," %s ",str);
	sscanf(p," %d:%d ",&h,&m);
	ltm.tm_hour=h;
	ltm.tm_min=m;
	ltm.tm_sec=0;

	p=strstr(p,str); //name
	p+=strlen(str);
	while(*p==0x20) p++;
	name=g_strdup(p);

	gchar * fullname=g_build_filename(DestDir,name,NULL);

	time_t ut=mktime(&ltm);
	struct utimbuf times;
	times.actime = ut;
        times.modtime = ut;

	if(right[0]=='d') 
	{
		CreateDirInDir(fullname);
	} else
	{
		mkfile(fullname,size);
	        utime(fullname, &times );
	}
	return 0;
} 
示例#9
0
文件: scuzz.c 项目: 99years/plan9
static long
cmdwrite(ScsiReq *rp, int argc, char *argv[])
{
	long n, prevsize = 0;
	vlong nbytes, total;
	int fd, pid;
	char *p;

	nbytes = ~0ULL >> 1;
	switch(argc){

	default:
		rp->status = Status_BADARG;
		return -1;

	case 2:
		nbytes = strtoll(argv[1], &p, 0);
		if(nbytes == 0 && p == argv[1]){
			rp->status = Status_BADARG;
			return -1;
		}
		/*FALLTHROUGH*/

	case 1:
		if((fd = mkfile(argv[0], OREAD, &pid)) == -1){
			rp->status = Status_BADARG;
			return -1;
		}
		break;
	}
	total = 0;
	while(nbytes){
		n = vlmin(nbytes, maxiosize);
		if((n = read(fd, rwbuf, n)) == -1){
			if(total == 0)
				total = -1;
			break;
		}
		if (n == 0)
			break;
		if (prevsize != n) {
			print("tape block size=%ld\n", n);
			prevsize = n;
		}
		if(SRwrite(rp, rwbuf, n) != n){
			if(total == 0)
				total = -1;
			if(rp->status == STok)
				rp->status = Status_SW;
			break;
		}
		nbytes -= n;
		total += n;
	}
	close(fd);
	if(pid >= 0 && waitfor(pid)){
		rp->status = Status_SW;
		return -1;
	}
	return total;
}
示例#10
0
文件: scuzz.c 项目: 99years/plan9
static long
cmdwtrack(ScsiReq *rp, int argc, char *argv[])
{
	uchar mode, track;
	long n, nbytes, total, x;
	int fd, pid;
	char *p;

	mode = track = 0;
	nbytes = 0;
	switch(argc){

	default:
		rp->status = Status_BADARG;
		return -1;

	case 4:
		if((mode = strtoul(argv[3], &p, 0)) == 0 && p == argv[3]){
			rp->status = Status_BADARG;
			return -1;
		}
		/*FALLTHROUGH*/

	case 3:
		if((track = strtoul(argv[2], &p, 0)) == 0 && p == argv[2]){
			rp->status = Status_BADARG;
			return -1;
		}
		/*FALLTHROUGH*/

	case 2:
		if((nbytes = strtoul(argv[1], &p, 0)) == 0 && p == argv[1]){
			rp->status = Status_BADARG;
			return -1;
		}
		/*FALLTHROUGH*/

	case 1:
		if((fd = mkfile(argv[0], OREAD, &pid)) == -1){
			rp->status = Status_BADARG;
			return -1;
		}
		break;
	}
	total = 0;
	n = MIN(nbytes, maxiosize);
	if((n = readn(fd, rwbuf, n)) == -1){
		fprint(2, "file read failed %r\n");
		close(fd);
		return -1;
	}
	if((x = SRwtrack(rp, rwbuf, n, track, mode)) != n){
		fprint(2, "wtrack: write incomplete: asked %ld, did %ld\n", n, x);
		if(rp->status == STok)
			rp->status = Status_SW;
		close(fd);
		return -1;
	}
	nbytes -= n;
	total += n;
	while(nbytes){
		n = MIN(nbytes, maxiosize);
		if((n = read(fd, rwbuf, n)) == -1){
			break;
		}
		if((x = SRwrite(rp, rwbuf, n)) != n){
			fprint(2, "write: write incomplete: asked %ld, did %ld\n", n, x);
			if(rp->status == STok)
				rp->status = Status_SW;
			break;
		}
		nbytes -= n;
		total += n;
	}
	close(fd);
	if(pid >= 0 && waitfor(pid)){
		rp->status = Status_SW;
		return -1;
	}
	return total;
}
示例#11
0
int main(int argc, char **argv)
{
        int f, c;
        long n, nb;

        time(&utime);

        pname = argv[0];
        endian = S4_ENDIAN;
        if( argc > 1 && argv[1][0] == '-' )
        {
                if( !strcmp("-be", argv[1]) )
                {
                        doswap = S4_ENDIAN == S4_BE ? 0 : 1;
                        endian = S4_BE;
                }
                else if( !strcmp("-le", argv[1]) )      
                {
                        doswap = S4_ENDIAN == S4_BE ? 1 : 0;
                        endian = S4_LE;
                }
                argv++;
                argc--;
        }

        /*
         * open relevent files
         */
        if(argc < 3) {
                printf("usage: %s filsys blocks[:inodes] [gap blocks/cyl]\n", 
                       pname );
                exit(1);
        }
                   
        fsys   = argv[1];
        sizing = argv[2];
     
        /* Create new file, clobbering old one. */
        fsfd = open(fsys, O_RDWR|O_CREAT|O_TRUNC, 0640 );
        if(fsfd < 0) {
                printf("%s: cannot create\n", fsys);
                exit(1);
        }
     
        nb = n = 0;

        /* if there's an argument, and we can crack it into
           size:inodes, or size, take them, else complain.
           If nothing, take defaults */

        for(f=0; (c=sizing[f]); f++) {
                if(c<'0' || c>'9') {
                        if(c == ':') {
                                nb = n;
                                n = 0;
                                continue;
                        }
                        printf("Mkfs: expected numbers, not '%s'\n", sizing);
                        exit(1);
                }
                n = n*10 + (c-'0');
        }
        if(!nb) {
                nb = n / SECTPB;
                n = nb/4;
        } else {
                nb /= SECTPB;
        }

        /* nb is number of logical blocks in fs,
           n is number of inodes */

        filsys->s_fsize = nb - 2;
                   
        n /= NBINODE;		/* number of logical blocs for inodes */
        if(n <= 0)
                n = 1;
     
        /* cap inodes */
        if(n > 65500/NBINODE)
        {
          printf("Too many inode blocks, %ld max\n", 65500/NBINODE );
          n = 65500/NBINODE;
        }
     
        filsys->s_isize = n + 2;

        /* set magic number for file system type */
        filsys->s_magic = S4_FsMAGIC;
        filsys->s_type = (FSBSIZE == 512) ? S4_Fs1b : S4_Fs2b;
     
        /* cylinder */
        if(argc >= 5) {
                f_m = atoi(argv[3]);
                f_n = atoi(argv[4]);
                if(f_n <= 0 || f_n >= MAXFN)
                        f_n = CYLSIZE;
                if(f_m <= 0 || f_m > f_n)
                        f_m = STEPSIZE;
        }
     
        f_n /= SECTPB;
     
        if( f_n > (filsys->s_fsize / 4) )
                f_n = filsys->s_fsize / 4;
     
        f_m = (f_m +(SECTPB -1))/SECTPB;  /* gap rounded up to the next block */

        /* don't set these until adjustments are made above. */
        filsys->s_vinfo[0] = f_m;
        filsys->s_vinfo[1] = f_n;
     
        printf("Built %s-endian file system\n", S4_BE == endian ? "big" : "little");
        printf("bytes per logical block = %d\n",  FSBSIZE);
        printf("total logical blocks    = %ld\n", (long)filsys->s_fsize);
        printf("total inodes            = %ld\n", n*NBINODE);
        printf("freelist gap            = %d\n",  filsys->s_vinfo[0]);
        printf("freelist cylinder size  = %d \n", filsys->s_vinfo[1]);

        if(filsys->s_isize >= filsys->s_fsize) {
                printf("%ld/%ld: bad file blocks/inode blks ratio\n",
                       (long)filsys->s_fsize, (long)filsys->s_isize-2);
                exit(1);
        }
                   
        /* ---------------------------- */
        /* geometry set up, now prepare */

        ino = 0;
        filsys->s_tinode = 0;
        filsys->s_tfree = filsys->s_fsize;
     
        /* write zeros to the whole inode table */
        memset( buf, 0, FSBSIZE );
        for(n=2; n!=filsys->s_isize; n++) {
                wtfs(n, buf, s4b_ino );
                filsys->s_tinode += NBINODE;
        }
                   
        /* touch end block to set length and ensure writable. */
        wtfs( nb - 1, buf, s4b_raw );

        /* populate the freelist */
        bflist();

        /* create the root directory with no parent inode */
        mkfile((struct inode *)0);

        /* stamp the superblock */
        filsys->s_time = utime;

        /* write super-block onto file system */
        if( doswap )
                s4_fsu_swap( (s4_fsu*)filsys, s4b_super );

        lseek(fsfd, (long)S4_SUPERBOFF, 0);
        if(write(fsfd, (char *)filsys, SBSIZE) != SBSIZE) {
                printf("write error: super-block\n");
                exit(1);
        }
     
        if( doswap )
                s4_fsu_swap( (s4_fsu*)filsys, s4b_super );

        if( error )     
        {
                printf("mkfs: ERROR making filesystem!!!\n");
        }
        else
        {
                printf("mkfs: Available blocks  = %ld  %.fk %.2fM\n",
                       (long)filsys->s_tfree,
                       (double)filsys->s_tfree * FSBSIZE / 1024,
                       (double)filsys->s_tfree * FSBSIZE / 1024 / 1024 );
        }
        exit(error);
}
示例#12
0
文件: mmap1.c 项目: sathnaga/ltp
int main(int argc, char **argv)
{
	int c, i;
	int file_size;
	int num_iter;
	double exec_time;
	int fd;
	void *status;
	pthread_t thid[2];
	long chld_args[3];
	extern char *optarg;
	struct sigaction sigptr;
	int ret;

	/* set up the default values */
	file_size = 1024;
	num_iter = 1000;
	exec_time = 24;

	while ((c = getopt(argc, argv, "hvl:s:x:")) != -1) {
		switch (c) {
		case 'h':
			usage(argv[0]);
			break;
		case 'l':
			if ((num_iter = atoi(optarg)) == 0)
				OPT_MISSING(argv[0], optopt);
			else if (num_iter < 0)
				printf
				    ("WARNING: bad argument. Using default %d\n",
				     (num_iter = 1000));
			break;
		case 's':
			if ((file_size = atoi(optarg)) == 0)
				OPT_MISSING(argv[0], optopt);
			else if (file_size < 0)
				printf
				    ("WARNING: bad argument. Using default %d\n",
				     (file_size = 1024));
			break;
		case 'v':
			verbose_print = 1;
			break;
		case 'x':
			exec_time = atof(optarg);
			if (exec_time == 0)
				OPT_MISSING(argv[0], optopt);
			else if (exec_time < 0)
				printf
				    ("WARNING: bad argument. Using default %.0f\n",
				     (exec_time = 24));
			break;
		default:
			usage(argv[0]);
			break;
		}
	}

	/* We don't want other mmap calls to map into same area as is
	 * used for test (mmap_address). The test expects read to return
	 * test pattern or read must fail with SIGSEGV. Find an area
	 * that we can use, which is unlikely to be chosen for other
	 * mmap calls. */
	distant_area = mmap(0, DISTANT_MMAP_SIZE, PROT_WRITE | PROT_READ,
		MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
	if (distant_area == (void *)-1)
		tst_brkm(TBROK | TERRNO, NULL, "distant_area: mmap()");
	SAFE_MUNMAP(NULL, distant_area, (size_t)DISTANT_MMAP_SIZE);
	distant_area += DISTANT_MMAP_SIZE / 2;

	if (verbose_print)
		tst_resm(TINFO, "Input parameters are: File size:  %d; "
			 "Scheduled to run:  %lf hours; "
			 "Number of mmap/write/read:  %d",
			 file_size, exec_time, num_iter);

	alarm(exec_time * 3600);

	/* Do not mask SIGSEGV, as we are interested in handling it. */
	sigptr.sa_sigaction = sig_handler;
	sigfillset(&sigptr.sa_mask);
	sigdelset(&sigptr.sa_mask, SIGSEGV);
	sigptr.sa_flags = SA_SIGINFO | SA_NODEFER;

	for (i = 0; sig_info[i].signum != -1; i++) {
		if (sigaction(sig_info[i].signum, &sigptr, NULL) == -1) {
			perror("man(): sigaction()");
			fprintf(stderr,
				"could not set handler for %s, errno = %d\n",
				sig_info[i].signame, errno);
			exit(-1);
		}
	}

	tst_tmpdir();

	for (;;) {
		if ((fd = mkfile(file_size)) == -1)
			tst_brkm(TBROK, NULL,
				 "main(): mkfile(): Failed to create temp file");

		if (verbose_print)
			tst_resm(TINFO, "Tmp file created");

		chld_args[0] = fd;
		chld_args[1] = file_size;
		chld_args[2] = num_iter;

		if ((ret =
		     pthread_create(&thid[0], NULL, map_write_unmap,
				    chld_args)))
			tst_brkm(TBROK, NULL, "main(): pthread_create(): %s",
				 strerror(ret));

		tst_resm(TINFO, "created writing thread[%lu]", thid[0]);

		if ((ret = pthread_create(&thid[1], NULL, read_mem, chld_args)))
			tst_brkm(TBROK, NULL, "main(): pthread_create(): %s",
				 strerror(ret));

		tst_resm(TINFO, "created reading thread[%lu]", thid[1]);

		for (i = 0; i < 2; i++) {
			if ((ret = pthread_join(thid[i], &status)))
				tst_brkm(TBROK, NULL,
					 "main(): pthread_join(): %s",
					 strerror(ret));

			if (status)
				tst_brkm(TFAIL, NULL,
					 "thread [%lu] - process exited "
					 "with %ld", thid[i], (long)status);
		}

		close(fd);
	}

	tst_rmdir();

	exit(0);
}
示例#13
0
文件: lex.c 项目: BGCX261/znos-git
int
main(int argc, char *argv[])
{
	int fd;
	char *p;

	ARGBEGIN{
	case 'C':
		dontcompile++;
		break;
	case 'c':
		mustcompile++;
		break;
	case 'l':
		listing++;
		break;
	default:
		usage();
	}ARGEND;

	fmtinstall('i', iconv);
	fmtinstall('a', aconv);
	kinit();
	pcentry = -1;
	dentry = -1;

	if(argc != 1)
		usage();
	file = argv[0];
	bin = Bopen(file, OREAD);
	if(bin == 0) {
		nerr++;
		print("open: %s: %r\n", file);
		exits("errors");
	}
	p = strrchr(file, '/');
	if(p == nil)
		p = file;
	else
		p++;
	ofile = mkfile(p, ".s", ".dis");
	fd = create(ofile, OWRITE, 0666);
	if(fd < 0) {
		nerr++;
		print("can't create: %s: %r\n", ofile);
		exits("errors");
	}
	Binit(&output, fd, OWRITE);
	bout = &output;
	line = 1;
	yyparse();
	Bterm(bin);
	Bterm(bout);
	close(fd);

	if(nerr != 0){
		remove(ofile);
		exits("errors");
	}

	exits(0);
    
    return 0;
}