int thesmurFS_create(const char* path, mode_t mod, struct fuse_file_info* fi) { char* physical_path; char* path_copy; int fd; //emergency_output("create"); if(get_physical_path(path, &physical_path) == -1) { //emergency_output("ENOMEM"); return -errno; } fd = creat(physical_path, mod); if(fd<0) return -errno; fi->fh = fd; //emergency_output("create - update hash"); //emergency_output(physical_path); path_copy = calloc(strlen(physical_path)+1, sizeof(char)); memcpy(path_copy, physical_path, strlen(physical_path)+1); update_hash_file(path_copy); make_parent_dir(path_copy); update_hash_folder(path_copy, 1); free(path_copy); return 0; }
int thesmurFS_truncate(const char* path, off_t size) { char* physical_path; char* path_copy; int r; if(get_physical_path(path, &physical_path) == -1) { //emergency_output("ENOMEM"); return -errno; } //emergency_output("truncating:"); //emergency_output(path); //emergency_output_plus_n("new size", size); r = truncate(physical_path, size); //emergency_output_plus_n("truncate returns", r); if(r == -1) { return -errno; //emergency_output_plus_n("truncate errno", errno); //emergency_output("-----truncate"); } //emergency_output("-----truncate"); //emergency_output("truncate - update hash"); //emergency_output(physical_path); path_copy = calloc(strlen(physical_path)+1, sizeof(char)); memcpy(path_copy, physical_path, strlen(physical_path)+1); update_hash_file(path_copy); make_parent_dir(path_copy); update_hash_folder(path_copy, 1); free(path_copy); return r; }
int thesmurFS_rmdir(const char* path) { char* physical_path; char* path_copy; int r; if(get_physical_path(path, &physical_path) == -1) { //emergency_output("ENOMEM"); return -errno; } r = rmdir(physical_path); if(r<0) return -errno; path_copy = calloc(strlen(physical_path)+1, sizeof(char)); memcpy(path_copy, physical_path, strlen(physical_path)+1); make_parent_dir(path_copy); update_hash_folder(path_copy, 1); free(path_copy); return r; }
int thesmurFS_release(const char* path, struct fuse_file_info *fi) { char* path_copy; int r; //emergency_output("release"); //get_physical_path(path, &physical_path); r = close(fi->fh); if(r == -1) return -errno; get_physical_path(path, &path_copy); //emergency_output("release - update hash"); //emergency_output(path_copy); update_hash_file(path_copy); make_parent_dir(path_copy); update_hash_folder(path_copy, 1); free(path_copy); return r; }
/* * Output a block of volume data as requested by the 'vo' object. */ int update_volume_output(struct volume *wrld, struct volume_output_item *vo) { int failure = 0; char *filename; switch (wrld->notify->volume_output_report) { case NOTIFY_NONE: break; case NOTIFY_BRIEF: case NOTIFY_FULL: mcell_log("Updating volume output '%s' scheduled at time %.15g on " "iteration %lld.", vo->filename_prefix, vo->t, wrld->current_iterations); break; default: UNHANDLED_CASE(wrld->notify->volume_output_report); } /* build the filename */ filename = CHECKED_SPRINTF("%s.%lld.dat", vo->filename_prefix, wrld->current_iterations); /* Try to make the directory if it doesn't exist */ if (make_parent_dir(filename)) { free(filename); return 1; } /* Output the volume item */ failure = output_volume_output_item(wrld, filename, vo); free(filename); /* Reschedule this volume item, if appropriate */ if (!failure) failure = reschedule_volume_output_item(wrld, vo); /* Should we return failure if we can't create the file? Doing so will bring * down the entire sim... */ return failure; }
/* touch depfile for symbol 'name' */ static int conf_touch_dep(const char *name) { int fd, ret; const char *s; char *d, c; /* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */ if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path)) return -1; d = depfile_path + depfile_prefix_len; s = name; while ((c = *s++)) *d++ = (c == '_') ? '/' : tolower(c); strcpy(d, ".h"); /* Assume directory path already exists. */ fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd == -1) { if (errno != ENOENT) return -1; ret = make_parent_dir(depfile_path); if (ret) return ret; /* Try it again. */ fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd == -1) return -1; } close(fd); return 0; }
/************************************************************************** check_reaction_output_file: Check that the reaction output file is writable within the policy set by the user. Creates and/or truncates the file to 0 bytes, as appropriate. Note that for SUBSTITUTE, the truncation is done later on, during initialization. In: parse_state: parser state os: output set containing file details Out: 0 if file preparation is successful, 1 if not. The file named will be created and emptied or truncated as requested. **************************************************************************/ int check_reaction_output_file(struct output_set *os) { FILE *f; char *name; struct stat fs; int i; name = os->outfile_name; if (make_parent_dir(name)) { // mdlerror_fmt(parse_state, // "Directory for %s does not exist and could not be // created.", // name); return 1; } switch (os->file_flags) { case FILE_OVERWRITE: f = fopen(name, "w"); if (!f) { switch (errno) { case EACCES: // mdlerror_fmt(parse_state, "Access to %s denied.", name); return 1; case ENOENT: // mdlerror_fmt(parse_state, "Directory for %s does not exist", // name); return 1; case EISDIR: // mdlerror_fmt(parse_state, "%s already exists and is a // directory", name); return 1; default: // mdlerror_fmt(parse_state, "Unable to open %s for writing", // name); return 1; } } fclose(f); break; case FILE_SUBSTITUTE: f = fopen(name, "a+"); if (!f) { switch (errno) { case EACCES: // mdlerror_fmt(parse_state, "Access to %s denied.", name); return 1; case ENOENT: // mdlerror_fmt(parse_state, "Directory for %s does not exist", // name); return 1; case EISDIR: // mdlerror_fmt(parse_state, "%s already exists and is a // directory", name); return 1; default: // mdlerror_fmt(parse_state, "Unable to open %s for writing", // name); return 1; } } i = fstat(fileno(f), &fs); if (!i && fs.st_size == 0) os->file_flags = FILE_OVERWRITE; fclose(f); break; case FILE_APPEND: case FILE_APPEND_HEADER: f = fopen(name, "a"); if (!f) { switch (errno) { case EACCES: // mdlerror_fmt(parse_state, "Access to %s denied.", name); return 1; case ENOENT: // mdlerror_fmt(parse_state, "Directory for %s does not exist", // name); return 1; case EISDIR: // mdlerror_fmt(parse_state, "%s already exists and is a // directory", name); return 1; default: // mdlerror_fmt(parse_state, "Unable to open %s for writing", // name); return 1; } } i = fstat(fileno(f), &fs); if (!i && fs.st_size == 0) os->file_flags = FILE_APPEND_HEADER; fclose(f); break; case FILE_CREATE: i = access(name, F_OK); if (!i) { i = stat(name, &fs); if (!i && fs.st_size > 0) { // mdlerror_fmt(parse_state, // "Cannot create new file %s: it already exists", // name); return 1; } } f = fopen(name, "w"); if (f == NULL) { switch (errno) { case EEXIST: // mdlerror_fmt(parse_state, "Cannot create %s because it already // exists", // name); return 1; case EACCES: // mdlerror_fmt(parse_state, "Access to %s denied.", name); return 1; case ENOENT: // mdlerror_fmt(parse_state, "Directory for %s does not exist", // name); return 1; case EISDIR: // mdlerror_fmt(parse_state, "%s already exists and is a // directory", name); return 1; default: // mdlerror_fmt(parse_state, "Unable to open %s for writing", // name); return 1; } } fclose(f); break; default: UNHANDLED_CASE(os->file_flags); } return 0; }