Beispiel #1
0
int main( int argc, char** argv )
{
    if ( argc < 4 ) {
        usage( argv[0] );
        return( 1 );
    }
    if ( initialize_fs( argv[1], argv[2], argv[3], NULL, 0 ) < 0 ) {
        printf( "Error: Failed to format %s: %s\n", argv[1], strerror( errno ) );
    }
    return( 0 );
}
Beispiel #2
0
void MainWindow::LoadFilesystems()
{
	system( "dd if=/dev/random of=/tmp/TestDrive bs=1024 count=8192 && sync" );
	pDir = opendir("/system/drivers/fs/");
	while ( (psEntry = readdir( pDir )) != NULL)
	{
			if ( initialize_fs( "/tmp/TestDrive", psEntry->d_name, "TEST", NULL, 0 ) < 0 )
			{
				continue;
			} else {
				m_pcFilesystem_Selection->AppendItem( psEntry->d_name );
			}
	}
	m_pcFilesystem_Selection->SetSelection(0);
}
Beispiel #3
0
void MainWindow::Format()
{
			/* Show Splash Screen */
			Splash* pcWindow = new Splash(LoadImageFromResource("logo.png"),"Formatting...",false,0.0);
			pcWindow->Go();

			/* Get Device */
			char zDevice[24];
			int nDevice = m_pcDevice_Selection->GetSelection();
			if( nDevice == 0 )
			{
				m_pcFileRequester = new os::FileRequester( os::FileRequester::LOAD_REQ, new os::Messenger( this ), zDevice, os::FileRequester::NODE_FILE, true );
				m_pcFileRequester->Show();
				m_pcFileRequester->MakeFocus();
				printf(zDevice);
			} else {
				sprintf(zDevice, "%s", m_pcDevice_Selection->GetItem(nDevice).c_str());
			}

			/* Get Filesystem */
			int nFilesystem = m_pcFilesystem_Selection->GetSelection();
			char zFilesystem[16];
			sprintf(zFilesystem, "%s", m_pcFilesystem_Selection->GetItem(nFilesystem).c_str());

			/* Get Volumename */
			os::String cVolumename = m_pcVolumename_Text->GetValue();
			char zVolumename[32];
			sprintf(zVolumename, "%s", cVolumename.c_str());

			/* Get Arguments */
			os::String cArguments = m_pcArguments_Text->GetValue();
			char zArguments[64];
			sprintf(zArguments, "%s", cArguments.c_str());

			/* Format */
			if ( initialize_fs( zDevice, zFilesystem, zVolumename, NULL, 0 ) < 0 ) {
				char zError[256];
				sprintf( zError, "%s", strerror(errno));
				os::Alert* pcAlert = new os::Alert( "Format", zError, m_pcIcon->LockBitmap(),0, "_Ok",NULL);
				pcAlert->Go( new os::Invoker( 0 ) );
			}

			/*  Remove Splash Screen */
			pcWindow->Quit();
}
int main()
{
int fsinit = 0;
char input[256];
char *parser;
unsigned short n = 0;
char dirbuf[BLOCK_SIZE];
int i =0;
unsigned short bytes_written;
unsigned int number_of_blocks =0, number_of_inodes=0;

printf("Enter command:\n");
while(1)
{

scanf(" %[^\n]s", input);
parser = strtok(input," ");

if(strcmp(parser, "initfs")==0)
{
char *filepath;
char *num1, *num2;
filepath = strtok(NULL, " ");
num1 = strtok(NULL, " ");
num2 = strtok(NULL, " ");
	if(access(filepath, F_OK) != -1)
	{
	if((fd = open(filepath,O_RDWR,0600))== -1)
    {
        printf("\n filesystem already exists but open() failed with error [%s]\n",strerror(errno));
         return 1;
    }
	printf("filesystem already exists and the same will be used.\n");
	fsinit=1;
	}
	else
	{
	if (!num1 || !num2)
	  printf(" All arguments(path, number of inodes and total number of blocks) have not been entered\n");
		else
		{
		number_of_blocks = atoi(num1);
		number_of_inodes = atoi(num2);
		
		if(initialize_fs(filepath,number_of_blocks, number_of_inodes))
		{
		printf("The file system is initialized\n");
		fsinit = 1;
		}
		else
		{
		printf("Error initializing file system. Exiting... \n");
		return 1;
		}
		}
	}
 parser = NULL;
}
	else if(strcmp(parser, "mkdir")==0)
	{
		char *dirname;
	
	 if(fsinit == 0)
	 printf("The file system is not initialized. Please retry after initializing file system\n");
	 else
	 {
	  dirname = strtok(NULL, " ");
	  if(!dirname)
	    printf("No directory name entered. Please retry\n");
	  else
	  {
	  unsigned int dirinum = allocateinode();
	  if(dirinum < 0)
		{
		 printf("Error : ran out of inodes \n");
		 return 1;
		}
	  mkdirectory(dirname,dirinum);
	  }
	  }
	   parser = NULL;
	}
	else if(strcmp(parser, "cpin")==0)
	{
		char *targname;
		char *srcname;
	  if(fsinit == 0)
	 printf("The file system is not initialized. Please retry after initializing file system\n");
	  else
	  {

	  srcname = strtok(NULL, " ");
	  targname = strtok(NULL, " ");
	 
	  if(!srcname || !targname )
	    printf("Required file names(source and target file names) have not been entered. Please retry\n");
	  else
	  {
	  	
	   cpin(srcname,targname);
	  }
	  }
	   parser = NULL;
	}
	else if(strcmp(parser, "cpout")==0)
	{
		char *targnameout;
		char *srcnameout;
	 if(fsinit == 0)
	  printf("The file system is not initialized. Please retry after initializing file system\n");
	 else
	  {
	  
	  srcnameout = strtok(NULL, " ");
	  targnameout = strtok(NULL, " ");
	 
	  if(!srcnameout || !srcnameout )
	    printf("Required file names(source and target file names) have not been entered. Please retry\n");
	  else
	  {
	  	
	   cpout(srcnameout,targnameout);
	  }
	  }
	   parser = NULL;
	}
	else if(strcmp(parser, "q")==0)
	{
	
	lseek(fd,BLOCK_SIZE,0);

	 if((bytes_written =write(fd,&super,BLOCK_SIZE)) < BLOCK_SIZE)
	 {
	 printf("\nERROR : error in writing the super block");
	 return 1;
	 } 
	
	return 0;
	}
	else
	{
	printf("\nInvalid command\n ");
	}
	}
}