int FileName::makePath(mode_t mode) const { char *pp; char *sp; int status; char *copypath = strdup(c_str()); if (copypath == NULL) REPORT_ERROR(ERR_MEM_BADREQUEST,"FileName::makePath: Canot alloc memory"); status = 0; pp = copypath; while (status == 0 && (sp = strchr(pp, '/')) != 0) { if (sp != pp) { /* Neither root nor double slash in path */ *sp = '\0'; status = do_mkdir(copypath, mode); *sp = '/'; } pp = sp + 1; } if (status == 0) status = do_mkdir(c_str(), mode); free(copypath); return status; }
void mkdirs() { do_mkdir(MOMO_CACHE); do_mkdir(MOMO_RECORD); do_mkdir(MOMO_CACHE_AUDIO); do_mkdir(MOMO_CACHE_FILE); do_mkdir(MOMO_CACHE_PHOTO); };
/** ** mkpath - ensure all directories in path exist ** Algorithm takes the pessimistic view and works top-down to ensure ** each directory in path exists, rather than optimistically creating ** the last element and working backwards. */ int mkpath(const char *path, mode_t mode) { char *pp; char *sp; int status; char *copypath = strdup(path); status = 0; pp = copypath; while (status == 0 && (sp = strchr(pp, '/')) != 0) { if (sp != pp) { /* Neither root nor double slash in path */ *sp = '\0'; status = do_mkdir(copypath, mode); *sp = '/'; } pp = sp + 1; } if (status == 0) status = do_mkdir(path, mode); free(copypath); return (status); }
void sysfs_init(void) { do_mkdir("/dev_vfs/infiniband", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/class", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/class/infiniband_verbs", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/class/infiniband", S_IRWXU | S_IRWXG | S_IRWXO); make_device("/sys/class/infiniband_verbs/abi_version", S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&ib_api_ver); do_mkdir("/sys/module", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/module/mlx4_core", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/module/mlx4_core/parameters", S_IRWXU | S_IRWXG | S_IRWXO); make_device("/sys/module/mlx4_core/parameters/log_num_mgm_entry_size", S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&mlx4_mgm); #if 0 /* Do this thru init scripts */ do_mkdir("/proc", S_IRWXU | S_IRWXG | S_IRWXO); make_device("/proc/cpuinfo", S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&cpuinfo); #endif }
int mkdir_test() { int ret = 0; printf("mkdir_test: Start\n"); /* * Create new directory */ printf("\tbegin: Create new directory(%s)\n", NEW_DIR_PATH_1); if((ret = do_mkdir(NEW_DIR_PATH_1, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) != 0){ goto out; } printf("\tend: Success\n"); /* * re-Create new directory */ printf("\tbegin: try to re-create existing directory(%s)\n", NEW_DIR_PATH_1); ret = do_mkdir(NEW_DIR_PATH_1, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); switch(ret){ case 0: printf("\texisting directory can be re-created!!\n"); ret = 1; goto out; case EEXIST: break; default: printf("\terror is not EEXIT, but %s\n", strerror(ret)); } ret = 0; printf("\tend: Success\n"); /* * Create another new directory */ printf("\tbegin: Create new directory(%s)\n", NEW_DIR_PATH_2); if((ret = do_mkdir(NEW_DIR_PATH_2, S_IRUSR | S_IXUSR | S_IWUSR | S_IRGRP | S_IXUSR | S_IROTH |S_IXUSR )) != 0){ goto out; } printf("\tend: Success\n"); out: if (ret) { printf("\tend: Failed\n"); } printf("mkdir_test: Finish\n"); return ret; }
int do_root(char *name, char *size) { if (debug) printf("%s\n", __func__); diskPartition = malloc(FILESYSTEM_SIZE); // Allocates memory for diskPartition //diskPartition = calloc(1, FILESYSTEM_SIZE); // Allocates memory for diskPartition pcb = (PartitionControlBlock *) diskPartition; // Casts diskPartiton to type PartitionControlBlock pcb->freeBlockCount = NUM_BLOCKS; // Initializes the freeBlockCount to NUM_BLOCKS if (debug) printf("PCB MEMORY: %p\n", pcb); for(int i=0; i < NUM_BLOCKS; i++) // Initializes the Bitmap to all 0s setBitmap(i,0); setBitmap(0,1); // Sets the first block of the bitmap to 1 directoryTable = diskPartition + sizeof(PartitionControlBlock); // Finds the starting location for the Directory Table dtb = (DirectoryTable *) directoryTable; // Creates the directory table if (debug) printf("DTB MEMORY: %p\n", dtb); pwd = &((*dtb).directoryEntries[0]); int returnValue; returnValue = do_mkdir("root", NULL); // Creates the root directory if (debug) printf("Return Value: %d\n", returnValue); if (debug) printf("DoRoot: SubDirIndex(PWD): %d\n",(*pwd).subdirectoryIndex); return 0; }
/* * A function executed by a thread that creates a directory called /dir00n * (where n is arg1) and writes 50 files into it called /dir00n/test000 through * /dir00n/test049. If any fail, exit with their return code. Threads running * this are created by both kshell_thread_test and kshell_directory_test. */ static void *make_dir_thread(int arg1, void *arg2) { char dir[TESTBUFLEN]; /* A buffer for the directory name */ char file[TESTBUFLEN]; /* A buffer for the full file pathname */ int rv = 0; /* return values */ int i = 0; /* Scratch */ /* Make the directory name and the directory. Snprintf is safe - it * always zero-terminates and never overflows the buffer. */ snprintf(dir, TESTBUFLEN, "/dir%03d", arg1); do_mkdir(dir); for (i = 0; i < 50 ; i++ ) { int f= 0; /* File descriptor */ snprintf(file, TESTBUFLEN, "%s/test%03d", dir, i); /* Open a file (creating it if it's not there) */ if ( (f = do_open(file, O_WRONLY | O_CREAT)) < 0 ) { rv = f; goto fail; } /* Write the same content to every file. */ if ( (rv = do_write(f, FILE_CONTENT, CONTENT_LEN)) != CONTENT_LEN) { do_close(f); goto fail; } do_close(f); } rv = 0; fail: do_exit(rv); return NULL; }
void* func_msg(void* arg) { struct thread_info* args = arg; // struct sockaddr_in client; int sock = args->sock; int read_n, errcnt = 0; ftp_rqt request; // printf("in thread\n"); // fprintf(stderr, "sock: %d\n", sock); while (true) { memset(&request, 0, RQT_LEN); read_n = recv(sock, (char*)&request, RQT_LEN, 0); if (read_n < 0) { errcnt ++; if (errcnt > 10) break ; continue ; } if (read_n == 0) { fprintf(stderr, "quit"); break ; } // printf("msg: %d; read_n: %d\n", request.type, read_n); if (request.type == CMD_CLOSE) break; else if (request.type == CMD_CD) do_chdir(&request, sock); else if (request.type == CMD_MKDIR) do_mkdir(&request, sock); else if (request.type == CMD_RMDIR) do_rmdir(&request, sock); else if (request.type == CMD_LS) do_lsdir(&request, sock); else if (request.type == CMD_GET) { do_get(&request, sock); break; } else if (request.type == CMD_PUT) { printf("put\n"); do_put(&request, sock); break; } // send(sock, CONFIRM, strlen(CONFIRM)+1, 0); } thread_end(args); }
bool assure_dir_exist(std::string const &path) { DIR *dir = opendir(path.c_str()); if(dir != nullptr) { closedir(dir); return true; } return do_mkdir(path, 0777); }
/* This creates a new directory with default permissions. Since there * might be some directory-default permissions affecting this, we can't * force the permissions directly using the original umask and mkdir(). */ int mkdir_defmode(char *fname) { int ret; umask(orig_umask); ret = do_mkdir(fname, ACCESSPERMS); umask(0); return ret; }
static char *get_local_name(struct file_list *flist,char *name) { STRUCT_STAT st; int e; if (verbose > 2) rprintf(FINFO,"get_local_name count=%d %s\n", flist->count, NS(name)); if (!name) return NULL; if (do_stat(name,&st) == 0) { if (S_ISDIR(st.st_mode)) { if (!push_dir(name)) { rsyserr(FERROR, errno, "push_dir#1 %s failed", full_fname(name)); exit_cleanup(RERR_FILESELECT); } return NULL; } if (flist->count > 1) { rprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n"); exit_cleanup(RERR_FILESELECT); } return name; } if (flist->count <= 1 && ((e = strlen(name)) <= 1 || name[e-1] != '/')) return name; if (do_mkdir(name,0777 & ~orig_umask) != 0) { rsyserr(FERROR, errno, "mkdir %s failed", full_fname(name)); exit_cleanup(RERR_FILEIO); } if (verbose > 0) rprintf(FINFO, "created directory %s\n", safe_fname(name)); if (dry_run) { dry_run++; return NULL; } if (!push_dir(name)) { rsyserr(FERROR, errno, "push_dir#2 %s failed", full_fname(name)); exit_cleanup(RERR_FILESELECT); } return NULL; }
/** * Process the next incoming request * * @return status response */ status_t process_req() { msg_t *msg = malloc(sizeof(msg_t)); resp_t *resp = NULL; if (!EREADDATA(*msg)) { debug("Disconnected!\n"); return DISCON; } msg->buf[sizeof(msg->buf)-1] = '\0'; switch (msg->type) { case MKDIR: resp = do_mkdir(msg); break; case LIST: resp = do_list(msg); break; case PUT: resp = do_put(msg); break; case GET: resp = do_get(msg); break; case RM: resp = do_rm(msg); break; case RMDIR: resp = do_rmdir(msg); break; case QUIT: return EXIT; default: return ERR; } if (!resp) return ERR; ESENDDATA(*resp); if (last) free(last); last = (char *)resp; return OK; }
static void do_fork(void) { int fork_pid, wait_pid; int status, i; wait_for_parent(); /* * Fork a kid. Keep track of the kid's pid, have the kid do_mkdir, * and wait for it. Compare the fork_pid with the wait_pid to be * sure they are the same. */ for (i = 0; i < 50; i++) { fork_pid = FORK_OR_VFORK(); if (fork_pid < 0) { tst_resm(TFAIL, "Fork failed"); tst_exit(); } if (fork_pid == 0) { #ifdef UCLINUX if (self_exec(argv0, "n", 5) < 0) { tst_resm(TFAIL, "do_fork self_exec failed"); tst_exit(); } #else do_mkdir(); #endif } errno = 0; while (((wait_pid = waitpid(fork_pid, &status, 0)) != -1) || (errno == EINTR)) { if (wait_pid == -1) continue; if (fork_pid != wait_pid) { tst_resm(TFAIL, "Didnt get a pid returned " "from waitpid that matches the one " "returned by fork"); tst_resm(TFAIL, "fork pid = %d, wait pid = " "%d", fork_pid, wait_pid); fail = 1; } } } exit(4); }
/**************************************************************************** Create a directory given an absolute path, perms based upon another directory path ****************************************************************************/ static int make_bak_dir(char *fname,char *bak_path) { STRUCT_STAT st; STRUCT_STAT *st2; char fullpath[MAXPATHLEN]; extern int orig_umask; char *p; char *q; while(strncmp(bak_path,"./",2)==0) bak_path += 2; if(bak_path[strlen(bak_path)-1]!='/') { snprintf(fullpath,sizeof(fullpath),"%s/",bak_path); } else { snprintf(fullpath,sizeof(fullpath),"%s",bak_path); } p=fullpath; q=&fullpath[strlen(fullpath)]; /* End of bak_path string */ strcat(fullpath,fname); /* Make the directories */ while ((p=strchr(p,'/'))) { *p = 0; if(do_lstat(fullpath,&st)!=0) { do_mkdir(fullpath,0777 & ~orig_umask); if(p>q) { if(do_lstat(q,&st)!=0) { rprintf(FERROR,"make_bak_dir stat %s : %s\n",fullpath,strerror(errno)); } else { st2=&st; set_modtime(fullpath,st2->st_mtime); if(do_lchown(fullpath,st2->st_uid,st2->st_gid)!=0) { rprintf(FERROR,"make_bak_dir chown %s : %s\n",fullpath,strerror(errno)); }; if(do_chmod(fullpath,st2->st_mode)!=0) { rprintf(FERROR,"make_bak_dir failed to set permissions on %s : %s\n",fullpath,strerror(errno)); }; }; } }; *p = '/'; p++; } return 0; }
int securesoho_factory_default(void) { int tvmode=0; /* default is NTSC */ /* remove the /conf directory */ do_cmd("/bin/rm", SOURCE_DIR, "-fr", NULL); do_mkdir(SOURCE_DIR); /* to copy correct config as default */ tvmode = bs_config_int_get(CONF_DEVICE_MP_CONFIG, "CONF_DEVICE_MP_TVMODE"); securesoho_copy(SECURESOHO_FACTORY_DEFAULT_SETTINGS, SECURESOHO_CONFIG_SETTINGS); if (tvmode){ /* PAL */ securesoho_string_set(CONFIG_NTSC_OR_PAL, "PAL"); } securesoho_copy("/conf_src/wizard.conf.default", "/conf/wizard.conf"); return 0; }
/* * A function executed by a thread that creates a directory called /dir00n * (where n is arg1) and unlinks 50 files from it called /dir00n/test000 through * /dir00n/test049. Ignore the return codes (files may not be there yet). * Threads running this are created by kshell_directory_test. Structurally * similar to make_dir_thread. */ static void *rm_dir_thread(int arg1, void *arg2) { char dir[TESTBUFLEN]; /* Directory pathname */ char file[TESTBUFLEN]; /* Each file's pathname */ int rv = 0; /* Return value */ int i = 0; /* Scratch */ /* Make the directory */ snprintf(dir, TESTBUFLEN, "/dir%03d", arg1); do_mkdir(dir); /* Unlink the files */ for (i = 0; i < 50 ; i++ ) { snprintf(file, TESTBUFLEN, "%s/test%03d", dir, i); do_unlink(file); } do_exit(rv); return NULL; }
int mkpath(const char* path) { char* pp, *sp; int status=0; char copypath[64]; size_t slen = strlen(path); memcpy(copypath,path,slen); copypath[slen]='\0'; pp = copypath; while (status == 0 && (sp = strchr(pp, '/')) != 0) { if (sp != pp) { *sp = '\0'; status = do_mkdir(copypath); *sp = '/'; } pp = sp + 1; } return status; }
int main(int argv, char* args[]){ disk = open("/dev/fd0",O_RDWR); if (argv > 1){ if (strcmp(format, args[1]) == 0) do_format(); else if (strcmp(mkdir, args[1]) == 0){ if (argv > 2) do_mkdir(args[2]); else printf("Usage: mkdir dir\n"); } else if (strcmp(chdir, args[1]) == 0){ if (argv > 2) do_chdir(args[2]); else printf("Usage: chdir dir\n"); } else if (strcmp(copy, args[1]) == 0) { do_copy(args[2], args[3], args[4]); } else if (strcmp(dir, args[1]) == 0) do_dir(args[2]); else if (strcmp("info", args[1]) == 0){ info(args[2]); } else if (strcmp("freeblock", args[1]) == 0) free_block(); else if (strcmp("checkblock", args[1]) == 0) check_block(args[2]); else printf("Unknown dtool command.\n"); } return 0; }
/* recursively make a directory path */ static int make_dir(char *name, int mask) { char newdir [MAXPATHLEN]; char *p, *d; /* copy pathname over, look for last '/' */ for (p = d = newdir; *name; *d++ = *name++) if (*name == '/') p = d; if (p == newdir) return 0; *p = 0; /* make the new directory, if that fails then make its parent */ while (do_mkdir (newdir, mask) != 0) if ((errno != ENOENT) || !make_dir (newdir, mask)) return 0; return 1; } /* make_dir */
void devfs_init(void) { int mode; /* Make sure there is a dev directory */ struct dentry *dentry = lookup_dentry("/dev/", 0); if (!dentry) { assert(!do_mkdir("/dev/", S_IRWXU | S_IRWXG | S_IRWXO)); } else { kref_put(&dentry->d_kref); } /* Notice we don't kref_put(). We're storing the refs globally */ dev_stdin = make_device("/dev/stdin", S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, &dev_f_op_stdin); dev_stdout = make_device("/dev/stdout", S_IWUSR | S_IWGRP | S_IWOTH, __S_IFCHR, &dev_f_op_stdout); /* Note stderr uses the same f_op as stdout */ dev_stderr = make_device("/dev/stderr", S_IWUSR | S_IWGRP | S_IWOTH, __S_IFCHR, &dev_f_op_stdout); dev_null = make_device("/dev/null", S_IWUSR | S_IWGRP | S_IWOTH, __S_IFCHR, &dev_f_op_null); }
/* Create any necessary directories in fname. Any missing directories are * created with default permissions. */ int create_directory_path(char *fname) { char *p; int ret = 0; while (*fname == '/') fname++; while (strncmp(fname, "./", 2) == 0) fname += 2; umask(orig_umask); p = fname; while ((p = strchr(p,'/')) != NULL) { *p = '\0'; if (do_mkdir(fname, ACCESSPERMS) < 0 && errno != EEXIST) ret = -1; *p++ = '/'; } umask(0); return ret; }
static int sys_mkdir(mkdir_args_t *arg) { mkdir_args_t kern_args; char *path; int err; if ((err = copy_from_user(&kern_args, arg, sizeof(mkdir_args_t))) < 0) { curthr->kt_errno = -err; return -1; } path = user_strdup(&kern_args.path); if (!path) { curthr->kt_errno = EINVAL; return -1; } err = do_mkdir(path); kfree(path); if (err < 0) { curthr->kt_errno = -err; return -1; } else return err; }
int main (int argc, char **argv) { int exit = 0; char *buffer = g_new (char, 1024) ; GIOChannel *ioc; guint watch_id = 0; GOptionContext *ctx = NULL; GError *error = NULL; /* default to interactive on a terminal */ interactive = isatty (0); ctx = g_option_context_new("test-vfs"); g_option_context_add_main_entries(ctx, options, NULL); if (!g_option_context_parse(ctx, &argc, &argv, &error)) { g_printerr("main: %s\n", error->message); g_error_free(error); g_option_context_free(ctx); return 1; } g_option_context_free(ctx); files = g_hash_table_new (g_str_hash, g_str_equal); if (noninteractive) interactive = FALSE; if (interactive) vfserr = stderr; else vfserr = stdout; if (!mate_vfs_init ()) { fprintf (vfserr, "Cannot initialize mate-vfs.\n"); return 1; } mate_vfs_module_callback_push (MATE_VFS_MODULE_CALLBACK_AUTHENTICATION, authentication_callback, NULL, NULL); if (argc == 1) cur_dir = g_get_current_dir (); else cur_dir = g_strdup(argv[1]); if (cur_dir && !G_IS_DIR_SEPARATOR (cur_dir [strlen (cur_dir) - 1])) cur_dir = g_strconcat (cur_dir, G_DIR_SEPARATOR_S, NULL); if (interactive == TRUE) { main_loop = g_main_loop_new (NULL, TRUE); ioc = g_io_channel_unix_new (0 /* stdin */); g_io_channel_set_encoding (ioc, NULL, NULL); g_io_channel_set_buffered (ioc, FALSE); watch_id = g_io_add_watch (ioc, G_IO_IN | G_IO_HUP | G_IO_ERR, callback, buffer); g_io_channel_unref (ioc); } while (!exit) { char *ptr; if (interactive) { fprintf (stdout,"\n%s > ", cur_dir); fflush (stdout); strcpy (buffer, ""); g_main_loop_run (main_loop); } else { /* In non-interactive mode we just do this evil * thingie */ buffer[0] = '\0'; fgets (buffer, 1023, stdin); if (!buffer [0]) { exit = 1; continue; } } if (!buffer || buffer [0] == '#') continue; arg_data = g_strsplit (g_strchomp (buffer), delim, -1); arg_cur = 0; if ((!arg_data || !arg_data[0]) && interactive) continue; if (!interactive) printf ("Command : '%s'\n", arg_data [0]); ptr = arg_data[arg_cur++]; if (!ptr) continue; if (g_ascii_strcasecmp (ptr, "ls") == 0) do_ls (); else if (g_ascii_strcasecmp (ptr, "cd") == 0) do_cd (); else if (g_ascii_strcasecmp (ptr, "dump") == 0) do_dump (); else if (g_ascii_strcasecmp (ptr, "type") == 0 || g_ascii_strcasecmp (ptr, "cat") == 0) do_cat (); else if (g_ascii_strcasecmp (ptr, "cp") == 0) do_cp (); else if (g_ascii_strcasecmp (ptr, "rm") == 0) do_rm (); else if (g_ascii_strcasecmp (ptr, "mkdir") == 0) do_mkdir (); else if (g_ascii_strcasecmp (ptr, "rmdir") == 0) do_rmdir (); else if (g_ascii_strcasecmp (ptr, "mv") == 0) do_mv (); else if (g_ascii_strcasecmp (ptr, "info") == 0 || g_ascii_strcasecmp (ptr, "stat") == 0) do_info (); else if (g_ascii_strcasecmp (ptr, "findtrash") == 0) do_findtrash (); else if (g_ascii_strcasecmp (ptr, "ssl") == 0) do_ssl (); else if (g_ascii_strcasecmp (ptr, "sync") == 0) fprintf (vfserr, "a shell is like a boat, it lists or syncs (RMS)\n"); else if (g_ascii_strcasecmp (ptr,"help") == 0 || g_ascii_strcasecmp (ptr,"?") == 0 || g_ascii_strcasecmp (ptr,"info") == 0 || g_ascii_strcasecmp (ptr,"man") == 0) list_commands (); else if (g_ascii_strcasecmp (ptr,"exit") == 0 || g_ascii_strcasecmp (ptr,"quit") == 0 || g_ascii_strcasecmp (ptr,"q") == 0 || g_ascii_strcasecmp (ptr,"bye") == 0) exit = 1; /* File ops */ else if (g_ascii_strcasecmp (ptr, "open") == 0) do_open (); else if (g_ascii_strcasecmp (ptr, "create") == 0) do_create (); else if (g_ascii_strcasecmp (ptr, "close") == 0) do_close (); else if (g_ascii_strcasecmp (ptr, "handleinfo") == 0) do_handleinfo (); else if (g_ascii_strcasecmp (ptr, "read") == 0) do_read (); else if (g_ascii_strcasecmp (ptr, "seek") == 0) do_seek (); else fprintf (vfserr, "Unknown command '%s'", ptr); g_strfreev (arg_data); arg_data = NULL; } if (interactive) { g_source_remove (watch_id); g_main_loop_unref (main_loop); main_loop = NULL; } g_free (buffer); g_free (cur_dir); close_files (); return 0; }
bool assure_dir_exist( const std::string &path ) { return do_mkdir( path, 0777 ) || ( errno == EEXIST && dir_exist( path ) ); }
void *extra_self_tests(int arg1, void *arg2) { /* creating /test1/test2/ directories */ dbg(DBG_ERROR | DBG_VFS,"TEST: Creating directories\n"); do_mkdir("dir"); do_mkdir("dir/dir1"); do_mkdir("dir/dir2"); do_mkdir("dir/dir3"); do_mkdir("dir/dir4"); dbg(DBG_ERROR | DBG_VFS,"TEST: Directories are created\n"); int fd; char *file2buf="File 2 write only test case"; char *file1buf="Testing file_1 for write operation"; char readbuf[150]; dbg(DBG_ERROR | DBG_VFS,"TEST: Change directory to dir/dir1\n"); do_chdir("dir/dir1"); /* file1.txt creation with O_CREAT|O_WRONLY flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Create file1.txt with O_CREAT|O_WRONLY flag in directory dir/dir1\n"); fd = do_open("file1.txt", O_CREAT|O_WRONLY); do_write(fd, file1buf, strlen(file1buf)); do_close(fd); /* file2.txt creation with O_CREAT|O_RDONLY flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Change directory to dir/dir2\n"); do_chdir("/dir/dir2"); dbg(DBG_ERROR | DBG_VFS,"TEST: Create file2.txt with O_CREAT | O_RDONLY flag in directory dir/dir2\n"); fd = do_open("file2.txt", O_CREAT | O_RDONLY); do_close(fd); /* Write into file2.txt using O_WRONLY flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Write into file2.txt with O_WRONLY flag in directory dir/dir2\n"); fd = do_open("file2.txt", O_WRONLY); do_write(fd, file2buf, strlen(file2buf)); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: written chars: \"%s\" in file2.txt\n",file2buf); char *appendbuf=" Appending for O_WRONLY|O_APPEND mode"; /* Append into file2.txt using O_WRONLY|O_APPEND flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Append into file2.txt with O_WRONLY|O_APPEND flag in directory dir/dir2\n"); fd = do_open("file2.txt", O_WRONLY|O_APPEND); do_write(fd, appendbuf, strlen(appendbuf)); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: Appending chars: \"%s\" in file2.txt\n",appendbuf); fd = do_open("file2.txt", O_RDONLY); memset(readbuf,0,sizeof(char)*150); do_read(fd,readbuf,strlen(file2buf)+strlen(appendbuf)); dbg(DBG_ERROR | DBG_VFS,"TEST: After Appending text in file2.txt is: \"%s\" \n",readbuf); char *append2buf=" Appending for O_RDWR|O_APPEND mode in file2"; /* Append into file2.txt using O_RDWR|O_APPEND flag*/ dbg(DBG_ERROR | DBG_VFS,"TEST: Append into file2.txt with O_RDWR|O_APPEND flag in directory dir/dir2\n"); fd = do_open("file2.txt", O_RDWR|O_APPEND); do_write(fd, append2buf, strlen(append2buf)); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: Appending chars: \"%s\" in file2.txt\n",append2buf); fd = do_open("file2.txt", O_RDONLY); memset(readbuf,0,sizeof(char)*150); do_read(fd,readbuf,strlen(file2buf)+strlen(append2buf)+strlen(appendbuf)); dbg(DBG_ERROR | DBG_VFS,"TEST: After Appending text in file2.txt is: \"%s\" \n",readbuf); dbg(DBG_ERROR | DBG_VFS,"TEST:Linking Source directory => /dir/dir2, Destination directory => /dir/linkofdir2 \n"); do_chdir("/"); do_link("dir/dir2","dir/linkofdir2"); dbg(DBG_ERROR | DBG_VFS,"TEST:Linking Source file => /dir/dir1/file1.txt, to the Destination => /dir/linkoffile1 \n"); do_link("dir/dir1/file1.txt","dir/linkoffile1"); dbg(DBG_ERROR | DBG_VFS,"TEST: Renaming directory from dir/dir3 to dir/renamed \n"); do_rename("dir/dir3","dir/renameddir3"); dbg(DBG_ERROR | DBG_VFS,"TEST: Renaming file from dir/dir1/file1.txt to dir/dir1/renamedfile1.txt \n"); do_rename("dir/dir1/file1.txt","dir/dir1/renamedfile1.txt"); dbg(DBG_ERROR | DBG_VFS,"TEST: Removing directory dir/dir4 \n"); do_rmdir("dir/dir4"); dbg(DBG_ERROR | DBG_VFS,"TEST: reading 18 chars from file: /dir/linkoffile2 which is hard link of /dir/dir2/file2.txt \n"); fd = do_open("dir/linkoffile2", O_RDONLY); memset(readbuf,0,sizeof(char)*150); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: read 18 chars: \"%s\" from file: /dir/linkoffile1\n",readbuf); dbg(DBG_ERROR | DBG_VFS,"TEST: reading file using lseek function on /dir/linkoffile2 which is hard link of /dir/dir2/file2.txt \n"); memset(readbuf,0,sizeof(char)*150); fd = do_open("dir/linkoffile2", O_RDONLY); do_lseek(fd,-19,2); do_read(fd,readbuf,19); do_close(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: read chars: \"%s\" using lseek from file: /dir/linkoffile1\n",readbuf); dbg(DBG_ERROR | DBG_VFS,"TEST: creating a duplicate file descriptor of file: /dir/dir2/file2.txt using do_dup()\n"); fd = do_open("/dir/dir2/file2.txt", O_RDONLY); int fd2= do_dup(fd); dbg(DBG_ERROR | DBG_VFS,"TEST: duplicate file descriptor is :\"%d\" of file: /dir/dir2/file2.txt \n",fd2); do_close(fd); do_close(fd2); dbg(DBG_ERROR | DBG_VFS,"TEST: creating a duplicate file descriptor of file: /dir/dir2/file2.txt using do_dup2()\n"); fd = do_open("/dir/dir2/file2.txt", O_RDONLY); fd2= do_dup2(fd,20); dbg(DBG_ERROR | DBG_VFS,"TEST: custom file descriptor is :\"%d\" of file: /dir/dir2/file2.txt \n",fd2); do_close(fd); do_close(fd2); /* Testing stat struct *statbuf; dbg(DBG_ERROR | DBG_VFS,"TEST: Testing the stat system call for directory dir\n"); do_stat("dir",statbuf); dbg(DBG_ERROR | DBG_VFS,"TEST: Output of stat for directory dir is :\"%s\" \n",statbuf);*/ shellTest(); return NULL; }
void sysfs_create(int devnum, const struct file_operations *verb_fops, void *ptr) { char sysname[256] = "/sys/class/infiniband_verbs/uverbs0"; char devname[] = "/dev_vfs/infiniband/uverbs0"; char drvname[64] = "/sys/class/infiniband/"; int sysnameidx = strlen(sysname), drvidx; struct file *fp; struct ib_uverbs_device *uvp = (struct ib_uverbs_device *)ptr; /* Create correct name */ if (devnum > 9) panic("Too many devs"); devname[strlen(devname) - 1] = '0' + devnum; sysname[sysnameidx - 1] = '0' + devnum; /* Foll fops need to come from caller */ fp = make_device(devname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)verb_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband/mlx4_0 */ strncpy((drvname + strlen(drvname)), uvp->ib_dev->name, 12); do_mkdir(drvname, S_IRWXU | S_IRWXG | S_IRWXO); drvidx = strlen(drvname); /* /sys/class/infiniband/mlx4_0/node_type */ strncpy(drvname + drvidx, "/node_type", 11); make_device(drvname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&ntype_fops); /* /sys/class/infiniband/mlx4_0/vsd */ strncpy(drvname + drvidx, "/vsd", 5); fp = make_device(drvname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&vsd_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband_verbs/uverbs0 */ do_mkdir(sysname, S_IRWXU | S_IRWXG | S_IRWXO); /* /sys/class/infiniband_verbs/uverbs0/device */ strncpy(sysname + sysnameidx, "/device", 16); do_mkdir(sysname, S_IRWXU | S_IRWXG | S_IRWXO); /* /sys/class/infiniband_verbs/uverbs0/device/device */ strncpy(sysname + sysnameidx, "/device/device", 16); fp = make_device(sysname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&ddev_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband_verbs/uverbs0/device/vendor */ strncpy(sysname + sysnameidx, "/device/vendor", 16); fp = make_device(sysname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&dven_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband_verbs/uverbs0/ibdev */ strncpy(sysname + sysnameidx, "/ibdev", 16); fp = make_device(sysname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&dname_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband_verbs/uverbs0/abi_version */ strncpy(sysname + sysnameidx, "/abi_version", 16); fp = make_device(sysname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&dver_fops); set_fs_info(fp, ptr); }
int main( int argc, char *argv[] ) { char cmd[MAX_STRING_LEN]; char path[MAX_STRING_LEN]; char buffer[MAX_STRING_LEN]; char *line; char myname[MAX_STRING_LEN]; char *saveptr; char *token; char treefile[MAX_STRING_LEN]; char treefile2[MAX_STRING_LEN]; int count; int i; int length; int myrank; int num_elems_recv; int num_nodes; int treefile_size; int treefile_size2; MPI_Status stat; FILE *fptr; struct timeval t1_start; struct timeval t1_end; double t1_time; struct timeval split_start; struct timeval split_end; double split_time; int seed = 17; int status; /* Track time to run mrsrf-mpi */ gettimeofday(&t1_start, NULL); /* I initialize for myself the MPI API */ MPI_Init(&argc, &argv); /* Who am I? I request my ID number */ MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* How many nodes are available */ MPI_Comm_size(MPI_COMM_WORLD, &num_nodes); /* What is my hostname? */ MPI_Get_processor_name (myname, &length); fprintf(stderr,"\n[Node %d]:****Executing MrsRF-MPI on %s**** \n",myrank, myname); /* Process command-line arguments */ process_command_line_args(argc, argv); status = do_mkdir(MRSRFPQ_TEMP_DIR, 0777); if (status == -1) { fprintf(stderr, "Error creating directory %s", MRSRFPQ_TEMP_DIR); MPI_Abort(MPI_COMM_WORLD, 1); } /* Node 0 creates tree files for the other nodes */ if (myrank == 0) { gettimeofday(&t1_start, NULL); // Check to make sure that the number of trees is greater than the total number of cores if ((CORES * num_nodes) > NUM_MASTER_TREES) { fprintf(stderr, "The total number of cores (%d) is greater than the number of trees (%d) \n", CORES, NUM_MASTER_TREES); MPI_Abort(MPI_COMM_WORLD, 1); } // Create directory for storing files needed globally by MrsRF-MPI /* status = do_mkdir(MRSRF_MPI_TEMP_DIR, 0777); if (status == -1) { fprintf(stderr, "Error creating directory %s", MRSRF_MPI_TEMP_DIR); MPI_Abort(MPI_COMM_WORLD, 1); } */ //fprintf (stderr, "[Node %d]: Partitioning the input for the %d nodes\n", myrank, num_nodes); // Split input among the nodes /*fprintf (stderr, "[Node %d]: Partitioning the input for the %d nodes\n", myrank, num_nodes); fprintf(stderr, "[Node %d]: Creating __input-0.txt\n", myrank); gettimeofday(&split_start, NULL); //sprintf(cmd, "./peanuts/split_trees.pl %s %d %d %s", MASTER_TREE_FILE, NUM_MASTER_TREES, num_nodes, "./"); sprintf(cmd, "./peanuts/split_trees.pl %s %d %d", MASTER_TREE_FILE, NUM_MASTER_TREES, num_nodes); fprintf(stderr, "[Node %d]: %s\n", myrank, cmd); system(cmd); gettimeofday(&split_end, NULL); split_time = split_end.tv_sec - split_start.tv_sec + (split_end.tv_usec - split_start.tv_usec) / 1.e6; fprintf(stderr,"\n[Node %d]: ****Input split among the nodes: %g seconds**** \n", myrank, split_time); */ // Create seed for all nodes to use -- necessary for calls to hashbase in MrsRF code srand(time(NULL)); seed = rand() % MAX_INT_32; } MPI_Barrier(MPI_COMM_WORLD); MPI_Bcast (&seed, 1, MPI_INT, 0, MPI_COMM_WORLD); /* Safe for all processors to continue after broadcast of seed value */ //fprintf(stderr, "seed: %d\n", seed); // Process __input-0.txt file to get Node i's data /* sprintf(buffer, "__input-0.txt"); fptr = fopen(buffer, "r"); assert(fptr); line = (char *) malloc (MAX_STRING_LEN * sizeof(char)); for (i = 0; i < num_nodes; i++) { if ((fgets(line, MAX_STRING_LEN - 1, fptr) != NULL) && (i == myrank)) { // get treefile name token = strtok_r(line, " ", &saveptr); assert(token); strcpy(treefile, token); // get treefile2 name token = strtok_r(NULL, " ", &saveptr); assert(token); strcpy(treefile2, token); // get number of trees in treefile token = strtok_r(NULL, " ", &saveptr); assert(token); treefile_size = atoi(token); // get number of trees in treefile2 token = strtok_r(NULL, " ", &saveptr); assert(token); treefile_size2 = atoi(token); count = i; } } fclose(fptr); assert(count == myrank); */ /* Run MrsRF-phoenix-ver4 */ sprintf(cmd, "%s %d %s %d %d %d %d %d %d %d", MRSRFPQ, CORES, MASTER_TREE_FILE, TAXA, NUM_MASTER_TREES, num_nodes, myrank, OUTPUT, ROUNDS, seed); //sprintf(cmd, "%s %d %s %s %s %d %d %d %d %d %d %d %d", MRSRFPQ, CORES, treefile, treefile2, MASTER_TREE_FILE, TAXA, treefile_size, treefile_size2, NUM_MASTER_TREES, myrank, OUTPUT, ROUNDS, seed); fprintf(stderr, "[Node %d]: Running: %s\n", myrank, cmd); system(cmd); // Wait for all nodes to finish in order to create the final matrix MPI_Barrier(MPI_COMM_WORLD); /* node 0 constructs the final matrix */ if (OUTPUT ==1 && myrank == 0) { // Create directory for output of final RF matrix strcpy(path, "mrsrf-mpi-output"); status = do_mkdir(path, 0777); if (status == -1) { fprintf(stderr, "Error creating directory %s", path); MPI_Abort(MPI_COMM_WORLD, 1); } // Create final RF matrix fprintf(stderr, "[Node 0]: Creating final matrix\n"); sprintf(cmd, "./peanuts/create_final_matrix.pl %s %d node", path, num_nodes); system(cmd); fprintf(stderr, "[Node 0]: Final matrix computed\n"); } gettimeofday(&t1_end, NULL); t1_time = t1_end.tv_sec - t1_start.tv_sec + (t1_end.tv_usec - t1_start.tv_usec) / 1.e6; fprintf(stderr,"\n[Node %d]: ****MrsRF-MPI Completed: %g seconds**** \n", myrank, t1_time); /* Close the MPI API: */ MPI_Finalize(); return 0; }
/** * Once we're inside of idleproc_run(), we are executing in the context of the * first process-- a real context, so we can finally begin running * meaningful code. * * This is the body of process 0. It should initialize all that we didn't * already initialize in kmain(), launch the init process (initproc_run), * wait for the init process to exit, then halt the machine. * * @param arg1 the first argument (unused) * @param arg2 the second argument (unused) */ static void *idleproc_run(int arg1, void *arg2) { int status; pid_t child; /* create init proc */ kthread_t *initthr = initproc_create(); init_call_all(); GDB_CALL_HOOK(initialized); /* Create other kernel threads (in order) */ #ifdef __VFS__ curproc->p_cwd=vfs_root_vn; vref(vfs_root_vn); if(initthr!=NULL) { initthr->kt_proc->p_cwd=vfs_root_vn; vref(vfs_root_vn); } KASSERT(do_mkdir("/dev") == 0); KASSERT(do_mknod("/dev/null", S_IFCHR, MKDEVID(1, 0)) == 0); KASSERT(do_mknod("/dev/zero", S_IFCHR, MKDEVID(1, 1)) == 0); KASSERT(do_mknod("/dev/tty0", S_IFCHR, MKDEVID(2, 0)) == 0); KASSERT(do_mknod("/dev/tty1", S_IFCHR, MKDEVID(2, 1)) == 0); KASSERT(do_mknod("/dev/tty2", S_IFCHR, MKDEVID(2, 3)) == 0); /* Once you have VFS remember to set the current working directory * of the idle and init processes */ /* Here you need to make the null, zero, and tty devices using mknod */ /* You can't do this until you have VFS, check the include/drivers/dev.h * file for macros with the device ID's you will need to pass to mknod */ #endif /* Finally, enable interrupts (we want to make sure interrupts * are enabled AFTER all drivers are initialized) */ intr_enable(); /* Run initproc */ sched_make_runnable(initthr); /* dbg_print("\nidleproc_run returned from sched_make_rinnable and calling do wait_pid \n");*/ /* Now wait for it */ child = do_waitpid(-1, 0, &status); dbg(DBG_INIT,"Process %d cleaned successfully\n", child); KASSERT(PID_INIT == child); #ifdef __MTP__ kthread_reapd_shutdown(); #endif #ifdef __VFS__ /* Shutdown the vfs: */ dbg_print("weenix: vfs shutdown...\n"); vput(curproc->p_cwd); if (vfs_shutdown()) panic("vfs shutdown FAILED!!\n"); #endif dbg_print("weenix: vfs shutdown...\n"); /* Shutdown the pframe system */ #ifdef __S5FS__ pframe_shutdown(); #endif dbg_print("\nweenix: halted cleanly!\n"); GDB_CALL_HOOK(shutdown); hard_shutdown(); return NULL; }
int vfs_selftest(kshell_t *kshell, int argc, char **argv) { int fd1,fd2; char *y="/ab/fil"; char x[2]; int err; do_mkdir("/ab"); do_mknod("/ab/new", S_IFCHR,MKDEVID(1,1)); fd1=do_open("/ab/new",2); fd2=do_dup2(fd1,NFILES+1); if(fd2<0) { dbg(DBG_PRINT,"File not created\n"); } do_mknod("/ab/notmade",4096,MKDEVID(1,1)); do_mknod("/ab/new/not",S_IFCHR,MKDEVID(1,1)); do_mknod("/ab/new", S_IFCHR,MKDEVID(1,1)); do_mknod("", S_IFCHR,MKDEVID(1,1)); /*do_close(fd1);*/ for(fd2=1;fd2<35;fd2++) { sprintf(x,"%d",fd2); strcat(y,x); do_mknod(y,S_IFCHR,MKDEVID(1,0)); err=do_open(y,2); if(err<0) { break; } if(fd2<10) { y[strlen(y)-1]='\0'; } else { y[strlen(y)-2]='\0'; } } do_mknod("/ab/new1", S_IFCHR,MKDEVID(1,1)); err=do_dup(fd1); do_unlink("/ab/new/ab"); do_unlink("/ab/new"); do_close(fd1); for(fd2=NFILES-1;fd2>0;fd2--) { err=do_close(fd2); sprintf(x,"%d",fd2); strcat(y,x); do_unlink(y); if(err<0) { break; } if(fd2<10) { y[strlen(y)-1]='\0'; } else { y[strlen(y)-2]='\0'; } } do_link("/a","/dev"); do_link("/dev","/a"); do_link("/dev","/a"); do_rmdir("/a"); /* mkdir("/k"); do_link("/ab","/k");*/ do_rmdir("/ab"); /*do_rmdir("/k");*/ /*GS: SELF TESTS*/ dbg(DBG_PRINT,"\n*************************************************************\n"); dbg(DBG_PRINT,"\n\n\n\n(GRADING2C)(kmain.c)(selftest_proc_run) selftests begin\n"); int retVal = 0; int i = 0; /* 1. dbg(DBG_PRINT, "(GRADING2C) (vfs_syscall.c) (do_stat) strlen too long, return -ENAMETOOLONG\n");*/ char longPath[1024 + 1] = {0}; for(i = 0; i < 1025; i++) longPath[i] = 'a'; struct stat buf; retVal = do_stat(longPath, &buf); retVal=do_chdir(longPath); /*2. dbg(DBG_PRINT, "(GRADING2B) ENOTDIR or ENOENT\n");*/ retVal = do_stat("", &buf); /*3. dbg(DBG_PRINT, "(GRADING2C) (vfs_syscall.c) (do_getdent) Invalid file descriptor fd, return -EBADF\n");*/ struct dirent dirp; retVal = do_getdent(-1, &dirp); /*4. dbg(DBG_PRINT, "(GRADING2C) (vfs_syscall.c) (do_getdent) Invalid file descriptor fd, return -EBADF\n");*/ retVal = do_getdent(1, &dirp); /*5. dbg(DBG_PRINT, "(GRADING2C) (vfs_syscall.c) (do_getdent) File descriptor does not refer to a directory, return -ENOTDIR\n");*/ do_mknod("/./file", S_IFCHR,MKDEVID(1,1)); fd1 = do_open("/./file",2); retVal = do_getdent(fd1, &dirp); do_unlink("/./file"); do_close(fd1); /*6. dbg(DBG_PRINT, "(GRADING2C) (vfs_syscall.c) (do_rename) Both are valid names \n");*/ /* and */ /*7. dbg(DBG_PRINT, "(GRADING2C) (vfs_syscall.c) (do_rename) error do_link, return error\n"); \n");*/ retVal = do_rename("/./aaa", "/./bbb"); dbg(DBG_PRINT,"\n\nretVal=%d",retVal); dbg(DBG_PRINT,"\n*************************************************************\n"); return 0; }
void addFilespec(FILE *fd, int squash_uids, int squash_perms) { unsigned long rmode, mode, uid, gid, major, minor, i; unsigned long start, increment, count, octmode, decmode; char *c, *dir, *name, *dname = NULL, *path = NULL, *path2 = NULL, *line = NULL; char type; size_t len; int argv, i2, overWrite = 0, lineno = 0; __u16 inodeType; while ( getline(&line, &len, fd) >= 0 ) { rmode = mode = uid = gid = major = minor = start = count = overWrite = 0; increment = 1; lineno++; if (( c = strchr(line, '#'))) *c = 0; if ( path ) { free( path ); path = NULL; } if ( path2 ) { free( path2 ); path2 = NULL; } argv = sscanf(line, "%" SCANF_PREFIX "s %c %ld %lu %lu %lu %lu %lu %lu %lu", SCANF_STRING(path), &type, &rmode, &uid, &gid, &major, &minor, &start, &increment, &count); if ( argv < 3 ) { if ( argv > 0 ) log_warning("device table[%d]: bad format for entry '%s' [skip]", lineno, path); continue; } i2 = 0; octmode = rmode; decmode = 0; while ( octmode != 0 ) { decmode = decmode + (octmode % 10) * pow(8, i2++); octmode = octmode / 10; } if ( squash_uids ) uid = gid = 0; mode = decmode; path2 = strdup( path ); name = basename( path ); dir = dirname( path2 ); if (( !strcmp(name, ".")) || ( !strcmp(name, "..")) || ( !strcmp(name, "/"))) { log_warning("device table[%d]: [skip]", lineno); continue; } log_action(ACT_CHDIR, dir, NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir(dir)) { log_warning("device table[%d]: target directory '%s' for entry '%s' does not exist [skip]", lineno, dir, name); log_action(ACT_CHDIR, "/", NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir("/")) log_error("[Filesystem error] cannot chdir to root"); continue; } if (( type != 'd' ) && ( type != 'f' ) && ( type != 'p' ) && ( type != 'c' ) && ( type != 'b' ) && ( type != 's')) { log_warning("device table[%d]: bad type '%c' for entry '%s' [skip]", lineno, type, name); continue; } if (squash_perms) { mode &= ~( LINUX_S_IRWXG | LINUX_S_IRWXO ); rmode &= ~( LINUX_S_IRWXG | LINUX_S_IRWXO); } if ( count > 0 ) { if ( dname ) { free( dname ); dname = NULL; } unsigned len; len = strlen(name) + 10; dname = malloc(len + 1); for ( i = start; i < count; i++ ) { snprintf(dname, len, "%s%lu", name, i); if (( overWrite = name_to_inode(dname))) inodeType = inode_mode(dname); if (( type == 'd' ) && ( overWrite ) && ( !LINUX_S_ISDIR(inodeType))) log_error("[Remote fs mismatch] %s/%s exists but isn't a directory when it should be.", log_cwd(), dname); else if (( type != 'd' ) && ( overWrite )) { if ( LINUX_S_ISDIR(inodeType)) log_error("[Remote fs mismatch] %s/%s exists but is a directory when it shouldn't be.", log_cwd(), dname); if ((!LINUX_S_ISREG(inodeType)) && (!LINUX_S_ISLNK(inodeType)) && (!LINUX_S_ISBLK(inodeType)) && (!LINUX_S_ISCHR(inodeType)) && (!LINUX_S_ISFIFO(inodeType)) && (!LINUX_S_ISSOCK(inodeType))) log_error("[Remote fs mismatch] Existing file %s/%s has unknown/unsupported type [0x%x].", log_cwd(), dname, inodeType); } switch ( type ) { case 'd': mode |= LINUX_S_IFDIR; log_action(ACT_MKDIR, dname, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !overWrite ) if ( !do_mkdir(dname)) log_error("[Filesystem error] cannot mkdir %s/%s", log_cwd(), dname); break; case 'c': case 'b': if ( type == 'c' ) mode |= LINUX_S_IFCHR; else mode |= LINUX_S_IFBLK; if ( overWrite ) { log_action(ACT_RM, dname, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(dname)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), dname); } log_action(ACT_MKNOD, dname, NULL, 0, 0, 0, type, major, minor + ((i * increment) - start), overWrite); if ( !do_mknod(dname, type, major, minor + ((i * increment) - start))) log_error("[Filesystem error] cannot mknod %s/%s", log_cwd(), dname); break; case 's': case 'p': if ( type == 's' ) mode |= LINUX_S_IFSOCK; else mode |= LINUX_S_IFIFO; if ( overWrite ) { log_action(ACT_RM, dname, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(dname)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), dname); } log_action(ACT_MKNOD, dname, NULL, 0, 0, 0, type, 0, 0, overWrite); if ( !do_mknod(dname, type, 0, 0)) log_error("[Filesystem error] cannot mknod %s/%s", log_cwd(), dname); break; } log_action(ACT_CHMOD, dname, NULL, rmode, 0, 0, 0, 0, 0, 0); if ( !do_chmod(dname, rmode)) log_error("[Filesystem error] cannot chmod %s/%s", log_cwd(), dname); log_action(ACT_CHOWN, dname, NULL, 0, uid, gid, 0, 0, 0, 0); if ( !do_chown(dname, uid, gid)) log_error("[Filesystem error] cannot chown %s/%s", log_cwd(), dname); } log_action(ACT_CHDIR, "/", NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir("/")) log_error("[Filesystem error] cannot chdir to root"); free(dname); dname = NULL; } else { if (( overWrite = name_to_inode(name))) inodeType = inode_mode(name); if (( type == 'd' ) && ( overWrite ) && ( !LINUX_S_ISDIR(inodeType))) log_error("[Remote fs mismatch] %s/%s exists but isn't a directory when it should be.", log_cwd(), dname); else if ( type != 'd' ) { if (( overWrite ) && ( LINUX_S_ISDIR(inodeType))) log_error("[Remote fs mismatch] %s/%s exists but is a directory when it shouldn't be.", log_cwd(), dname); if (( overWrite ) && (!LINUX_S_ISREG(inodeType)) && (!LINUX_S_ISLNK(inodeType)) && (!LINUX_S_ISBLK(inodeType)) && (!LINUX_S_ISCHR(inodeType)) && (!LINUX_S_ISFIFO(inodeType)) && (!LINUX_S_ISSOCK(inodeType))) log_error("[Remote fs mismatch] Existing file %s/%s has unknown/unsupported type [0x%x].", log_cwd(), dname, inodeType); } switch ( type ) { case 'd': mode |= LINUX_S_IFDIR; log_action(ACT_MKDIR, name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !overWrite ) if ( !do_mkdir(name)) log_error("[Filesystem error] cannot mkdir %s/%s", log_cwd(), name); break; case 'c': case 'b': if ( type == 'c' ) mode |= LINUX_S_IFCHR; else mode |= LINUX_S_IFBLK; if ( overWrite ) { log_action(ACT_RM, name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(name)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), name); } log_action(ACT_MKNOD, name, NULL, 0, 0, 0, type, major, minor, overWrite); if ( !do_mknod(name, type, major, minor)) log_error("[Filesystem error] cannot mknod %s/%s", log_cwd(), name); break; case 's': case 'p': if ( type == 's' ) mode |= LINUX_S_IFSOCK; else mode |= LINUX_S_IFIFO; if ( overWrite ) { log_action(ACT_RM, name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(name)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), name); } log_action(ACT_MKNOD, name, NULL, 0, 0, 0, type, 0, 0, overWrite); if ( !do_mknod(name, type, 0, 0)) log_error("[Filesystem error] cannot mknod %s/%s", log_cwd(), name); break; } log_action(ACT_CHMOD, name, NULL, rmode, 0, 0, 0, 0, 0, 0); if ( !do_chmod(name, rmode)) log_error("[Filesystem error] cannot chmod %s/%s", log_cwd(), name); log_action(ACT_CHOWN, name, NULL, 0, uid, gid, 0, 0, 0, 0); if ( !do_chown(name, uid, gid)) log_error("[Filesystem error] cannot chown %s/%s", log_cwd(), name); log_action(ACT_CHDIR, "/", NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir("/")) log_error("[Filesystem error] cannot chdir to root"); } } if ( line ) { free( line ); line = NULL; } if ( path ) { free( path ); path = NULL; } if ( path2 ) { free( path2 ); path2 = NULL; } }