void testRun2()
{
	pause(PAUSE);

	initFileSystem("Drive2MB", "");

	if(!virDrive)
	{
		fprintf(stderr, "Error opening drive. Exiting");
		exit(1);
	}
	fprintf(stdout, "Virtual drive opened\n");

	printBootClusterInfo();

	pause(PAUSE);

	fprintf(stdout, "\n");
	printDirectoryListing("root");
	printDirectoryListing("directory0");
	printDirectoryListing("directory1");
	printDirectoryListing("directory1/directory2");
	printDirectoryListing("directory1/directory2/directory3");

	pause(PAUSE);
}
int main(void) {
	pthread_t tConsola, tEscucharConexiones,
			  tConectarMaRTA, tLeerEntradas, tPrueba, tPersistencia;

	initFileSystem();

	pthread_create(&tPersistencia, NULL, persistirEstructuras, NULL);

	pthread_create(&tConsola, NULL, execConsola, NULL);
	pthread_create(&tEscucharConexiones, NULL, escucharConexiones, NULL);
	pthread_create(&tLeerEntradas, NULL, leerEntradas, NULL);

	pthread_join(tConsola,NULL);

	return 0;
}
Example #3
0
int open(const char *path, int mode)
{
    int fd;
    struct FileDescriptor *fdPtr;
    DirectoryEntry *entry;

    (void) mode;	// mode is ignored

    if (!gInitialized)
    {
        if (initFileSystem() < 0)
            return -1;

        gInitialized = 1;
    }

    for (fd = 0; fd < MAX_DESCRIPTORS; fd++)
    {
        if (!gFileDescriptors[fd].isOpen)
            break;
    }

    if (fd == MAX_DESCRIPTORS)
    {
        // Too many files open
        errno = EMFILE;
        return -1;
    }

    fdPtr = &gFileDescriptors[fd];

    // Search for file
    entry = lookupFile(path);
    if (entry)
    {
        fdPtr->isOpen = 1;
        fdPtr->fileLength = entry->length;
        fdPtr->startOffset = entry->startOffset;
        fdPtr->currentOffset = 0;
        return fd;
    }

    errno = ENOENT;
    return -1;
}
Example #4
0
 int main() {
 	STATUS ret;
	char msg[256];

	ret = initLcd();
	ASSERT(ret == STATUS_OK);
 	//ret = initAdc();
	//ASSERT(ret == STATUS_OK);
	ret = initMotor();
	ASSERT(ret == STATUS_OK);
	ret = initZigbee();
	ASSERT(ret == STATUS_OK);
	ret = initFileSystem();
	ASSERT(ret == STATUS_OK);

	while (!feof(MAP_FILE)){
		fscanf(MAP_FILE, "%s", msg);
		printf("%s", msg);
	}
	while(1);
	return 0;
 }
Example #5
0
int main(void) {

int retcode;
unsigned int count;
fileHandleType fh;
int useraccount;
void *message;
int messagetype;
newUserMessageType *newuser;
loginMessageType *loginuser;
newPostMessageType *newPost;
addCommentMessageType *newComment;
unsigned int postID;
int responseCode;
unsigned int nextPostID = 100;
unsigned int sessionToken;
char *postText;
int postSize;
int endIt;
    
    // using a small blocksize of 256 bytes because postings are small and this is more efficient
    retcode = initFileSystem(512, 512, 512*2000);

    securityIDFileHandle = -1;

    if (retcode != 0) {

        printf("Error making filesystem.\n");
        _terminate(-1);
    }

    retcode = makeMemoryFile("sticky.posts", 0x4347C000 + 1536, 160*16,  1,  ROOT_ID );

    if ( retcode != 0 ) {

        printf("Error making posts.log\n");
        _terminate(-1);
    }

    retcode = makeMemoryFile("initialPostID.mem", 0x4347C000, 4, 1, ROOT_ID );

    if ( retcode != 0 ) {

        printf("Error making posts.log\n");
        _terminate(-1);
    }

	retcode = createFile("Users.db", REGULAR, ROOT_ID);	
    
    if ( retcode != 0 ) {

        printf("Error making Users.db\n");
        _terminate(-1);
    }

    retcode = createFile("posts.log", REGULAR, ROOT_ID);

    if ( retcode != 0 ) {

        printf("Error making posts.log\n");
        _terminate(-1);
    }

    // seed the first postID with magic page data.  After this they just increase by 1 each time
    fh = openFile("initialPostID.mem", ROOT_ID);

    if ( fh < 0 ) {

        printf("Error opening initialPostID.mem\n");
        _terminate(-1);
    }
    readFile(fh, (void *)&nextPostID, sizeof(nextPostID), 0, 0, ROOT_ID);
    nextPostID &= 0x0fffffff;

    // we'll never re-seed the postID so just delete the file
    deleteFile(fh, ROOT_ID);

    // this file will allow us to get semi-random userID's from the magic page.  It is kept open and a new ID is 
    // read whenever a new account is created
    retcode = makeMemoryFile("UserIDs.mem", 0x4347C004, 1532, 1, ROOT_ID );

    if ( retcode != 0 ) {

        printf("Error making UserIDs.mem\n");
        _terminate(-1);
    }

    retcode = allocate(1024, 0, &message);

    if (retcode != 0) {

        _terminate(-1);
    }

    endIt = 0;

    while (!endIt) {

    	messagetype = receiveMessage(message);

    	switch (messagetype) {

    			// add a new user
    		case 0xa0:

    			newuser = (newUserMessageType *)message;

    			if (create_user(newuser->name, newuser->password, newuser->fullname) >= 0 ) {

    				responseCode = 0;
    				
    			}
    			else {

    				responseCode = -1;

    			}

    			sendResponse((void *)&responseCode, sizeof(responseCode));

    			break;

    			// authenticate a user
    		case 0xb0:

    			loginuser = (loginMessageType *)message;
    			useraccount = authenticate(loginuser->name, loginuser->password);

    			sendResponse((void *)&useraccount, sizeof(useraccount));

    			break;

    			// retrieve a single post to this user's feed
    		case 0xc0:

                sessionToken = *(unsigned int *)message;

                retcode = newFeedPost(sessionToken, &postText, &postSize);

                if (retcode == 0 ) {

                    sendResponse((void *)postText, postSize);
                    deallocate((void *)postText, postSize);
                }
                else {

                    retcode = -1;
                    sendResponse((void *)&retcode, sizeof(retcode));

                }
    			break;

    			 // record a new post from the user
    		case 0xd0:

                newPost = (newPostMessageType *)message;

                retcode = savePost(nextPostID, newPost->sessionToken, newPost->post);

                if (retcode == 0) {

                    retcode = nextPostID;
                    ++nextPostID;
                }
                else {

                    retcode = -1;
                }

                sendResponse((void *)&retcode, sizeof(retcode));

    			break;

                // comment on a post
            case 0xe0:

                newComment = (addCommentMessageType *)message;

                retcode = saveComment(newComment->postID, newComment->commenterID, newComment->comment);

                sendResponse((void *)&retcode, sizeof(retcode));

                break;

                // retrieve a specific post by its ID--this will include any comments as well
            case 0xf0:

                postID = *(unsigned int *)message;

                if ( postID < 16 ) {

                     retcode = sendStickPost( postID );
                }
                else {

                    retcode = retrievePost( postID, 1 , &postText, &postSize);

                    if (retcode == 0) {

                        sendResponse((void *)postText, postSize);
                        deallocate((void *)postText, postSize);
                    }
                }

                if ( retcode == -1 ) {

                    sendResponse((void *)&retcode, sizeof(retcode));

                }
                // response sent by the retrievePost() function
                break;

            case 100:

                endIt = 1;
                break;

    		default:

                endIt = 1;

    			break;

    	} //switch


    } // while (1)

    printf("BYE!\n");

}  // main  
void testRun1()
{
	pause(PAUSE);

	initFileSystem("Drive2MB", "2MB_VDrive");

	if(!virDrive)
	{
		fprintf(stderr, "Error opening drive. Exiting");
		exit(1);
	}
	fprintf(stdout, "Virtual drive opened\n");

	printBootClusterInfo();

	pause(PAUSE);

	fprintf(stdout, "Opening 'testfile0.txt'\n");
	BC_FILE *testfile0 = openFile("testfile0.txt");
	
	fprintf(stdout, "Creating 'directory0'\n");
	createDirectory("directory0");

	fprintf(stdout, "Opening 'directory0/testfile1.txt'\n");
	BC_FILE *testfile1 = openFile("directory0/testfile1.txt");

	fprintf(stdout, "\n");
	printDirectoryListing("root");
	printDirectoryListing("directory0");

	printBootClusterInfo();

	pause(PAUSE);

	fprintf(stdout, "Opening 'directory1/directory2/directory3/testfile2.txt'\n");
	BC_FILE *testfile2 = openFile("directory1/directory2/directory3/testfile2.txt");

	fprintf(stdout, "\n");
	printDirectoryListing("root");
	printDirectoryListing("directory0");
	printDirectoryListing("directory1");
	printDirectoryListing("directory1/directory2");
	printDirectoryListing("directory1/directory2/directory3");

	pause(PAUSE);

	fprintf(stdout, "Writing 69 characters to 'directory1/directory2/directory3/testfile2.txt'\n");
	char *test69 = "The man in black fled across the desert, and the gunslinger followed.";
	writeFile(test69, 69, testfile2);

	fprintf(stdout, "Writing 645 characters to 'testfile0.txt'\n");
	char *test644 = "The man in black fled across the desert, and the gunslinger followed.\nThe desert was the apotheosis of all deserts, huge, standing to the sky\nfor what looked like eternity in all directions. It was white and blinding\nand waterless and without feature save for the faint, cloudy haze of the\nmountains which sketched themselves on the horizon and the devil-grass which\nbrought sweet dreams, nightmares, death. An occasional tombstone sign pointed\nthe way, for once the drifted track that cut its way through the thick crust\nof alkali had been a highway. Coaches and buckas had followed it. The world\nhad moved on since then. The world had emptied.";
	writeFile(test644, 645, testfile0);

	fprintf(stdout, "Writing 2066 characters to 'directory0/testfile1.txt'\n");
	char *test2066 = "The greatest mystery the universe offers is not life but size. Size\nencompasses life, and the Tower encompasses size. The child, who is\nmost at home with wonder, says: Daddy, what is above the sky? And the\nfather says: The darkness of space. The child: What is beyond space?\nThe father: The galaxy. The child: Beyond the galaxy? The father:\nAnother galaxy. The child: Beyond the other galaxies? The father: No\none knows. You see? Size defeats us. For the fish, the lake in which\nhe lives is the universe. What does the fish think when he is jerked\nup by the mouth through the silver limits of existence and into a new\nuniverse where the air drowns him and the light is blue madness? Where\nhuge bipeds with no gills stuff it into a suffocating box and cover it\nwith wet weeds to die? Or one might take the tip of the pencil and\nmagnify it. One reaches the point where a stunning realization strikes\nhome: The pencil tip is not solid; it is composed of atoms which whirl\nand revolve like a trillion demon planets. What seems solid to us is\nactually only a loose net held together by gravity. Viewed at their\nactual size, the distances between these atoms might become league,\ngulfs, aeons. The atoms themselves are composed of nuclei and revolving\nprotons and electrons. One may step down further to subatomic\nparticles. And then to what? Tachyons? Nothing? Of course not.\nEverything in the universe denies nothing; to suggest an ending is the\none absurdity. If you fell outward to the limit of the universe, would\nyou find a board fence and signs reading DEAD END? No. You might find\nsomething hard and rounded, as the chick must see the egg from the\ninside. And if you should peck through the shell (or find a door), what\ngreat and torrential light might shine through your opening at the end\nof space? Might you look through and discover our entire universe is\nbut part of one atom on a blade of grass? Might you be forced to think\nthat by burning a twig you incinerate an eternity of eternities? That\nexistence rises not to one infinite but to an infinity of them?";
	writeFile(test2066, 2066, testfile1);

	fprintf(stdout, "\n");
	printDirectoryListing("root");
	printDirectoryListing("directory0");
	printDirectoryListing("directory1");
	printDirectoryListing("directory1/directory2");
	printDirectoryListing("directory1/directory2/directory3");

	pause(PAUSE);

	fprintf(stdout, "Rewinding and reading 69 characters from 'directory1/directory2/directory3/testfile2.txt':\n\n");
	rewindBC_File(testfile2);
	char strRead2[70];
	readFile(strRead2, 69, testfile2);
	strRead2[69] = '\0';
	printf("%s\n\n", strRead2);

	fprintf(stdout, "Rewinding and reading 645 characters from 'testfile0.txt':\n\n");
	rewindBC_File(testfile0);
	char strRead0[646];
	readFile(strRead0, 645, testfile0);
	strRead0[645] = '\0';
	printf("%s\n\n", strRead0);

	fprintf(stdout, "Rewinding and reading 2066 characters from 'directory0/testfile1.txt':\n\n");
	rewindBC_File(testfile1);
	char strRead1[2067];
	readFile(strRead1, 2066, testfile1);
	strRead1[2066] = '\0';
	printf("%s\n\n", strRead1);

	printBootClusterInfo();

	fprintf(stdout, "\n");
	printDirectoryListing("root");
	printDirectoryListing("directory0");
	printDirectoryListing("directory1");
	printDirectoryListing("directory1/directory2");
	printDirectoryListing("directory1/directory2/directory3");

	pause(PAUSE);

	fprintf(stdout, "Attempting to print non-existent directories\n");

	fprintf(stdout, "\n");
	printDirectoryListing("directory1/directory4/directory3");
	printDirectoryListing("directory1/directory2/directory3/directory4");

	pause(PAUSE);

	fprintf(stdout, "Deleting 'testfile0.txt'\n");
	deleteFile(testfile0);

	printBootClusterInfo();

	fprintf(stdout, "\n");
	printDirectoryListing("root");
	printDirectoryListing("directory0");
	printDirectoryListing("directory1");
	printDirectoryListing("directory1/directory2");
	printDirectoryListing("directory1/directory2/directory3");

	pause(PAUSE);

	fprintf(stdout, "Closing 'testfile1.txt'\n");
	closeFile(testfile1);
	fprintf(stdout, "Closing 'testfile2.txt'\n");
	closeFile(testfile2);

	closeFileSystem();
}
Example #7
0
bool MainApp::OnInit() 
{
	synced = false;
	num_files = 0;
	screen_height = wxGetDisplaySize().GetHeight();
	screen_width = wxGetDisplaySize().GetWidth();
	endUpdating = false;
	SyncType = SYNC_NEW;

	/* give global main app handle a pointer to the app */
	MAIN_APP = this;

	orangefs_enable_debug( OrangeFS_DEBUG_FILE | OrangeFS_DEBUG_MVS, debugLogFilename, OrangeFS_CLIENT_DEBUG | OrangeFS_GETATTR_DEBUG | OrangeFS_SETATTR_DEBUG);

	allocateMembers();

	initFileSystem();

	/* get all the file system names */
	for (int i=0; i < mntents[0]->num_orangefs_config_servers; i++)
	{
		fsNames.Add(mntents[i]->orangefs_fs_name);
	}

	fsNames.Add("Other file system");

	MAIN_FRAME = new MainFrame("OrangeFS File Browser", 
							   wxPoint((screen_width/2) - (DEFAULT_WIN_WIDTH/2), /* middle of screen */
							   (screen_height/2) - (DEFAULT_WIN_HEIGHT/2)), 
 	 	 	 				   wxSize(DEFAULT_WIN_WIDTH, DEFAULT_WIN_HEIGHT));

	/* load up the local configurations */
	localConfig = new LocalConfig;

	/* parses the local metadata file and loads all runtime cache maps */
	metadataHandler = MetadataHandler::getInstance();	

	orangefs_debug_print("---- Parsed metadata file and loaded cache ----\n");

	/* if there is an existing configuration */
	if( localConfig->load() ) 
	{
		orangefs_debug_print("Using existing sync configuration from file : %s\n", localConfig->getConfigPath() );
	}
	else 
	{
		orangefs_debug_print("No existing sync config file found.\n");
	}

		/* now, just check for updates */
#ifdef WIN32
	HANDLE threadHandle;

		/* spawn a new thread to handle the syncing; if the user closes the app while it's still syncing, the app window will become invisible, but the sync thread will still be running */
		threadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) updateAll, 0, 0, NULL);

		/* give the main app the handle so it can determine what it's finished */
		MAIN_APP->setThreadHandle(threadHandle);
#endif

	/* now that we've loaded (or not loaded) locally synced files, display the file browser */
	MAIN_FRAME->Show(true);
	SetTopWindow(MAIN_FRAME);

	return true;
}