Beispiel #1
0
int Server_Creat(int pinum, int type, char *name){

    Data_Init();

	if(Inode_BitMap.bits[pinum] == false || inode_table[pinum].type != MFS_DIRECTORY){
		return -1;
	}

	if(Server_LookUp(pinum,name) >= 0){
		return 0;
	}

	int inum = First_Empty(&Inode_BitMap);
	Set_Bit(&Inode_BitMap, inum);

	if(Add_Entry(pinum, inum, name, inode_table, data_region) != 0){
		fprintf(stderr,"add entry error\n");
	}

	if(type == MFS_REGULAR_FILE){
		inode_table[inum].type = type;
		inode_table[inum].size = 0;
		inode_table[inum].blocks = 0;
		int i;
		for(i = 0; i < MFS_PTR_NUMS; i++){
			inode_table[inum].ptr[i] = -1;
		}
	}

	if(type == MFS_DIRECTORY){
		int to_write_block = First_Empty(&Data_BitMap);
		Set_Bit(&Data_BitMap,to_write_block);
		inode_table[inum].type = type;
		inode_table[inum].size = 2 * sizeof(MFS_DirEnt_t);
		inode_table[inum].blocks = 1;
		inode_table[inum].ptr[0] = to_write_block;
		int i;
		for(i = 1; i < MFS_PTR_NUMS; i++){
			inode_table[inum].ptr[i] = -1;
		}

		MFS_DirEnt_t * entries = (MFS_DirEnt_t *) data_region[to_write_block].data;

		entries[0].inum = inum;
		strcpy(entries[0].name, ".");
		entries[1].inum = pinum;
		strcpy(entries[1].name, "..");

		for(i = 2; i < MFS_BLOCK_SIZE / sizeof(MFS_DirEnt_t); i++){
			entries[i].inum = -1;
		}
	}

	Data_Write();

	return 0;
}
Beispiel #2
0
int list_file(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
    int i;
    int len_name;

    if(ftwbuf->level == 1)
    {
        if(strcmp(fpath, Dir_Act))
        {
            switch(typeflag)
            {
                case FTW_D:
                    len_name = strlen(fpath);
                    while(len_name--)
                    {
                        if(fpath[len_name] == '/')
                        {
                            len_name++;
                            break;
                        }
                    }
                    
                    nbr_dirs++;
                    Add_Entry(&fpath[len_name], _A_SUBDIR);
                    break;

                case FTW_F:
                    len_name = strlen(fpath);
                    while(len_name--)
                    {
                        if(fpath[len_name] == '/')
                        {
                            len_name++;
                            break;
                        }
                    }
                    
                    Add_Entry(&fpath[len_name], _A_FILE);
                    break;
            }
        }
    }
    return 0;
}
Beispiel #3
0
int Modify_Entry(struct table *a, int row, char * entry, bool first)
{
	int result = -1;

	if(a->entries[row] != NULL)
	{
		if(first)
		{
			Delete_Entry(a, row);
			Add_Entry(a, row, entry, true);
		}
		else
			Add_Entry(a, row, entry, false);

		result = 1;
	}

	return result;
}
Beispiel #4
0
// ------------------------------------------------------
// Fill the list with the content of the relevant directory
void Read_SMPT(void)
{
    int i;

    lt_items[Scopish] = 0;  
    list_counter[Scopish] = 0;

#if defined(__WIN32__)
    struct _finddata_t c_file;
#endif

    long hFile;

    nbr_dirs = 0;

    switch(Scopish)
    {
        case SCOPE_ZONE_MOD_DIR:
            cur_dir = Dir_Mods;
            break;
        case SCOPE_ZONE_INSTR_DIR:
            cur_dir = Dir_Instrs;
            break;
        case SCOPE_ZONE_PRESET_DIR:
            cur_dir = Dir_Presets;
            break;
        case SCOPE_ZONE_REVERB_DIR:
            cur_dir = Dir_Reverbs;
            break;
        case SCOPE_ZONE_PATTERN_DIR:
            cur_dir = Dir_Patterns;
            break;
        case SCOPE_ZONE_SAMPLE_DIR:
            cur_dir = Dir_Samples;
            break;
        case SCOPE_ZONE_MIDICFG_DIR:
            cur_dir = Dir_MidiCfg;
            break;
    }
    CHDIR(cur_dir);

    // Find first .c file in current directory
    strcpy(Dir_Act, cur_dir);

#if defined(__WIN32__)
    strcat(Dir_Act, "\\*.*");

    if((hFile = _findfirst(Dir_Act, &c_file)) == -1L)
    {
        Add_Entry("No files in current directory.", 0);
    }
    else
    {
        // The first directory
        if(c_file.attrib & _A_SUBDIR)
        {
            if(strcmp(c_file.name, ".") &&
               strcmp(c_file.name, ".."))
            {
                nbr_dirs++;
                Add_Entry(c_file.name, _A_SUBDIR);
            }
        }

        // Find the rest of the directories 
        while(_findnext(hFile, &c_file) == 0)
        {
            if(c_file.attrib & _A_SUBDIR)
            {
                if(strcmp(c_file.name, ".") &&
                   strcmp(c_file.name, ".."))
                {
                    nbr_dirs++;
                    Add_Entry(c_file.name, _A_SUBDIR);
                }
            }
        }
        // End dir
        _findclose(hFile);

        if((hFile = _findfirst(Dir_Act, &c_file)) != -1L)
        {
            // The first file
            if(!(c_file.attrib & _A_SUBDIR))
            {
                Add_Entry(c_file.name, 0);
            }
            // Find the rest of the files
            while(_findnext(hFile, &c_file) == 0)
            {
                if(!(c_file.attrib & _A_SUBDIR))
                {
                    Add_Entry(c_file.name, 0);
                }
            } // while      
            _findclose(hFile);

            if(sort_files)
            {
                qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files);
                //Insert_List_Separators();
            }
            //else
            {
                Insert_Entry("", _A_SEP, 0);
            }
            Insert_Entry("..", _A_SUBDIR, 0);
            Insert_Entry(".", _A_SUBDIR, 0);
        }
    }

    // Add the available drives to the bottom of the list
    char *Ptr_Drives;
    GetLogicalDriveStrings(1024, List_Drives);

    Ptr_Drives = List_Drives;
    i = 0;
    if(Ptr_Drives[0]) Add_Entry("", _A_SEP);
    while(Ptr_Drives[0])
    {
        Add_Entry(Ptr_Drives, _A_SUBDIR);
        Ptr_Drives += strlen(Ptr_Drives) + 1;
    }

#elif defined(__AMIGAOS4__) || defined(__AROS__)

#if defined(__AMIGAOS4__)
#define LockDosList(f) IDOS->LockDosList(f)
#define NextDosEntry(d,f) IDOS->NextDosEntry(d, f)
#define CopyStringBSTRToC(bin,sout,len) IDOS->CopyStringBSTRToC(bin, sout, len)
#define	UnLockDosList(f) IDOS->UnLockDosList(f)
#endif

    if (!strcmp(Dir_Act, "/"))
    {
        // Only display volumes
        struct DosList *dl;
        const uint32 flags = LDF_VOLUMES | LDF_READ;
        char BString[1024];
        dl = LockDosList(flags);
        while ((dl = NextDosEntry(dl, flags)) != NULL)
        {
            // Convert it first
            CopyStringBSTRToC(dl->dol_Name, BString, sizeof(BString));
            Add_Entry(BString, _A_SUBDIR);
        }
        UnLockDosList(flags);
    }
    else
    {
        DIR *dirp;
        struct dirent *dp;

        dirp = opendir(Dir_Act);
        if (dirp)
        {
            // Add the directories first
            while ((dp = readdir(dirp)) != NULL)
            {
                if(dp->d_type == DT_DIR)
                {
                    nbr_dirs++;
                    Add_Entry(dp->d_name, _A_SUBDIR);
                }
            }
            closedir(dirp);
        }

        dirp = opendir(Dir_Act);
        if (dirp)
        {
            // Then add the files
            while ((dp = readdir(dirp)) != NULL)
            {
                if(dp->d_type != DT_DIR)
                {
                    Add_Entry(dp->d_name, 0);
                }
            }
            closedir(dirp);
        }

        if(sort_files)
        {
            qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files);
            //Insert_List_Separators();
        }
        //else
        {
            Insert_Entry("", _A_SEP, 0);
        }
        // Insert parent directory at the top
        Insert_Entry("/", _A_SUBDIR, 0);
    }

#else

    // Enum them
    nftw(Dir_Act, &list_file, FTW_PHYS, 0);

    if(sort_files)
    {
        qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files);
        //Insert_List_Separators();
    }
    //else
    {
        Insert_Entry("", _A_SEP, 0);
    }
    // Always insert them at the top of the list
    Insert_Entry("../", _A_SUBDIR, 0);
    Insert_Entry("./", _A_SUBDIR, 0);

#endif

    // Insert a separator between files and directories
    if(nbr_dirs)
    {
        for(i = list_counter[Scopish] - 1; i >= 0; i--)
        {
            if(SMPT_LIST[i].Type == _A_FILE)
            {
                Insert_Entry("", _A_SEP, i + 1);
                break;
            }
        }
    }
}
Beispiel #5
0
void server()
{
    int i, j, run_length = 0, print_lock = 0;
    short print_Requested = 0;
    char * all_strings;
	struct table t;
	Create_table(&t);
	Message_t msg;
	msg = (Message_t)malloc(sizeof(struct message));

	openPort(SERVER_PORT);
	while(1)
	{
            print_lock = 0;
			for(i = 0; i < 10; i++)
				if(t.status[i] == LOCKED)
				{
					msg->error_code = -1;
					print_lock = 1;
				}

			if(print_Requested && !print_lock)
			{

				for(i = 0; i < 10; i++)
				{
				 if(t.entries[i]!=NULL)
                    run_length += strlen(t.entries[i]);
				}

				all_strings = malloc((run_length+10) * sizeof(char));
				run_length = 0;
				for(i = 0; i < 10; i++)
				{
					 if(t.entries[i]!=NULL)
					 {
					     for(j = 0; j < strlen(t.entries[i]); j++)
                            all_strings[run_length++] = t.entries[i][j];
						all_strings[run_length++] = '\n';
					 }

				}
				j=0;
				msg->total_size = run_length;
				msg->error_code = 1; //Extended transmission
				while((run_length = run_length - 10) > -9)
				{
					char line[MESSAGE_LENGTH] = "";
					for(i = 0; (i < MESSAGE_LENGTH) && (j < msg->total_size); i++)
						line[i] = all_strings[j++];
					memcpy(msg->msg, line, MESSAGE_LENGTH * sizeof(char));
					if(j >= msg->total_size)
						msg->error_code = 0; //End of transmission
					Send(msg->reply_port, msg);
				}
                print_lock = 0;
                print_Requested = 0;
			}


		Receive(SERVER_PORT, msg);

		//also, take care of print request
		if(msg->operation == PRINT)
		{
			//check if anything is locked
			for(i = 0; i < 10; i++)
				if(t.status[i] == LOCKED)
				{
					msg->error_code = -1;
					print_lock = 1;
					print_Requested = 1;
				}
			if(!print_lock)
			{
				for(i = 0; i < 10; i++)
					run_length += strlen(t.entries[i]);

				all_strings = malloc((run_length + 10) * sizeof(char));
				run_length = 0;
				for(i = 0; i < 10; i++)
				{
					for(j = 0; j < strlen(t.entries[i]); j++)
						all_strings[run_length++] = t.entries[i][j];
					all_strings[run_length++] = '\n';
				}
				j=0;
				msg->total_size = run_length;
				msg->error_code = 1; //Extended transmission
				while((run_length = run_length - 10) > -9)
				{
					char line[MESSAGE_LENGTH] = "";
					for(i = 0; (i < MESSAGE_LENGTH) && (j < msg->total_size); i++)
						line[i] = all_strings[j++];
					memcpy(msg->msg, line, MESSAGE_LENGTH * sizeof(char));
					if(j >= msg->total_size)
						msg->error_code = 0; //End of transmission
					Send(msg->reply_port, msg);
				}
			print_lock = 0;
			print_Requested = 0;
			}
			else
			{
			    continue;
			}

		}
		else if( t.status[msg->row] == LOCKED ) //Resource is locked
		{
			if(msg->reply_port != t.locker[msg->row]) //Resource is locked by some other client, cannot lock
				msg->error_code = -1;
			else //Resource requestor is also the resource locker
			{
				if(msg->error_code == 1) //Extended transmission ongoing, more msgs to come
				{
					if(msg->operation == ADD)
						msg->error_code = Add_Entry(&t, msg->row, msg->msg, false);
					else if(msg->operation == MODIFY)
						msg->error_code = Modify_Entry(&t, msg->row, msg->msg, false);
				}
				else //Last message of extended transmission
				{
					if(msg->operation == ADD)
						msg->error_code = Add_Entry(&t, msg->row, msg->msg, false);
					else if(msg->operation == MODIFY)
						msg->error_code = Modify_Entry(&t, msg->row, msg->msg, false);

					Unlock(&t, msg->row);
				}
			}
		}
		else //Not locked
		{
			if(msg->error_code == 1) //Extended transmission, lock
			{
				Lock(&t, msg->row, msg->reply_port);
				if(msg->operation == ADD)
					msg->error_code = Add_Entry(&t, msg->row, msg->msg, true);
				else if(msg->operation == MODIFY)
					msg->error_code = Modify_Entry(&t, msg->row, msg->msg, true);
			}
			else
			{
				if(msg->operation == ADD)
					msg->error_code = Add_Entry(&t, msg->row, msg->msg, true);
				else if(msg->operation == MODIFY)
					msg->error_code = Modify_Entry(&t, msg->row, msg->msg, true);
				else
					msg->error_code = Delete_Entry(&t, msg->row);

			}
		}
		Send(msg->reply_port, msg);

	}

	closePort(SERVER_PORT);
}