Пример #1
0
int main(object me, string file)
{
	int i;
	object obj, *inv;
	string err;
	mixed files;
	string dir;
	string* temp;

	seteuid( geteuid(me) );

	if (!file) file = me->query("cwf");
	if (!file)
		return notify_fail("你要重新编译什麽档案?\n");

	if( (obj = present(file, environment(me))) && interactive(obj) )
		return update_player(obj);

	if( file == "me" )
		return update_player(me);

  if (file[strlen(file)-1]=='/') 
	{
		file = file[0..strlen(file)-2];
		dir = resolve_path(me->query("cwd"), file);
		dir += "/";
	}
  else 
  {
  	dir = resolve_path(me->query("cwd"), file);
//  	write("adir= "+dir+"\n");
		if (file_size(dir) > 0) return updatefile(me,dir);
		else if (file_size(dir+".c") > 0) return updatefile(me,dir+".c");
//  	write("bdir= "+dir+"\n");
	}
	if( file_size(dir)==-2 && dir[strlen(dir)-1] != '/' ) dir += "/";
//  	write("cdir= "+dir+"\n");
	files = get_dir(dir, -1);
	if( !sizeof(files) )
	{
		if (file_size(dir) == -2) return notify_fail("目录是空的。\n");
		else return notify_fail("没有这个文件或目录。\n");
	}
	if (dir[sizeof(dir)-1]!='/')
	 {
	 	temp = explode(dir,"/");
	 	temp -= ({temp[sizeof(temp)-1]});
Пример #2
0
void processcommand( char *command, char *P1, char *P2, char *P3 ) {

    if( strcmp(command, "createvfs") == 0 ) {
        int size = atoi(P2);
        if( (0 == strcmp(P1,"")) || 0 == P2 ) {
            printf("createvfs_FAILURE %s \n",ERR_VFS_CREATE_00);
        } else {
            createvfs (P1,size);
        }
    }
    else if( strcmp(command, "mountvfs") == 0 ) {
        if( (0 == strcmp(P1,"")) ) {
            printf("mountvfs_FAILURE %s \n",ERR_VFS_MOUNT_05);
        } else {
            if( 1 == ui_mountFlag ) {
                printf("mountvfs_FAILURE %s \n",ERR_VFS_MOUNT_04);
            } else {
                mountvfs (P1);
            }
        }
    }
    else if( strcmp(command, "unmountvfs") == 0 ) {
        if( (0 == strcmp(P1,"")) ) {
            printf("unmountvfs_FAILURE %s \n",ERR_VFS_UNMOUNT_00);
        } else {
            if( 0 == ui_mountFlag ) {
                printf("unmountvfs_FAILURE %s \n",ERR_VFS_UNMOUNT_04);
            } else {
                unmountvfs (P1);
            }
        }
    }
    else if( strcmp(command, "makedir") == 0 ) {
        if( (0 == strcmp(P1,"")) || (0 == strcmp(P2,"")) ) {
            printf("makedir_FAILURE %s \n",ERR_VFS_MAKEDIR_00);
        } else {
            if( 0 == ui_mountFlag ) {
                printf("makedir_FAILURE %s \n",ERR_VFS_MAKEDIR_05);
            } else {
                makedir (P1,P2);
            }
        }
    }
    else if( strcmp(command, "deletedir") == 0 )
        deletedir (P1);
    else if( strcmp(command, "movedir") == 0 )
        movedir (P1,P2);
    else if( strcmp(command, "listdir") == 0 ) {
        int flag = atoi(P2);
        listdir (P1,flag,P3);
    }
    else if( strcmp(command, "addfile") == 0 )
        addfile (P1,P2,P3);
    else if( strcmp(command, "listfile") == 0 )
        listfile (P1,P2);
    else if( strcmp(command, "updatefile") == 0 )
        updatefile (P1,P2);
    else if( strcmp(command, "removefile") == 0 )
        removefile (P1);
    else if( strcmp(command, "movefile") == 0 )
        movefile (P1,P2);
    else if( strcmp(command, "copyfile") == 0 )
        copyfile (P1,P2);
    else if( strcmp(command, "exportfile") == 0 )
        exportfile (P1,P2);
    else if( strcmp(command, "searchfile") == 0 )
        searchfile (P1,P2);
    else
        printf("Ignoring invalid command %s\n", command);
}
Пример #3
0
int upload(void) {	/* Ändrad för nikfiles.data 960707 JÖ */
    int area,ret,editret,dirnr;
    long tid;
    struct EditLine *el;
    FILE *fp;
    __aligned struct FileInfoBlock info;
    struct Fil *allokpek;
    char nikfilename[100],errbuff[100],filnamn[50],tmpfullname[100], outbuffer[81];
    UBYTE tn;
    struct TransferFiles *tf;

    if(Servermem->cfg.ar.preup1) sendautorexx(Servermem->cfg.ar.preup1);
    if(area2==-1) {
        puttekn("\r\nI vilken area? ",-1);
    } else {
        sprintf(outbuffer,"\r\nI vilken area? (<RETURN> för %s)",Servermem->areor[area2].namn);
        puttekn(outbuffer,-1);
    }
    if(getstring(EKO,40,NULL)) return(1);
    if((area=parsearea(inmat))==-1) {
        puttekn("\n\rFinns ingen sådan area!\n\r",-1);
        return(0);
    } else if(area==-3) {
        if(area2==-1) return(0);
        area=area2;
    }
    if(!arearatt(area, inloggad, &Servermem->inne[nodnr])) {
        puttekn("\n\rFinns ingen sådan area!\n\r",-1);
        return(0);
    }
    if((Servermem->areor[area].flaggor & AREA_NOUPLOAD) && (Servermem->inne[nodnr].status < Servermem->cfg.st.laddaner)) {
        puttekn("\n\n\rDu har ingen rätt att ladda upp till den arean!\n\r",-1);
        return(0);
    }
    Servermem->action[nodnr] = UPLOAD;
    Servermem->varmote[nodnr] = area;
    Servermem->vilkastr[nodnr] = NULL;
    if(ret=recbinfile(Servermem->cfg.ultmp)) {
        while(tf=(struct TransferFiles *)RemHead((struct List *)&tf_list))
            FreeMem(tf,sizeof(struct TransferFiles));
        if(carrierdropped()) return(1);
        return(0);
    }

    /* printf("Filnamn = %s\n",FilePart(tf->Filnamn));
    printf("Cps = %d\n\n",tf->cps); */

    for(tf=(struct TransferFiles *)tf_list.mlh_Head; tf->node.mln_Succ; tf=(struct TransferFiles *)tf->node.mln_Succ) {
        strcpy(xprfilnamn,tf->Filnamn);
        if(stcgfn(filnamn,xprfilnamn)>40) puttekn("\r\nVARNING! Filnamnet större än 40 tecken!\r\n",-1);
        if(!filnamn[0]) {
            puttekn("\r\n\nHmm... Filen har inget namn. Skriv ett brev till sysop.\r\n",-1);
            continue;
        }
        if(!valnamn(filnamn,area,errbuff)) {
            for(;;) {
                puttekn(errbuff,-1);
                puttekn("\r\nNytt namn: ",-1);
                if(getstring(EKO,40,NULL)) {
                    DeleteFile(xprfilnamn);
                    return(1);
                }
                if(!inmat[0]) continue;
                if(valnamn(inmat,area,errbuff)) break;
            }
            strcpy(filnamn,inmat);
            sprintf(tmpfullname,"%s%s",Servermem->cfg.ultmp,filnamn);
            if(!Rename(xprfilnamn,tmpfullname)) {
                sprintf(outbuffer,"\r\n\nKunde inte döpa om filen från '%s'\r\ntill '%s'.\r\n",xprfilnamn,tmpfullname);
                puttekn(outbuffer,-1);
                DeleteFile(xprfilnamn);
                continue;
            }
        } else strcpy(tmpfullname,xprfilnamn);
        if(!(allokpek=(struct Fil *)AllocMem(sizeof(struct Fil),MEMF_PUBLIC | MEMF_CLEAR))) {
            puttekn("\r\n\nKunde inte allokera minne för filen!\r\n",-1);
            continue;
        }
        time(&tid);
        allokpek->tid=allokpek->validtime=tid;
        allokpek->uppladdare=inloggad;
        if(dfind(&info,tmpfullname,0)) {
            sprintf(outbuffer,"\r\nHittar inte filen %s!\r\n",tmpfullname);
            puttekn(outbuffer,-1);
            FreeMem(allokpek,sizeof(struct Fil));
            continue;
        }
        allokpek->size=info.fib_Size;

        sprintf(outbuffer,"\r\n\r\nFilnamn: %s", filnamn);
        puttekn(outbuffer,-1);
        puttekn("\r\nVilken status ska behövas för att ladda ner filen? (0)",-1);
        if(getstring(EKO,3,NULL)) {
            FreeMem(allokpek,sizeof(struct Fil));
            return(1);
        }
        allokpek->status=atoi(inmat);
        if(Servermem->inne[nodnr].status >= Servermem->cfg.st.filer) {
            puttekn("\n\rSka filen valideras? ",-1);
            if(jaellernej('j','n',1)) puttekn("Ja",-1);
            else {
                puttekn("Nej",-1);
                allokpek->flaggor|=FILE_NOTVALID;
            }
            puttekn("\n\rSka filen ha fri download? ",-1);
            if(jaellernej('j','n',2)) {
                puttekn("Ja",-1);
                allokpek->flaggor|=FILE_FREEDL;
            } else puttekn("Nej",-1);
        } else if(Servermem->cfg.cfgflags & NICFG_VALIDATEFILES) allokpek->flaggor|=FILE_NOTVALID;
        sendfile("NiKom:Texter/Nyckelhjälp.txt");
        puttekn("\r\nVilka söknycklar ska filen ha? (? för att få en lista)\r\n",-1);
        if(editkey(allokpek->nycklar)) {
            FreeMem(allokpek,sizeof(struct Fil));
            return(1);
        }
        puttekn("\r\nBeskrivning:\r\n",-1);
        if(getstring(EKO,70,NULL)) {
            FreeMem(allokpek,sizeof(struct Fil));
            return(1);
        }
        strcpy(allokpek->beskr,inmat);
        dirnr = ChooseDirectoryInFileArea(
                    area, allokpek->nycklar, allokpek->size);
        if(dirnr==-1) {
            puttekn("\r\n\nKunde inte hitta något lämpligt directory för filen!\r\n",-1);
            DeleteFile(tmpfullname);
            FreeMem(allokpek,sizeof(struct Fil));
            continue;
        }
        allokpek->dir=dirnr;
        strcpy(allokpek->namn,filnamn);
        sprintf(inmat,"%s %s",tmpfullname,Servermem->areor[area].dir[dirnr]);
        argument=inmat;
        sendrexx(10);
        AddTail((struct List *)&Servermem->areor[area].ar_list,(struct Node *)allokpek);
        if(writefiles(area)) {
            puttekn("\r\n\nKunde inte skriva till datafilen\r\n",-1);

        }

        Servermem->inne[nodnr].upload++;
        Statstr.ul++;
        if(Servermem->cfg.logmask & LOG_UPLOAD) {
            LogEvent(USAGE_LOG, INFO, "%s laddar upp %s",
                     getusername(inloggad), allokpek->namn);
        }
        if(Servermem->cfg.ar.postup1) sendautorexx(Servermem->cfg.ar.postup1);
        puttekn("\r\n\nVill du skriva en längre beskrivning? (J/n) ",-1);
        while((tn=gettekn())!='j' && tn!='J' && tn!='n' && tn!='N' && tn!=13);
        if(tn=='j' || tn=='J') {
            puttekn("\r\n\nOk, går in i editorn.\r\n",-1);
            if((editret=edittext(NULL))==1) return(1);
            else if(editret==2) continue;
            sprintf(nikfilename,"%slongdesc/%s.long",Servermem->areor[area].dir[dirnr],filnamn);
            if(!(fp=fopen(nikfilename,"w"))) {
                puttekn("\r\n\nKunde inte öppna longdesc-filen\r\n",-1);
                freeeditlist();
                continue;
            }
            for(el=(struct EditLine *)edit_list.mlh_Head; el->line_node.mln_Succ; el=(struct EditLine *)el->line_node.mln_Succ) {
                if(fputs(el->text,fp)) {
                    freeeditlist();
                    fclose(fp);
                    continue;
                }
                fputc('\n',fp);
            }
            freeeditlist();
            fclose(fp);
            puttekn("\r\n",-1);
            allokpek->flaggor|=FILE_LONGDESC;
            updatefile(area,allokpek);
        }
    }

    while(tf=(struct TransferFiles *)RemHead((struct List *)&tf_list))
        FreeMem(tf,sizeof(struct TransferFiles));

    return(0);
}
Пример #4
0
main(int argc, char *argv[])
{
int error;
int i,fd;
int pagenum,*buf;
int *buf1,*buf2;
int fd1,fd2;
int nowrites;

//int stale_file[2][];
	if( argc == 3 )
	{
		printf("output The argument supplied are %s, %s\n", argv[1], argv[2]);
		//char temp[] = *argv[1];
		//nowrites = *argv[2];
		sscanf(argv[1], "%d", &filesize); 
		sscanf(argv[2], "%d", &nowrites);
		filesize = filesize*PF_MAX_BUFS; 
		printf("output final The argument supplied are %d, %d\n", filesize, nowrites);
	}
	else
	{
		printf("One argument expected.\n");
		filesize = 2*PF_MAX_BUFS;
		nowrites = 20;
	}
	/* create a few files */
	if ((error=PF_CreateFile(FILE1))!= PFE_OK){
		PF_PrintError("file1");
		exit(1);
	}
	printf("file size - %d", filesize);
	int stale_file1[20000];
	for (i=0; i<filesize; i++)
	{
		stale_file1[i] = 0;
	}
	printf("file1 created\n");

	if ((error=PF_CreateFile(FILE2))!= PFE_OK){
		PF_PrintError("file2");
		exit(1);
	}
	int stale_file2[20000];
	for (i=0; i<filesize; i++)
	{
		stale_file2[i] = 0;
	}
	printf("file2 created\n");

	
	/* write to file1 */
	writefile(FILE1,stale_file1);

	/* print it out */
	readfile(FILE1,stale_file1);
	
	
	//Sequential Updates
	reads = 0;
	writes = 0;
	erases = 0;
	if ((fd=PF_OpenFile(FILE1))<0){
		PF_PrintError("open file");
		exit(1);
	}
	pagenum = -1;
	int temp = 0;
	printf("\noutput final Sequential Updates\n");
	while (temp<nowrites && (error=PF_GetNextPage(fd,&pagenum,&buf))== PFE_OK)
	//for(i=0; i<nowrites; i++)
	{
		i = pagenum;
		temp++;
		if ((error=PF_UnfixPage(fd,pagenum,FALSE))!= PFE_OK){
			PF_PrintError("unfix");
			exit(1);
		}
		updatefile(FILE1,stale_file1,i);
	}
	printf("reads - %d\n", reads);
	printf("erases - %d\n", erases);
	printf("writes - %d\n", writes);
	garbagecollect(FILE1,stale_file1);
	printf("output file size - %d\n", filesize);
	printf("output Number of updates - %d\n", nowrites);
	printf("output Number of pages in block - %d\n", PAGEINBLOCK);
	printf("output After garbage collection\n");
	printf("output final reads - %d\n", reads);
	printf("output final erases(in units of blocks) - %d\n", erases/PAGEINBLOCK);
	printf("output final writes - %d\n", writes);
	
	if ((error=PF_CloseFile(fd))!= PFE_OK){
		PF_PrintError("close file");
		exit(1);
	}
	readfile(FILE1, stale_file1);

	/* write to file2 */
	writefile(FILE2,stale_file2);

	/* print it out */
	readfile(FILE2,stale_file2);
		

	//Random Updates 
	reads = 0;
	writes = 0;
	erases = 0;
	if ((fd=PF_OpenFile(FILE2))<0){
		PF_PrintError("open file");
		exit(1);
	}
	pagenum = -1;
	temp = 0;
	printf("\noutput final Random Updates\n");
	while (temp<nowrites && ((error=PF_GetNextPage(fd,&pagenum,&buf))== PFE_OK || error == PFE_EOF) )
	//for(i=0; i<nowrites; i++)
	{
		if(error == PFE_EOF)
		{
			printf("output EOF reached\n");
			pagenum = -1;
			continue;
		}
		i = pagenum;
		if ((error=PF_UnfixPage(fd,pagenum,FALSE))!= PFE_OK){
			printf("outputerror - %d\n", error);
			PF_PrintError("unfix");
			exit(1);
		}
		int j = rand();
		if(j%2 == 0) continue;
		temp++;
		//printf("output i : %d", i);
		//int j = rand() % filesize;
		updatefile(FILE2,stale_file2,i);
		if(temp==nowrites/2) 
		{
			printf("output Before garbage collection1:-\n");
			printf("output reads - %d\n", reads);
			printf("output erases(in units of blocks) - %d\n", erases/PAGEINBLOCK);
			printf("output writes - %d\n", writes);
			numpages(FILE2,stale_file2);
			printf("output total number of pages - %d, stale pages is - %d\n", numtotal,numstale);
			garbagecollect(FILE2,stale_file2);
			printf("output After garbage collection1:-\n");
			printf("output reads - %d\n", reads);
			printf("output erases(in units of blocks) - %d\n", erases/PAGEINBLOCK);
			printf("output writes - %d\n", writes);
			numpages(FILE2,stale_file2);
			printf("output total number of pages - %d, stale pages is - %d\n", numtotal,numstale);
		}
	}
	if(error != PFE_OK) 
	{
		PF_PrintError("output");
	}
	printf("output Before garbage collection2\n");
	printf("output reads - %d\n", reads);
	printf("output erases(in units of blocks) - %d\n", erases/PAGEINBLOCK);
	printf("output writes - %d\n", writes);
	numpages(FILE2,stale_file2);
	printf("output total number of pages - %d, stale pages is - %d\n", numtotal,numstale);
	garbagecollect(FILE2,stale_file2);
	printf("output file size - %d\n", filesize);
	printf("output Number of updates - %d, %d\n", temp, nowrites);
	printf("output Number of pages in block - %d\n", PAGEINBLOCK);
	printf("output After garbage collection2\n");
	printf("output final reads - %d\n", reads);
	printf("output final erases(in units of blocks) - %d\n", erases/PAGEINBLOCK);
	printf("output final writes - %d\n", writes);
	numpages(FILE2,stale_file2);
	printf("output total number of pages - %d, stale pages is - %d\n", numtotal,numstale);
		
	if ((error=PF_CloseFile(fd))!= PFE_OK){
		PF_PrintError("close file");
		exit(1);
	}
	readfile(FILE2, stale_file2);

	//readfile(FILE1,stale_file1);
	
	//garbagecollect(FILE1,stale_file1);
	
	//readfile(FILE1,stale_file1);
}