Esempio n. 1
0
File: rm.c Progetto: mslusarz/nvml
/*
 * rm_poolset_cb -- (internal) callback for removing replicas
 */
static int
rm_poolset_cb(struct part_file *pf, void *arg)
{
	if (pf->is_remote) {
		return remove_remote(pf->node_addr, pf->pool_desc);
	} else {
		const char *part_file = pf->path;

		outv(2, "part file   : %s\n", part_file);

		int exists = access(part_file, F_OK) == 0;
		if (!exists) {
			/*
			 * Ignore not accessible file if force
			 * flag is set
			 */
			if (force)
				return 0;

			err(1, "cannot remove file '%s'", part_file);
		}

		rm_file(part_file);
	}

	return 0;
}
Esempio n. 2
0
static int inotify_modify_helper(
	const char *name,
	const char *path,
	const void *dummy)
{
	int fd, rc = 0;
	char buffer[1] = { 0 };

	(void)dummy;
	if (mk_file(name, path, 4096) < 0)
		return -1;
	if ((fd = open(path, O_RDWR)) < 0) {
		pr_err(stderr, "%s: cannot open file %s: errno=%d (%s)\n",
			name, path, errno, strerror(errno));
		rc = -1;
		goto remove;
	}
do_modify:
	if (opt_do_run && (write(fd, buffer, 1) < 0)) {
		if ((errno == EAGAIN) || (errno == EINTR))
			goto do_modify;
		pr_err(stderr, "%s: cannot write to file %s: errno=%d (%s)\n",
			name, path, errno, strerror(errno));
		rc = -1;
	}
	(void)close(fd);
remove:
	(void)rm_file(name, path);
	return rc;
}
Esempio n. 3
0
/*
 *  rm_dir()
 *	clean files in directory and directory
 */
static int rm_dir(const char *name, const char *path)
{
	DIR *dp;
	int ret;

	dp = opendir(path);
	if (dp != NULL) {
		struct dirent *d;

		while ((d = readdir(dp)) != NULL) {
			char filename[PATH_MAX];

			if (!strcmp(d->d_name, ".") ||
			    !strcmp(d->d_name, ".."))
				continue;

			snprintf(filename, sizeof(filename), "%s/%s",
				path, d->d_name);
			(void)rm_file(name, filename);
		}
		(void)closedir(dp);
	}
	ret = rmdir(path);
	if (ret < 0 && errno != ENOENT)
		pr_err(stderr, "%s: cannot remove directory %s: errno=%d (%s)\n",
			name, path, errno, strerror(errno));
	return ret;
}
Esempio n. 4
0
/*
 *  mk_file()
 *	create file of length len bytes
 */
static int mk_file(const char *name, const char *filename, const size_t len)
{
	int fd;
	size_t sz = len;

	char buffer[BUF_SIZE];

	(void)rm_file(name, filename);
	if ((fd = open(filename, O_CREAT | O_RDWR, FILE_FLAGS)) < 0) {
		pr_err(stderr, "%s: cannot create file %s: errno=%d (%s)\n",
			name, filename, errno, strerror(errno));
		return -1;
	}

	memset(buffer, 'x', BUF_SIZE);
	while (sz > 0) {
		size_t n = (sz > BUF_SIZE) ? BUF_SIZE : sz;
		int ret;

		if ((ret = write(fd, buffer, n)) < 0) {
			pr_err(stderr, "%s: error writing to file %s: errno=%d (%s)\n",
				name, filename, errno, strerror(errno));
			(void)close(fd);
			return -1;
		}
		sz -= ret;
	}

	if (close(fd) < 0) {
		pr_err(stderr, "%s: cannot close file %s: errno=%d (%s)\n",
			name, filename, errno, strerror(errno));
		return -1;
	}
	return 0;
}
Esempio n. 5
0
static void inotify_creat_file(const char *name, const char *path)
{
	char filepath[PATH_MAX];

	mk_filename(filepath, PATH_MAX, path, "inotify_file");
	inotify_exercise(name, filepath, path, "inotify_file", inotify_creat_helper, IN_CREATE, NULL);
	(void)rm_file(name, filepath);
}
Esempio n. 6
0
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
main(int argc, char *argv[])
{
	int ch, rflag;

	setlocale(LC_ALL, "");

	Pflag = rflag = 0;
	while ((ch = getopt(argc, argv, "dfiPRr")) != -1)
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (Pflag) {
		if (pledge("stdio rpath wpath cpath getpw", NULL) == -1)
			err(1, "pledge");
	} else {
		if (pledge("stdio rpath cpath getpw", NULL) == -1)
			err(1, "pledge");
	}

	if (argc < 1 && fflag == 0)
		usage();

	checkdot(argv);

	if (*argv) {
		stdin_ok = isatty(STDIN_FILENO);

		if (rflag)
			rm_tree(argv);
		else
			rm_file(argv);
	}

	exit(eval);
}
Esempio n. 7
0
main(int argc,
	char *argv[])
#endif
{
	int ch, rflag;

#if defined(__GNO__)  &&  defined(__STACK_CHECK__)
	_beginStackCheck();
	atexit(report_stack);
#endif
	rflag = 0;
	while ((ch = getopt(argc, argv, "dfiPRr")) != EOF)
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
#ifndef __ORCAC__
	argv += optind;
#else
	argv = argv + optind;
#endif

	if (argc < 1)
		usage();

	checkdot(argv);
	if (!*argv)
		exit (eval);

	stdin_ok = isatty(STDIN_FILENO);
	uid = geteuid();

	if (rflag)
		rm_tree(argv);
	else
		rm_file(argv);
	exit (eval);
}
Esempio n. 8
0
static int inotify_delete_helper(
	const char *name,
	const char *path,
	const void *dummy)
{
	(void)dummy;

	return rm_file(name, path);
}
Esempio n. 9
0
static void inotify_open_file(const char *name, const char *path)
{
	char filepath[PATH_MAX];

	mk_filename(filepath, PATH_MAX, path, "inotify_file");
	if (mk_file(name, filepath, 4096) < 0)
		return;
	inotify_exercise(name, filepath, path, "inotify_file", inotify_open_helper, IN_OPEN, NULL);
	(void)rm_file(name, filepath);
}
Esempio n. 10
0
static void inotify_delete_file(const char *name, const char *path)
{
	char filepath[PATH_MAX];

	mk_filename(filepath, PATH_MAX, path, "inotify_file");
	if (mk_file(name, filepath, 4096) < 0)
		return;
	inotify_exercise(name, filepath, path, "inotify_file", inotify_delete_helper, IN_DELETE, NULL);
	/* We remove (again) it just in case the test failed */
	(void)rm_file(name, filepath);
}
Esempio n. 11
0
void inotify_attrib_file(const char *name, const char *path)
{
	char filepath[PATH_MAX];

	mk_filename(filepath, PATH_MAX, path, "inotify_file");
	if (mk_file(name, filepath, 4096) < 0)
		return;

	inotify_exercise(name, filepath, path, "inotify_file", inotify_attrib_helper, IN_ATTRIB, NULL);
	(void)rm_file(name, filepath);
}
Esempio n. 12
0
// done
static int handle_request(csiebox_server* server, int conn_fd) {
	csiebox_protocol_header header;
	memset(&header, 0, sizeof(header));
	int connection = recv_message(conn_fd, &header, sizeof(header));
	if (connection > 0 && header.req.magic == CSIEBOX_PROTOCOL_MAGIC_REQ) {
		switch (header.req.op) {
			case CSIEBOX_PROTOCOL_OP_LOGIN:
				fprintf(stderr, "========== ");
				csiebox_protocol_login req;
				if (complete_message_with_header(conn_fd, &header, &req)) {
					login(server, conn_fd, &req);
					fprintf(stderr, "[%s] [fd = %d] login\n", 
						server->client[conn_fd]->account.user, conn_fd);
				}
				return 0;
			case CSIEBOX_PROTOCOL_OP_SYNC_META:
				fprintf(stderr, "sync meta\n");
				csiebox_protocol_meta meta;
				if (complete_message_with_header(conn_fd, &header, &meta)) {
					sync_file(server, conn_fd, &meta);
				}
				return 0;
			case CSIEBOX_PROTOCOL_OP_SYNC_END:
				fprintf(stderr, "========== [%s] [fd = %d] sync end\n", 
					server->client[conn_fd]->account.user, conn_fd);
				sync_end(server, conn_fd);
				return 0;
			case CSIEBOX_PROTOCOL_OP_RM:
				fprintf(stderr, "sync rm\n");
				csiebox_protocol_rm rm;
				if (complete_message_with_header(conn_fd, &header, &rm)) {
					rm_file(server, conn_fd, &rm);
				}
				return 0;
			default:
				fprintf(stderr, "unknow op %x\n", header.req.op);
				return 0;
		}
	} else if (connection <= 0) {
		fprintf(stderr, "========== [%s] [fd = %d] logout\n", 
			server->client[conn_fd]->account.user, conn_fd);
		logout(server, conn_fd);
		return 1;
	}
	return 0;
}
Esempio n. 13
0
static void handle_inotify(csiebox_client* client) {
    int len = 0, i = 0;
    char buffer[EVENT_BUF_LEN];
    memset(buffer, 0, EVENT_BUF_LEN);

    if ((len = read(client->inotify_fd, buffer, EVENT_BUF_LEN)) <= 0) {
        return;
    }

    i = 0;
    while (i < len) {
        struct inotify_event* event = (struct inotify_event*)&buffer[i];
        char path[PATH_MAX];
        memset(path, 0, PATH_MAX);
        char* wd_path;
        if (!get_from_hash(&(client->inotify_hash), (void**)&wd_path, event->wd)) {
            continue;
        }
        sprintf(path, "%s/", wd_path);
        strncat(path, event->name, event->len);
        fprintf(stderr, "wd: %d\n", event->wd);
        if (event->mask & IN_CREATE) {
            fprintf(stderr, "type: create\n");
            fprintf(stderr, "sync file: %s\n", path);
            sync_file(client, path);
            if (event->mask & IN_ISDIR) {
                add_inotify(client, path);
            }
        } else if (event->mask & IN_ATTRIB) {
            fprintf(stderr, "type: attrib\n");
            fprintf(stderr, "sync file meta: %s\n", path);
            sync_file_meta(client, path);
        } else if (event->mask & IN_DELETE) {
            fprintf(stderr, "type: delete\n");
            fprintf(stderr, "rm file: %s\n", path);
            rm_file(client, path, event->mask & IN_ISDIR);
        } else {
            fprintf(stderr, "type: modify\n");
            fprintf(stderr, "sync file: %s\n", path);
            sync_file(client, path);
        }
        i += EVENT_SIZE + event->len;
    }
    memset(buffer, 0, EVENT_BUF_LEN);
}
Esempio n. 14
0
void rm_from_filelist(int id){

	int i,j,k;
	for(i=0;i<file_num;i++){
		for(j=0;j<MyFileList[i].copy_num;j++){
			if(MyFileList[i].loc_list[j]==id){
				pthread_mutex_lock(&lock);
				for(k=j+1;k<MyFileList[i].copy_num;k++){
					MyFileList[i].loc_list[k-1]=MyFileList[i].loc_list[k];
				}
				MyFileList[i].copy_num--;
				if(MyFileList[i].copy_num==0){
					printf("remove %s\n",MyFileList[i].filename);
					rm_file(i);
					i--;
				}
				pthread_mutex_unlock(&lock);
			}
		}
	}
}
Esempio n. 15
0
File: rm.c Progetto: astroynao/nvml
static int
rm_poolset_cb(const char *part_file, void *arg)
{
	outv(2, "part file   : %s\n", part_file);

	int exists = access(part_file, F_OK) == 0;
	if (!exists) {
		/*
		 * Ignore not accessible file if force
		 * flag is set
		 */
		if (force)
			return 0;

		err(1, "cannot remove file '%s'", part_file);
	}

	rm_file(part_file);

	return 0;
}
Esempio n. 16
0
/**
 * Handle a rm request
 *
 * @param msg client message data
 * @return Response data, NULL on allocation error
 */
resp_t *do_rm(msg_t *msg) {
    resp_t *resp = calloc(sizeof(resp_t));

    debug("Attempting to remove file...\n");

    if (!resp) {
        debug("Failed to allocate response.\n");
        return NULL;
    }

    if (!rm_file(msg->buf)) {
        resp->type = RM_OK;
        return resp;
    } else {
        debug("Failed to rm file.\n");
        resp->type = RM_FAIL;
        return resp;
    }

    cgc_memcpy(resp, msg, sizeof(resp_t));
    return resp;
}
Esempio n. 17
0
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
main(int argc, char *argv[])
{
	int ch;
	const char *p;
	pid_t tty_pgrp;

	/*
	 * Test for the special case where the utility is called as
	 * "unlink", for which the functionality provided is greatly
	 * simplified.
	 */
	if ((p = strrchr(argv[0], '/')) == NULL)
		p = argv[0];
	else
		++p;
	if (strcmp(p, "unlink") == 0) {
		while (getopt(argc, argv, "") != -1)
			usage();
		argc -= optind;
		argv += optind;
		if (argc != 1)
			usage();
		rm_file(&argv[0]);
		exit(eval);
	}

	Pflag = rflag = 0;
	while ((ch = getopt(argc, argv, "dfiIPRrvW")) != -1) {
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'I':
			/*
			 * The -I flag is intended to be generally aliasable
			 * in /etc/csh.cshrc.  We apply it only to foreground
			 * processes.
			 */
			if (ioctl(0, TIOCGPGRP, &tty_pgrp) == 0) {
				if (tty_pgrp == getpgrp())
					Iflag = 1;
			}
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		case 'v':
			vflag = 1;
			break;
		case 'W':
			Wflag = 1;
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 1) {
		if (fflag)
			return 0;
		usage();
	}

	checkdot(argv);
	uid = geteuid();
	
	signal(SIGINFO, siginfo);

	if (*argv) {
		stdin_ok = isatty(STDIN_FILENO);

		if (Iflag && !iflag) {
			if (check2(argv) == 0)
				exit (1);
		}
		if (rflag)
			rm_tree(argv);
		else
			rm_file(argv);
	}

	exit (eval);
}
    void addRepeatAnnotation(const string & in_vcf_filename, const string & repeat_masker_filename, const string & output_prefix) {

        cout << "[" << Utils::getLocalTime() << "] Running BayesTyperUtils (" << BTU_VERSION << ") addRepeatAnnotation ...\n" << endl;

        cout << "[" << Utils::getLocalTime() << "] Parsing RepeatMasker annotation ..." << endl;

        ifstream rm_file(repeat_masker_filename);

        unordered_map<string, map<string, vector<pair<uint, uint> > > > rm_allele_annotations;

        string line;
        uint line_count = 0;

        while (getline(rm_file, line)) {

            line_count++;

            if (line_count > 3) {

                auto line_split = Utils::splitStringEmptyIgnore(line, ' ');
                assert((line_split.size() == 15) or (line_split.size() == 16));

                string name = line_split.at(10);
                assert(!(name.empty()));

                assert(name.find(":") == string::npos);
                assert(name.find("#") == string::npos);

                assert(line_split.at(5).front() != '(');
                assert(line_split.at(5).back() != ')');
                assert(line_split.at(6).front() != '(');
                assert(line_split.at(6).back() != ')');
                assert(line_split.at(7).front() == '(');
                assert(line_split.at(7).back() == ')');

                uint query_start = stoi(line_split.at(5));
                uint query_end = stoi(line_split.at(6));

                assert(query_start <= query_end);

                auto rm_allele_annotations_it = rm_allele_annotations.emplace(line_split.at(4), map<string, vector<pair<uint, uint> > >());
                auto rm_allele_annotations_family_it = rm_allele_annotations_it.first->second.emplace(name, vector<pair<uint, uint> >());

                rm_allele_annotations_family_it.first->second.emplace_back(query_start, query_end);
            }
        }

        rm_file.close();

        map<uint,uint> label_count_freqs;

        for (auto & rm_allele_annotation : rm_allele_annotations) {

            uint num_labels = rm_allele_annotation.second.size();

            auto label_count_freq_emplace_res = label_count_freqs.emplace(num_labels, 1);

            if (!label_count_freq_emplace_res.second) {

                label_count_freq_emplace_res.first->second++;
            }
        }

        cout << "[" << Utils::getLocalTime() << "] Completed parsing of RepeatMasker annotation \n" << endl;
        cout << "[" << Utils::getLocalTime() << "] Label number distribution:\n" << endl;

        for (auto & label_count_freq : label_count_freqs) {

            cout << "\t- " << label_count_freq.first << ": " << label_count_freq.second << endl;
        }

        cout << "\n[" << Utils::getLocalTime() << "] Adding RepeatMasker labels to vcf ...\n" << endl;

        GenotypedVcfFileReader in_vcf(in_vcf_filename, true);

        VcfMetaData out_meta_data = in_vcf.metaData();
        assert(out_meta_data.infoDescriptors().emplace("RMA", Attribute::DetailedDescriptor("RMA", Attribute::Number::A, Attribute::Type::String, "RepeatMasker annotations (<family#nucleotide_cover>:...)")).second);

        VcfFileWriter out_vcf(output_prefix + ".vcf", out_meta_data, true);

        Variant * cur_var;
        uint num_variants = 0;
        uint num_allelles = 0;
        uint num_allelles_labelled = 0;

        while (in_vcf.getNextVariant(&cur_var)) {

            num_variants++;

            for (uint alt_idx = 0; alt_idx < cur_var->numAlts(); alt_idx++) {

                num_allelles++;

                string alt_id = cur_var->chrom() + "_" + to_string(cur_var->pos()) + "_" + to_string(alt_idx);
                auto rm_allele_annotations_find_res = rm_allele_annotations.find(alt_id);

                JoiningString alt_rm_label(':');

                if (rm_allele_annotations_find_res != rm_allele_annotations.end()) {

                    num_allelles_labelled++;

                    for (auto &repeat_family : rm_allele_annotations_find_res->second) {

                        JoiningString repeat_info_elements('#');
                        repeat_info_elements.join(repeat_family.first);
                        repeat_info_elements.join(to_string(calculateNucleotideCover(repeat_family.second)));

                        alt_rm_label.join(repeat_info_elements.str());
                    }

                    auto allele_attributes = Auxiliaries::alleleAttributes(cur_var->alt(alt_idx), cur_var->ref());
                    assert((allele_attributes.type == Auxiliaries::Type::Insertion) or (allele_attributes.type == Auxiliaries::Type::Deletion));

                } else {

                    alt_rm_label.join(".");
                }

                assert(!alt_rm_label.empty());
                assert(cur_var->alt(alt_idx).info().setValue("RMA", alt_rm_label.str()));
            }

            out_vcf.write(cur_var);

            if (num_variants % 100000 == 0) {

                cout << "[" << Utils::getLocalTime() << "] Labelled " << num_variants << " variant(s)" << endl;
            }

            delete cur_var;
        }

        cout << "\n[" << Utils::getLocalTime() << "] Completed BayesTyperUtils addRepeatMaskerAnnotation" << endl;
        cout << "[" << Utils::getLocalTime() << "] " << num_variants << " variant(s) were parsed in total" << endl;
        cout << "[" << Utils::getLocalTime() << "] " << num_allelles << " allele(s) were parsed in total" << endl;
        cout << "[" << Utils::getLocalTime() << "] " << num_allelles_labelled << " allele(s) were labelled\n" << endl;
    }
Esempio n. 19
0
File: ln.c Progetto: er13/e2tools
/* Name:	create_hard_link()
 *
 * Description:
 *
 * This function creates a hard link to an existing file
 *
 * Algorithm:
 *
 * Check input parameters
 * Check to see if the new file name already exists
 * Make sure the new file is not an existing directory
 * If the file exists, remove it if the del_current flag is set
 * Add the new file name and it's inode to the current directory.
 * Get the inode structure for the current inode number
 * update the number of links
 * Write the inode structure back out to the file system.
 *
 * Global Variables:
 *
 * None.
 *
 * Arguments:
 *
 * ext2_filsys fs;			  The current file system
 * ext2_ino_t cwd;			  The current working directory
 * ext2_ino_t new_file_ino;	  The inode number of the new file
 * char *newfile;			  The name of the new file
 * int ln_flags;			  Flags affecting hard_link action
 *
 * Return Values:
 *
 * 0 - the new file link was created successfully
 * any other value indicates an error
 *
 * Author: Keith W. Sheffield
 * Date:   03/05/2002
 *
 * Modification History:
 *
 * MM/DD/YY		 Name				Description
 * 06/30/02		 K.Sheffield		Directory link flag is now based on the
 *									type of file being linked.	This was
 *									causing problems if a directory was
 *									renamed.
 */
long
create_hard_link(ext2_filsys fs, ext2_ino_t cwd, ext2_ino_t new_file_ino,
                 char *newfile, int ln_flags)
{
  ext2_ino_t curr_ino;
  struct ext2_inode inode;
  long retval;
  int dir_flag;

  if (fs == NULL || newfile == NULL)
    {
      fputs("Invalid input parameter.  Exiting create_hard_link() with -1\n",
            stderr);
      return (-1);
    }

  /* check to see if the file name already exists in the current directory */
  if ((retval = ext2fs_namei(fs, cwd, cwd, newfile, &curr_ino)))
    {
      if (retval != EXT2_ET_FILE_NOT_FOUND)
        {
          fprintf(stderr, "%s\n",error_message(retval));
          return(retval);
        }

    }
  /* file name exists, let's see if is a directory */
  else if ((retval = ext2fs_check_directory(fs, curr_ino)))
    {
      if (retval != EXT2_ET_NO_DIRECTORY)
        {
          fprintf(stderr, "%s\n",error_message(retval));
          return(retval);
        }

      /* delete the existing file if needed */
      if ((ln_flags & E2T_FORCE) &&
          (curr_ino != new_file_ino))
        {
          if ((retval = rm_file(fs, cwd, newfile, curr_ino)))
            {
              fprintf(stderr, "%s\n",error_message(retval));
              return(retval);
            }
        }
      else
        {
          fprintf(stderr, "ln: %s: File exists\n", newfile);
          return(1);
        }
    }
  else
    {
    /* if we get here, then it's an existing directory */
      fprintf(stderr, "%s is a directory!\n", newfile);
      return(1);
    }

  /* read the inode associated with the file */
  if ((retval = read_inode(fs, new_file_ino, &inode)))
      {
      fprintf(stderr, "%s\n", error_message(retval));
      return (retval);
      }

  /* determine how to link into the directory based on the type of file */
  switch(inode.i_mode & LINUX_S_IFMT)
    {
    case LINUX_S_IFREG:
      dir_flag = EXT2_FT_REG_FILE;
      break;
    case LINUX_S_IFLNK:
      dir_flag = EXT2_FT_SYMLINK;
      break;
    case LINUX_S_IFDIR:
      dir_flag = EXT2_FT_DIR;
      break;
    case LINUX_S_IFSOCK:
      dir_flag = EXT2_FT_SOCK;
      break;
    case LINUX_S_IFBLK:
      dir_flag = EXT2_FT_BLKDEV;
      break;
    case LINUX_S_IFCHR:
      dir_flag = EXT2_FT_CHRDEV;
      break;
    case LINUX_S_IFIFO:
      dir_flag = EXT2_FT_FIFO;
      break;
    default:
      dir_flag = EXT2_FT_UNKNOWN;
      break;
    }


  if ((retval = ext2fs_link(fs, cwd, newfile, new_file_ino, dir_flag)))
    {
      /* check to see if we ran out of space in the directory */
      if (retval == EXT2_ET_DIR_NO_SPACE)
        {
          /* try resizing the directory and try again */
          if (0 == (retval = ext2fs_expand_dir(fs, cwd)))
            retval = ext2fs_link(fs, cwd, newfile, new_file_ino, dir_flag);
        }
      if (retval)
        {
          fprintf(stderr, "%s\n", error_message(retval));
          return retval;
        }
    }


  /* update the inode stat information */
  if ((ln_flags & E2T_DO_MV) == 0)
    {
      inode.i_links_count++;
      if ((retval = write_inode(fs, new_file_ino, &inode)))
        {
          fprintf(stderr, "%s\n", error_message(retval));
          return (retval);
        }
    }

  return(0);

} /* end of create_hard_link */
Esempio n. 20
0
File: rm.c Progetto: mslusarz/nvml
/*
 * pmempool_rm_func -- main function for rm command
 */
int
pmempool_rm_func(char *appname, int argc, char *argv[])
{
	int opt;
	while ((opt = getopt_long(argc, argv, optstr,
			long_options, NULL)) != -1) {
		switch (opt) {
		case 'h':
			pmempool_rm_help(appname);
			return 0;
		case 'v':
			vlevel++;
			break;
		case 's':
			only_pools = 1;
			break;
		case 'f':
			force = 1;
			ask_mode = ASK_NEVER;
			break;
		case 'i':
			ask_mode = ASK_ALWAYS;
			break;
		default:
			print_usage(appname);
			return -1;
		}
	}

	out_set_vlevel(vlevel);

	if (optind == argc) {
		print_usage(appname);
		return -1;
	}

	for (int i = optind; i < argc; i++) {
		char *file = argv[i];
		/* check if file exists and we can read it */
		int exists = access(file, F_OK | R_OK) == 0;
		if (!exists) {
			/* ignore not accessible file if force flag is set */
			if (force)
				continue;
			err(1, "cannot remove '%s'", file);
		}

		int is_poolset = util_is_poolset_file(file) == 1;

		if (is_poolset)
			outv(2, "poolset file: %s\n", file);
		else
			outv(2, "pool file   : %s\n", file);

		if (is_poolset) {
			rm_poolset(file);
			if (!only_pools)
				rm_file(file);
		} else {
			rm_file(file);
		}
	}

	return 0;
}
Esempio n. 21
0
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.	The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 *	file removal.
 */
int
main(int argc, char *argv[])
{
    int ch;
    char *p;

    (void)setlocale(LC_ALL, "");

    /*
     * Test for the special case where the utility is called as
     * "unlink", for which the functionality provided is greatly
     * simplified.
     */
    if ((p = strrchr(argv[0], '/')) == NULL)
        p = argv[0];
    else
        ++p;
    if (strcmp(p, "unlink") == 0) {
        while (getopt(argc, argv, "") != -1)
            usage();
        argc -= optind;
        argv += optind;
        if (argc != 1)
            usage();
        rm_file(&argv[0]);
        exit(eval);
    }

    Pflag = rflag = xflag = 0;
    while ((ch = getopt(argc, argv, "dfiIPRrvWx")) != -1)
        switch(ch) {
        case 'd':
            dflag = 1;
            break;
        case 'f':
            fflag = 1;
            iflag = 0;
            break;
        case 'i':
            fflag = 0;
            iflag = 1;
            break;
        case 'I':
            Iflag = 1;
            break;
        case 'P':
            Pflag = 1;
            break;
        case 'R':
        case 'r':			/* Compatibility. */
            rflag = 1;
            break;
        case 'v':
            vflag = 1;
            break;
        case 'W':
            Wflag = 1;
            break;
        case 'x':
            xflag = 1;
            break;
        default:
            usage();
        }
    argc -= optind;
    argv += optind;

    if (argc < 1) {
        if (fflag)
            return (0);
        usage();
    }

    checkdot(argv);
    checkslash(argv);
    uid = geteuid();

    (void)signal(SIGINFO, siginfo);
    if (*argv) {
        stdin_ok = isatty(STDIN_FILENO);

        if (Iflag) {
            if (check2(argv) == 0)
                exit (1);
        }
        if (rflag)
            rm_tree(argv);
        else
            rm_file(argv);
    }

    exit (eval);
}
Esempio n. 22
0
File: rm.c Progetto: dezelin/kBuild
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
kmk_builtin_rm(int argc, char *argv[], char **envp)
{
	int ch, rflag;

	/* reinitialize globals */
	argv0 = argv[0];
	dflag = eval = fflag = iflag = Pflag = vflag = Wflag = stdin_ok = 0;
	uid = 0;
	kBuildProtectionInit(&g_ProtData);

	/* kmk: reset getopt and set program name. */
	g_progname = argv[0];
	opterr = 1;
	optarg = NULL;
	optopt = 0;
	optind = 0; /* init */

	Pflag = rflag = 0;
	while ((ch = getopt_long(argc, argv, "dfiPRvW", long_options, NULL)) != -1)
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
#if 0
		case 'r':			/* Compatibility. */
#endif
			rflag = 1;
			break;
		case 'v':
			vflag = 1;
			break;
#ifdef FTS_WHITEOUT
		case 'W':
			Wflag = 1;
			break;
#endif
		case 261:
			kBuildProtectionTerm(&g_ProtData);
			usage(stdout);
			return 0;
		case 262:
			kBuildProtectionTerm(&g_ProtData);
			return kbuild_version(argv[0]);
		case 263:
			kBuildProtectionDisable(&g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE);
			break;
		case 264:
			kBuildProtectionEnable(&g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE);
			break;
		case 265:
			kBuildProtectionEnable(&g_ProtData, KBUILDPROTECTIONTYPE_FULL);
			break;
		case 266:
			kBuildProtectionDisable(&g_ProtData, KBUILDPROTECTIONTYPE_FULL);
			break;
		case 267:
			if (kBuildProtectionSetDepth(&g_ProtData, optarg)) {
			    kBuildProtectionTerm(&g_ProtData);
			    return 1;
			}
			break;
		case '?':
		default:
			kBuildProtectionTerm(&g_ProtData);
			return usage(stderr);
		}
	argc -= optind;
	argv += optind;

	if (argc < 1) {
		kBuildProtectionTerm(&g_ProtData);
		if (fflag)
			return (0);
		return usage(stderr);
	}

	if (!kBuildProtectionScanEnv(&g_ProtData, envp, "KMK_RM_")) {
		checkdot(argv);
		uid = geteuid();

		if (*argv) {
			stdin_ok = isatty(STDIN_FILENO);
			if (rflag)
				eval |= rm_tree(argv);
			else
				eval |= rm_file(argv);
		}
	} else {
		eval = 1;
	}

	kBuildProtectionTerm(&g_ProtData);
	return eval;
}
Esempio n. 23
0
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
main(int argc, char *argv[])
{
	int ch, rflag;

	setprogname(argv[0]);
	(void)setlocale(LC_ALL, "");

	Pflag = rflag = xflag = 0;
	while ((ch = getopt(argc, argv, "dfiPRrvWx")) != -1)
		switch (ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		case 'v':
			vflag = 1;
			break;
		case 'x':
			xflag = 1;
			break;
#ifndef __ANDROID__
		case 'W':
			Wflag = 1;
			break;
#endif
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc < 1) {
		if (fflag)
			return 0;
		usage();
	}

	(void)signal(SIGINFO, progress);

	checkdot(argv);

	if (*argv) {
		stdin_ok = isatty(STDIN_FILENO);

		if (rflag)
			rm_tree(argv);
		else
			rm_file(argv);
	}

	exit(eval);
	/* NOTREACHED */
}
Esempio n. 24
0
void main(int argc, char *argv[])
{
	int i = 0, cmd = -1, fd = 0; 
	char line[128], cname[64], temp_pathname[124], pathname[124] = "NULL", basename[124] = "NULL",
	     dirname[124] = "NULL", parameter[124] = "NULL", *device;

	//GETS DISK NAME TO MOUNT
	/*
	printf("Enter the name of your disk image\n");
	fgets(device, 128, stdin);
	device[strlen(device)-1] = 0;  // kill the \n char at end	
	*/
	device = "mydisk";
	
	mount_root(device, &fd);

	while(1)
	{
		//printf("P%d running: ", running.uid);
		printf("nick's@linux:");
		pwd(P0.cwd);
		printf("$ ");
		fgets(line, 128, stdin);
		line[strlen(line)-1] = 0;  // kill the \n char at end
		if (line[0]==0) continue;

		sscanf(line, "%s %s %s", cname, pathname, parameter);

		if(strcmp(pathname,"NULL") != 0)		
			strcpy(PATHNAME, pathname);
		
		if(strcmp(parameter,"NULL") != 0)		
			strcpy(PARAMETER, parameter);

		cmd = findCmd(cname); // map cname to an index
		switch(cmd)
		{
			case 0 : menu();		break;
			case 1 : pwd(P0.cwd);printf("\n");			break;
			case 2 : ls();			break;
			case 3 : cd();			break;
			case 4 : make_dir();		break;
			case 5 : rmdir();               break;
			case 6 : creat_file();          break;
			case 7 : link();                break;
			case 8 : unlink();              break;
			case 9 : symlink();             break;
			case 10: rm_file();             break;
			case 11: chmod_file();          break;
			case 12: chown_file();          break;
			case 13: stat_file();           break;
			case 14: touch_file();          break;
			case 20: open_file();           break;		//LEVEL 2
			case 21: close_file((int)PATHNAME);          break;
			case 22: pfd();                 break;
			case 23: lseek_file();          break;
			case 24: //access_file();         break;
				break;
			case 25: //read_file();           
				break;
			case 26: write_file();          break;
			case 27: cat_file();            break;
			case 28: cp_file();             break;
			case 29: mv_file();             break;
			case 30: mount();               break;		//LEVLEL 3
			case 31: //umount();              break;
			case 32: //cs();                  break;
			case 33: //do_fork();             break;
			case 34: //do_ps();               break;
			case 40: //sync();                break; 
			case 41: quit();              	 break;
			case 42 : system("clear");	break; 
			default: printf("invalid command\n");
			break;
			
		}

		//RESET NAMES
		strcpy(parameter, "NULL");
		strcpy(pathname, "NULL");
		strcpy(PATHNAME, "NULL");
	}
	
  }