Beispiel #1
0
void cmd_yaffs_ls(const char *mountpt, int longlist)
{
	int i;
	yaffs_DIR *d;
	yaffs_dirent *de;
	struct yaffs_stat stat;
	char tempstr[255];

	checkMount();
	d = yaffs_opendir(mountpt);

	if(!d)
	{
		printf("opendir failed\n");
	}
	else
	{
		for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
		{
			if (longlist)
			{
				sprintf(tempstr, "%s/%s", mountpt, de->d_name);
				yaffs_stat(tempstr, &stat);
				printf("%-25s\t%7ld\n",de->d_name, stat.st_size);
			}
			else
			{
				printf("%s\n",de->d_name);
			}
		}
	}
}
Beispiel #2
0
void cmd_yaffs_mv(const char *oldPath, const char *newPath)
{
	checkMount();

	int retval = yaffs_rename(newPath, oldPath);

	if ( retval < 0)
		printf("yaffs_unlink returning error: %d\n", retval);
}
Beispiel #3
0
void cmd_yaffs_rm(const char *path)
{
	checkMount();

	int retval = yaffs_unlink(path);

	if ( retval < 0)
		printf("yaffs_unlink returning error: %d\n", retval);
}
Beispiel #4
0
void cmd_yaffs_rmdir(const char *dir)
{
	checkMount();

	int retval = yaffs_rmdir(dir);

	if ( retval < 0)
		printf("yaffs_rmdir returning error: %d\n", retval);
}
Beispiel #5
0
void cmd_yaffs_mwrite_file(char *fn, char *addr, int size)
{
	int outh;

	checkMount();
	outh = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
	if (outh < 0)
	{
		printf("Error opening file: %d\n", outh);
	}

	yaffs_write(outh,addr,size);

	yaffs_close(outh);
}
Beispiel #6
0
void cmd_yaffs_mread_file(char *fn, char *addr)
{
	int h;
	struct yaffs_stat s;

	checkMount();

	yaffs_stat(fn,&s);

	printf ("Copy %s to 0x%p... ", fn, addr);
	h = yaffs_open(fn, O_RDWR,0);
	if(h<0)
	{
		printf("File not found\n");
		return;
	}

	yaffs_read(h,addr,(int)s.st_size);
	printf("\t[DONE]\n");

	yaffs_close(h);
}
//BEGIN MAIN
int main (int argc, char *arg[]) {

	char *userInput; //what the user types in
	
	size_t buffer = 128; //sets buffer for getline()
	
	char **tokens; //array of pointers to tokens of command typed
	int numTokens; //the number of tokens in input command
	
	tokens = (char **)malloc(sizeof(char *) * 128); //mallocs tokens with a max number of 128
	
//----------------------------------------------------------------------------------------------
//BEGIN PROGRAM WHILE LOOP
	while(1) { 
	
		printf("COMMAND> "); //print prompt to user
		userInput = (char *)malloc(sizeof(char) * 128); //malloc for userInput before tokenizing
		getline(&userInput, &buffer, stdin);// get user input
		userInput[strcspn(userInput, "\n")] = '\0'; //removes null character from end of user input
		
	//---Tokenize the user input
		char *point;
		int count;
		for(count = 0, point = strtok(userInput, " "); point != NULL; count++, point = strtok(NULL, " ")) {
            tokens[count] = (char *)malloc(strlen(point) + 1);
            strcpy(tokens[count], point);
        } //END tokenizing loop
        numTokens = count; //sets the number of token var equal to the number of actual tokens
        
	//---Check for output redirection and handle output if so
        int outputFile, consoleOutput;
        fflush(stdout); //clear stdout as a precaution
        int i; //counter for output redirection loop
        for(i = 0; i < numTokens; i++) {
            if(strcmp(tokens[i], ">") == 0) {
                //Output redirection
                outputFile = open(tokens[i+1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
                consoleOutput = dup(STDOUT_FILENO); //Copy original STDOUT

                if(outputFile) {
                    dup2(outputFile, STDOUT_FILENO);
                    close(outputFile);
                }
                break; //break out of output redirection loop
            }
        } //END output redirection for loop
        
	//---QUIT COMMAND - quit the program
		if(strcmp(tokens[0], "quit") == 0) {
			break;
		}//END QUIT COMMAND
		
	//---HELP COMMAND - print the help menu
		else if(strcmp(tokens[0], "help") == 0) {
			printf("\nWelcome to the floppy program!\n");
			printf("Here is a list of commands supported...\n");
			printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
			printf("help - prints the help menu (You just did this!)\n");
			printf("	usage: 	help\n");
			printf("~\n");
			printf("fmount - mounts a floppy image\n");
			printf("	usage:	fmount [floppyname]\n");
			printf("~\n");
			printf("fumount - unmounts the mounted floppy image\n");
			printf("	usage:	fumount\n");
			printf("~\n");
			printf("structure - lists the stucture of the floppy\n");
			printf("	usage:	structure\n");
			printf("~\n");
			printf("traverse - lists the content in the root directory\n");
			printf("	usage:	traverse\n");
			printf("~\n");
			printf("traverse -l - with the -l flag, the traverse command outputs more detailed info\n");
			printf("	usage:	traverse -l\n");
			printf("~\n");
			printf("showsector - show the content (in a hex dump) of the provided sector number\n");
			printf("	usage:	showsector [sectornumber]\n");
			printf("~\n");
			printf("showfat - show the content of the FAT table (in a hex dump)\n");
			printf("	usage: showfat\n");
			printf("~\n");
			printf(">>>THIS PROGRAM SUPPORTS OUTPUT REDIRECTION<<<\n");
			printf("\n");		
		}//END HELP COMMAND
		
	//---FMOUNT COMMAND - mounts the floppy
		else if(strcmp(tokens[0], "fmount") == 0) {	
		
			int mounted;
			
			if(numTokens < 2) {
				printf("ERROR: INCORRECT USAGE - see help menu\n");
				continue;
			}
			else {
				mount(tokens[1]);
				mounted = checkMount();
				if(mounted < 0) {
					printf("ERROR: COULD NOT MOUNT FLOPPY\n");
				}
				else {
				printf("%s is mounted!\n", tokens[1]);
				}
			}				
		} //END FMOUNT COMMAND
		
	//---FUMOUNT FUNCTION - unmounts the floppy
		else if(strcmp(tokens[0], "fumount") == 0) {
			
			int mounted;
			mounted = checkMount();
			
			if(mounted < 0) {
				printf("ERROR: THERE IS NO MOUNTED FLOPPY\n");
				continue;
			}
			else {
				unmount();
				printf("You have unmounted the floppy...\n");	
			}		
		}//END FUMOUNT COMMAND
		
	//---STRUCTURE COMMAND - displays the structure of the floppy
		else if(strcmp(tokens[0], "structure") == 0) {
		
			int mounted;
			mounted = checkMount();
			
			if(mounted < 0) {
				printf("ERROR: THERE IS NO MOUNTED FLOPPY\n");
				continue;
			}
			else {
				structure();
			}	
		}//END STRUCTURE COMMAND
	
	//---TRAVERSE AND TRAVERSE -L COMMANDS
		else if(strcmp(tokens[0], "traverse") == 0) {
			
			int mounted;
			mounted = checkMount();
			
			if(mounted < 0) {
				printf("ERROR: THERE IS NO MOUNTED FLOPPY\n");
				continue;
			}
			else if(strcmp(tokens[1], "-l") == 0) {
				traverse(1);
			}
			else {
				traverse(0);
			}
		} //END TRAVERSE AND TRAVERSE -L COMMANDS
		
	//---SHOWSECTOR COMMAND
		else if(strcmp(tokens[0], "showsector") == 0) {
		
			int mounted;
			mounted = checkMount();
			
			if(mounted < 0) {
				printf("ERROR: THERE IS NO MOUNTED FLOPPY\n");
				continue;
			}
			else if(numTokens < 2) {
				printf("ERROR: INCORRECT USAGE - see help menu\n");
				continue;
			}
			else {
				int sectorNumber = atoi(tokens[1]);
				showsector(sectorNumber);		
			}
		} //END SHOWSECTOR COMMAND
	
	//---SHOWFAT COMMAND
		else if(strcmp(tokens[0], "showfat") == 0) {
		
			int mounted;
			mounted = checkMount();
			
			if(mounted < 0) {
				printf("ERROR: THERE IS NO MOUNTED FLOPPY\n");
				continue;
			}
			else {
				showfat();
			}		
		} //END SHOWFAT COMMAND
			
	//---Put output back to default (the console) (in case output redirection was used)
		fflush(stdout); //clear stdout as a precaution
		if(consoleOutput) {
			dup2(consoleOutput, STDOUT_FILENO);
			close(consoleOutput);
		} //END reset the output to console
	//---Free up userInput and tokens[]
		free(userInput);
		int j;
		for (j = 0; j < numTokens; j++) {
			free(tokens[j]);
		}//END freeing of userInput and tokens[]

	} //END PROGRAM WHILE LOOP

	return 1; //RETURN VALUE FOR main()

} //END MAIN
Beispiel #8
0
void cmd_yaffs_read_file(char *fn)
{
	checkMount();
	read_a_file(fn);
}
Beispiel #9
0
void cmd_yaffs_write_file(char *yaffsName,char bval,int sizeOfFile)
{
	checkMount();
	make_a_file(yaffsName,bval,sizeOfFile);
}
Beispiel #10
0
void cmd_yaffs_umount(char *mp)
{
	checkMount();
	if( yaffs_unmount(mp) == -1)
		printf("Error umounting %s, return value: %d\n", mp, yaffsfs_GetError());
}
Beispiel #11
0
void mountPartitions(struct List *ptlist) 
{
    struct EasyStruct es =
    {
        sizeof(struct EasyStruct), 0,
        "HDToolBox",
        0,
        "Yes|No"
    };
    struct PartitionTableNode *table;
    struct PartitionHandle *ph;
    WORD cm;
    WORD reboot = 0;

    D(bug("[HDToolBox] mountPartitions()\n"));

    table = (struct PartitionTableNode *)ptlist->lh_Head;
    while (table->ln.ln_Succ)
    {
        if (table->type != PHPTT_UNKNOWN)
        {
            ph = (struct PartitionHandle *)table->ph->table->list.lh_Head;
            while (ph->ln.ln_Succ)
            {
                if (existsAttr(table->pattrlist, PTA_AUTOMOUNT))
                {
                LONG flag;

                    GetPartitionAttrsA(ph, PT_AUTOMOUNT, &flag, TAG_DONE);
                    if (flag)
                    {
                        if (existsAttr(table->pattrlist, PTA_NAME))
                        {
                        UBYTE name[32];
                        struct DosEnvec de;
    
                            GetPartitionAttrsA(ph, PT_NAME, name, PT_DOSENVEC, &de, TAG_DONE);
                            cm = checkMount(table, name, &de);
                            if (cm == 1)
                                mount(table, ph, name, &de);
                            else if (cm == 2)
                                kprintf("may reboot\n");
                            else if (cm == 3)
                                kprintf("have to reboot\n");
                            else
                                kprintf("mount %s not needed\n", name);
                            if (reboot<cm)
                                reboot = cm;
                        }
                        else
                            kprintf("Partition with no name is automountable\n");
                    }
                }
                ph = (struct PartitionHandle *)ph->ln.ln_Succ;
            }
        }
        table = (struct PartitionTableNode *)table->ln.ln_Succ;
    }
    if (reboot > 1)
    {
        if (reboot == 2)
        {
            es.es_TextFormat =
                "A reboot is not necessary because the changes do not\n"
                "affect the work of any running filesystem.\n"
                "Do you want to reboot anyway?";
        }
        else
        {
            es.es_TextFormat =
                "A reboot is required because the changes affect\n"
                "the work of at least one running filesystem.\n"
                "Do you want to reboot now?";
        }
        if (EasyRequestArgs(0, &es, 0, 0))
            ColdReboot();
    }
}