void stat(FILE *fp1) // To give information about file metadata
{
	int a,in,size,sind;
	char g,fnam[15],m;
	printf("\nEnter the filename with extension for which you want to get information\n");
	g=getchar();
	gets(fnam);
	a=search_f(fnam);
	if(a==1)
	{
		printf("\nFile does not exist\n");
	}
	else
	{
		fseek(fp1,a,0);
		in=getw(fp1);
		printf("Inode No: %d\n",in);
		printf("File Name: %s\n",fnam);
		fseek(fp1,17,1);
		size=getw(fp1);
		printf("File Size: %d\n",size);
		fseek(fp1,1,1);
		sind=getw(fp1);
		printf("Single Indirect block Address: %d\n",sind);
		fseek(fp1,1,1);
		fread(&m,1,1,fp1);
			if(m=='s')
			printf("Read and write permission\n");
			if(m=='r')
			printf("Read only permission\n");
			if(m=='w')
			printf("Write only permission\n");
	}
	return;
}		 
void write(FILE *fp1) // To write data at the dataspace for a file
{
	int a,u,si,free_point,da2=1,siz;
	char cm[15],g,h,inpdat[100],m,c;
	printf("\nEnter the file name with extension you want to write in\n");
	g=getchar();
	gets(cm);
	a=search_f(cm);
	if(a==1)
	printf("\nFile does not exist\n");
	else
	{
		fseek(fp1,a+31,0);
		fread(&m,1,1,fp1);
		if(m=='r')
		{
			printf("\nUser has read only permisssion so can't write\n");
		}
		else
		{	
			fseek(fp1,a+26,0);
			si=getw(fp1);
			fseek(fp1,frees,0);
	
	while(da2!=0)
	{       
         	da2=getw(fp1);
		printf("\n%d\n",da2);
		if(da2==0)
		{
			fseek(fp1,-4,1);
                        putw(da,fp1);
			//fseek(fp1,frees,0);
			//u=getw(fp1);
			//printf("%d",u);
			//fseek(fp1,4,1);
                        fwrite(&co,1,1,fp1);
      		}
		else
		{		
			fseek(fp1,frees+4,1);
			da=da+102400;	
		}
	}
	        fseek(fp1,si,0);
		putw(da,fp1);
		fwrite(&co,1,1,fp1);
		//printf("%d",da);
		fseek(fp1,da,0);
		printf("\nEnter the data you want to put in a file\n");
		h=getchar();
		gets(inpdat);
		siz=strlen(inpdat);
		fwrite(inpdat,100,1,fp1);
		fseek(fp1,a+21,0);
		putw(siz+1,fp1);
		
		}
	}		
}
Пример #3
0
/*
 * User friendly wrapper to call search from other modules.
 */
int search_api(struct sip_msg *msg, str *regex){
	int retval;

	void **param=pkg_malloc(sizeof(void*));
	
	*param=pkg_malloc(regex->len+1);
	memcpy(*param,regex->s,regex->len);
	memset(*param+regex->len,0,1);
	
	fixup_regexp_none(param,1);
	
	retval=search_f(msg, *param, NULL);
	
	fixup_free_regexp_none(param,1);
	pkg_free(param);
	
	return retval;
	
}
void read(FILE *fp1)// To read file data from data space
{
	int a,b,c,d,e;
	char g,namre[15],m,re[100];
	printf("\nEnter the name of the file with extension you want to read\n");
	g=getchar();
	gets(namre);
	printf("Enter no.of characters you want to read\n");
	scanf("%d",&e);
	a=search_f(namre);
	if(a==1)
	{
		printf("\nFile does not exist\n");
	}
	else
	{
		fseek(fp1,a+31,0);
		fread(&m,1,1,fp1);
		if(m=='w')
		{
			printf("\nUser has write only permisssion so can't read\n");
		}
		else
		{
			fseek(fp1,a+26,0);
			b=getw(fp1);
			fseek(fp1,b,0);
			c=getw(fp1);
			if(c==0)
			printf("\nFile is empty\n");
			else
			{
			fseek(fp1,c,0);
			fread(re,e,1,fp1);
			printf("%s\n",re);
			}
		}	

	}
	
	
	
}
Пример #5
0
int main()
{
    int i;
    char chose[MAXLEN];
    struct cell_f **f;
    struct cell_c **c;
    struct cell_f *head_f = NULL;
    struct cell_c *head_c = NULL;
    struct cell_f *h_f = NULL;
    FILE *fp_f, *fp_c;

    printf("Welcome!\n");

    if ((fp_f = fopen("original_file.dat", "r")) == NULL) {
        fprintf(stderr, "Cannot open file: original_filet.dat\n");
        return;
    }

    if ((fp_c = fopen("category_list.dat", "r")) == NULL) {
        fprintf(stderr, "Cannot open file: category_list.dat\n");
        return;
    }


    f = make_original_file_list(&head_f, fp_f);
    c = make_original_category_list(&head_c, fp_c);

    i = 0;

    while(i != 1) {
        printf("機能一覧を表示します。\n");
        printf("0: 新規ファイルの登録 \n1: 既存ファイルの削除 \n2: 任意のファイル、任意の項目への修正 \n3: 既存のファイルの検索 \n4: 新たな分類項目の追加 \n5: 既存の分類項目の削除 \n6: 任意のファイルのコメント抽出\n");
        printf(">");
        scanf("%s", chose);

        if(strlen(chose) > 1) {
            printf("入力エラーです。\n");
            continue;
        }

        switch (chose[0]) {
        case '0':
            insert_cell_file(c, f);
            break;

        case '1':
            delete_file(f);
            break;

        case '2':
            rename_file(f);
            break;

        case '3':
            search_f(&h_f, f);
            delete_cell(&h_f);
            break;

        case '4':
            insert_cell_category(c);
            break;

        case '5':
            delete_category(c);
            break;

        case '6':
            sub_function(f);
            break;

        default:
            printf("入力エラーです。\n");
            break;

        }

        printf("アプリケーションの実行を続けますか?\n");
        printf("0: Yes 1: No\n");
        printf(">");
        scanf("%d", &i);
        while(i != 0 && i != 1) {
            printf("アプリケーションの実行を続けますか?\n");
            printf("0: Yes 1: No\n");
            printf(">");
            scanf("%d", &i);
        }
    }

    fclose(fp_f);
    fclose(fp_c);

    if ((fp_f = fopen("original_file.dat", "w")) == NULL) {
        fprintf(stderr, "Cannot open file: original_filet.dat\n");
        return;
    }

    if ((fp_c = fopen("category_list.dat", "w")) == NULL) {
        fprintf(stderr, "Cannot open file: original_filet.dat\n");
        return;
    }

    while((*f) != NULL) {
        fprintf(fp_f, "%s %s %s %s %d\n", (*f)->main_title, (*f)->sub_title, (*f)->date, (*f)->path, (*f)->category);
        (*f) = (*f)->next;
    }

    while((*c) != NULL) {
        fprintf(fp_c, "%d %s\n", (*c)->number, (*c)->category);
        (*c) = (*c)->next;
    }

    fclose(fp_f);
    fclose(fp_c);

    return 0;
}