void determine_paths (char *argv0) { char buffer[8192], buffer2[MAX_PATH], *p; if (!fl_opt.has_driveletters) { // 1. User directory p = getenv ("HOME"); if (p == NULL) fly_error ("HOME variable is not set, aborting\n\n"); str_scopy (buffer, p); str_cats (buffer, ".nftp2"); if (access (buffer, X_OK) < 0) if (mkdir1 (buffer, 0700) < 0) fly_error ("\nCannot create directory `%s'\n\n", buffer); paths.user_libpath = strdup (buffer); chmod (buffer, 0700); // 2. System directory strcpy (buffer, USR_PATH"/nftp2"); if (access (buffer, X_OK) == 0) { paths.system_libpath = strdup (buffer); } else { strcpy (buffer, USR_LOCAL_PATH"/nftp2"); if (access (buffer, X_OK) == 0) paths.system_libpath = strdup (buffer); else paths.system_libpath = paths.user_libpath; } } else { // 1. System directory strcpy (buffer, argv0); str_translate (buffer, '\\', '/'); p = strrchr (buffer, '/'); if (p == NULL) p = buffer; *p = '\0'; // bare filename if (p == buffer) { buffer[0] = query_drive () + 'a'; buffer[1] = ':'; getcwd (buffer2, sizeof(buffer2)); str_translate (buffer2, '\\', '/'); if (buffer2[1] == ':') strcpy (buffer+2, buffer2+2); else strcpy (buffer+2, buffer2); } paths.system_libpath = strdup (buffer); // 2. User directory paths.user_libpath = paths.system_libpath; } }
void initialize (int *argc, char **argv[], char ***envp) { char buf[512], *p; char inifile[MAX_PATH], ifile[MAX_PATH]; time_t t1; struct tm tm1; #ifdef __MINGW32__ WSADATA wsa; #endif //putenv ("TZ=GMT0"); //tzset (); // first we need to initialize FLY variables fly_initialize (); fl_opt.appname = "nftp"; if (fl_opt.has_console) fprintf (stderr, "\nNFTP - Version%sof %s, %s" "\nCopyright (C) Sergey Ayukov 1994--2000.\n\n", NFTP_VERSION, __DATE__, __TIME__); fly_process_args (argc, argv, envp); // checking command-line arguments check_args (*argc, *argv); // find where our config files are determine_paths ((*argv)[0]); // delete old temporary files clear_tmp (); // loading configuration files init_config (); // initilialize debug subsystem if specified if (options.debug) { sprintf (buf, /*sizeof(buf),*/ "%s/debug", paths.user_libpath); mkdir1 (buf, 0700); sprintf (buf, /*sizeof(buf),*/ "%s/debug/nftp.dbg.%u", paths.user_libpath, (int)getpid ()); dbfile = fopen (buf, "w"); tools_debug = dbfile; } if (options.log_cc) { sprintf (buf, /*sizeof(buf),*/ "%s/CC", paths.user_libpath); mkdir1 (buf, 0700); t1 = time (NULL); tm1 = *localtime (&t1); sprintf (buf, "CC/%04d-%02d-%02d.%02d:%02d:%02d.log", tm1.tm_year+1900, tm1.tm_mon, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm1.tm_sec); p = str_sjoin (paths.user_libpath, buf); cc_log = fopen (p, "w"); if (cc_log == NULL) options.log_cc = FALSE; free (p); } // load language-specific things nls_init (paths.system_libpath, paths.user_libpath); load_menu (); // check for correct NFTP.INI version strcpy (buf, NFTP_VERSION); str_strip2 (buf, " "); //if (str_numchars (buf, '.') > 1) *(strrchr (buf, '.')) = '\0'; if (strcmp (options.version, buf) != 0) { // looking for nftp.i file in user dir, then in system dir strcpy (ifile, paths.user_libpath); str_cats (ifile, "nftp.i"); if (access (ifile, R_OK) != 0) { strcpy (ifile, paths.system_libpath); str_cats (ifile, "nftp.i"); if (access (ifile, R_OK) != 0) fly_error (MSG(M_INI_CANT_FIND_NFTP_I), paths.user_libpath, paths.system_libpath); } strcpy (inifile, paths.user_libpath); str_cats (inifile, "nftp.ini"); update_inifile (inifile, ifile); GetProfileOptions (inifile); } config_fly (); #ifdef __MINGW32__ WSAStartup (MAKEWORD(1,1), &wsa); #endif }
int ext2(void) { printf("Hello World, this is the Ext2 FS\n"); // Hardcode test fs into memory so that we can test read // Set up the superblock struct ext2_super_block *sb; sb = (struct ext2_super_block*) (VIRT_MEM_LOCATION + EXT2_SUPERBLOCK_LOCATION); sb->s_inodes_count = 50; sb->s_blocks_count = 8192; sb->s_r_blocks_count = 6; sb->s_free_blocks_count = 8186; sb->s_free_inodes_count = 49; sb->s_first_data_block = 1; sb->s_log_block_size = 0; sb->s_log_frag_size = 0; sb->s_blocks_per_group = 8192; sb->s_frags_per_group = 8192; sb->s_inodes_per_group = 50; sb->s_magic = EXT2_MAGIC; sb->s_state = EXT2_VALID_FS; sb->s_errors = EXT2_ERRORS_CONTINUE; sb->s_creator_os = EXT2_OS_XINU; sb->s_first_ino = 2; sb->s_inode_size = sizeof( struct ext2_inode ); sb->s_block_group_nr = 0; char name[16] = "FAKE RAM FS :D"; memcpy(sb->s_volume_name,name,16); // Set up the group descriptors table struct ext2_group_desc *gpd; // DUMB POINTER ARITHMATIC gpd = (struct ext2_group_desc *) (sb + 1); gpd->bg_block_bitmap = 2; gpd->bg_inode_bitmap = 3; gpd->bg_inode_table = 4; gpd->bg_free_blocks_count = 44; gpd->bg_free_inodes_count = 19; gpd->bg_used_dirs_count = 1; // Set up the block bitmap uint8 *blBitmap; blBitmap = (uint8 *) (sb + 2); blBitmap[0] = 0x3F; // super block int i; for (i = 6; i < sb->s_blocks_count; i++) blBitmap[i] = 0; // Set up the inode bitmap uint8 *iBitmap; iBitmap = (uint8 *) (sb + 3); iBitmap[0] = 0x1; // . for (i = 1; i < sb->s_inodes_count; i++) iBitmap[i] = 0; // Set up the inode table struct ext2_inode *iTbl; iTbl = (struct ext2_inode *) (sb + 4); // Set up . inode iTbl->i_mode = EXT2_S_IFDIR; iTbl->i_size = sizeof(struct ext2_dir_entry_2); iTbl->i_links_count = 0; iTbl->i_blocks = 1; iTbl->i_flags = EXT2_NODUMP_FL; iTbl->i_block[0] = 5; // Set up . entry for the home directory struct ext2_dir_entry_2 *blk5; blk5 = (struct ext2_dir_entry_2 *) (sb + 5); blk5->inode = 1; blk5->next_dirent = 0; blk5->name_len = 1; blk5->filetype = 2; char homeName[255] = "."; memcpy(blk5->name, homeName, 255); _fs_ext2_init(); touch1( xinu_fs, "./", "test" ); char bufferL[9] = "Go long!"; uint32 bytes_written; ext2_write_status stat = ext2_write_file_by_path( xinu_fs, "./test", bufferL, &bytes_written, 0, 8 ); touch1( xinu_fs, "./", "yo"); stat = ext2_write_file_by_path( xinu_fs, "./yo", bufferL, &bytes_written, 0, 8 ); touch1( xinu_fs, "./", "whoah" ); stat = ext2_write_file_by_path( xinu_fs, "./whoah", bufferL, &bytes_written, 0, 8 ); touch1( xinu_fs, "./", "iasjdf" ); stat = ext2_write_file_by_path( xinu_fs, "./iasjdf", bufferL, &bytes_written, 0, 8 ); touch1( xinu_fs, "./", "f" ); stat = ext2_write_file_by_path( xinu_fs, "./f", bufferL, &bytes_written, 0, 8 ); ls1( xinu_fs, "./" ); printf("removing yo\n"); rm1( xinu_fs, "./", "yo" ); ls1( xinu_fs, "./" ); printf("touching asdf\n"); touch1( xinu_fs, "./", "asdf" ); stat = ext2_write_file_by_path( xinu_fs, "./asdf", bufferL, &bytes_written, 0, 8 ); ls1( xinu_fs, "./" ); printf("mking dir\n"); mkdir1( xinu_fs, "./", "dir" ); ls1( xinu_fs, "./" ); printf("touching yo\n"); touch1( xinu_fs, "./dir/", "yo" ); ls1( xinu_fs, "./dir/"); copy1( xinu_fs, "./", "whoah", "./", "hello" ); ls1( xinu_fs, "./" ); cat1( xinu_fs, "./", "hello" ); copy1( xinu_fs, "./", "hello", "./dir/", "hello" ); printf("HERE\n"); ls1( xinu_fs, "./dir/" ); cat1( xinu_fs, "./dir/", "hello" ); printf("removeing\n"); mv1( xinu_fs, "./dir/", "yo", "./", "a" ); ls1( xinu_fs, "./" ); cat1( xinu_fs, "./", "a" ); #if 0 // Test the read/write functions printf("Testing hardcoded data\n"); print_superblock( xinu_fs->sb ); struct ext2_inode *i1 = ext2_get_inode(xinu_fs, 1); print_inode( i1, 1, xinu_fs ); struct ext2_dir_entry_2 *home = ext2_get_first_dirent(xinu_fs, i1 ); print_dirent( home ); uint32 inode_num = ext2_inode_alloc( xinu_fs ); struct ext2_inode *i2 = ext2_get_inode( xinu_fs, inode_num+1 ); i2->i_mode = EXT2_S_IFREG; i2->i_size = 0; printf("Allocated new inode\n"); print_inode( i2, inode_num+1, xinu_fs ); struct ext2_dir_entry_2 *dirent = ext2_dirent_alloc( xinu_fs, i1 ); dirent->inode = 2; dirent->next_dirent = 0; dirent->name_len = 4; dirent->filetype = EXT2_FT_REG_FILE; char testName[255] = "test"; memcpy(dirent->name, testName, 255); printf("Allocated new dir_entry_2 test\n"); print_dirent( dirent ); char path[8] = "./test"; char buffer[14] = "Writing! Yay!"; char bufferL[9] = "Go long!"; uint32 bytes_written; ext2_write_status stat = ext2_write_file_by_path( xinu_fs, path, buffer, &bytes_written, 0, 13 ); printf("bytes_written = %d stat = %d\n", bytes_written, stat); char buffer2[12*1024]; // stat = ext2_write_file_by_path( xinu_fs, path, buffer2, // &bytes_written, 13, (12*1024)-1 ); printf("bytes_written = %d stat = %d\n", bytes_written, stat); // stat = ext2_write_file_by_path( xinu_fs, path, bufferL, // &bytes_written, (12*1024)+12, 8 ); printf("bytes_written = %d stat = %d\n", bytes_written, stat); int read = 0; char readBuf[30]; read = ext2_read_dirent( xinu_fs, dirent, readBuf, 0, 29); printf("Read %d bytes readBuf = %s\n", read, readBuf); // read = ext2_read_dirent( xinu_fs, dirent, readBuf, (12*1024)+12, 10); // printf("Read %d bytes readBuf = %s\n", read, readBuf); #endif return 0; }
static B mkdir(C*v){R!mkdir1(v);}