コード例 #1
0
ファイル: verify.c プロジェクト: Hooman3/minix
/*===========================================================================*
 *				verify_dentry				     *
 *===========================================================================*/
int verify_dentry(
	struct inode *parent, 	/* parent inode: the inode to verify */
	char name[NAME_MAX+1],	/* the given directory entry path component */
	char path[PATH_MAX],  	/* buffer to store the resulting path in */
	struct inode **res_ino	/* pointer for addressed inode (or NULL) */
)
{
/* Given a directory inode and a name, construct a path identifying that
 * directory entry, check whether the path to the parent is still valid, and
 * check whether there is an inode pointed to by the full path. Upon success,
 * res_ino will contain either the inode for the full path, with increased
 * refcount, or NULL if no such inode exists.
 */
  int r;

  if ((r = verify_inode(parent, path, NULL)) != OK)
	return r;

  dprintf(("%s: verify_dentry: given path is '%s', name '%s'\n",
	sffs_name, path, name));

  if ((r = push_path(path, name)) != OK)
	return r;

  dprintf(("%s: verify_dentry: path now '%s'\n", sffs_name, path));

  *res_ino = lookup_dentry(parent, name);

  return OK;
}
コード例 #2
0
ファイル: pass1.c プロジェクト: AlainODea/illumos-gate
void
pass1(void)
{
	uint_t c, i;
	daddr32_t cgd;
	struct inodesc idesc;
	fsck_ino_t inumber;
	fsck_ino_t maxinumber;

	/*
	 * Set file system reserved blocks in used block map.
	 */
	for (c = 0; c < sblock.fs_ncg; c++) {
		cgd = cgdmin(&sblock, c);
		if (c == 0) {
			/*
			 * Doing the first cylinder group, account for
			 * the cg summaries as well.
			 */
			i = cgbase(&sblock, c);
			cgd += howmany(sblock.fs_cssize, sblock.fs_fsize);
		} else {
			i = cgsblock(&sblock, c);
		}
		for (; i < cgd; i++) {
			note_used(i);
		}
	}
	/*
	 * Note blocks being used by the log, so we don't declare
	 * them as available and some time in the future we get a
	 * freeing free block panic.
	 */
	if (islog && islogok && sblock.fs_logbno)
		examinelog(&note_used);

	/*
	 * Find all allocated blocks.  This must be completed before
	 * we read the contents of any directories, as dirscan() et al
	 * don't want to know about block allocation holes.  So, part
	 * of this pass is to truncate any directories with holes to
	 * just before those holes, so dirscan() can remain blissfully
	 * ignorant.
	 */
	inumber = 0;
	n_files = n_blks = 0;
	resetinodebuf();
	maxinumber = sblock.fs_ncg * sblock.fs_ipg;
	for (c = 0; c < sblock.fs_ncg; c++) {
		for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
			if (inumber < UFSROOTINO)
				continue;
			init_inodesc(&idesc);
			idesc.id_type = ADDR;
			idesc.id_func = pass1check;
			verify_inode(inumber, &idesc, maxinumber);
		}
	}
	freeinodebuf();
}
コード例 #3
0
ファイル: mount.c プロジェクト: DragonQuan/minix3
/*===========================================================================*
 *				do_readsuper				     *
 *===========================================================================*/
PUBLIC int do_readsuper()
{
/* Mount the file system.
 */
  char path[PATH_MAX];
  struct inode *ino;
  struct hgfs_attr attr;
  int r;

  dprintf(("HGFS: readsuper (dev %x, flags %x)\n",
	(dev_t) m_in.REQ_DEV, m_in.REQ_FLAGS));

  if (m_in.REQ_FLAGS & REQ_ISROOT) {
	printf("HGFS: attempt to mount as root device\n");

	return EINVAL;
  }

  state.read_only = !!(m_in.REQ_FLAGS & REQ_RDONLY);
  state.dev = m_in.REQ_DEV;

  init_dentry();
  ino = init_inode();

  attr.a_mask = HGFS_ATTR_MODE | HGFS_ATTR_SIZE;

  /* We cannot continue if we fail to get the properties of the root inode at
   * all, because we cannot guess the details of the root node to return to
   * VFS. Print a (hopefully) helpful error message, and abort the mount.
   */
  if ((r = verify_inode(ino, path, &attr)) != OK) {
	if (r == EAGAIN)
		printf("HGFS: shared folders disabled\n");
	else if (opt.prefix[0] && (r == ENOENT || r == EACCES))
		printf("HGFS: unable to access the given prefix directory\n");
	else
		printf("HGFS: unable to access shared folders\n");

	return r;
  }

  m_out.RES_INODE_NR = INODE_NR(ino);
  m_out.RES_MODE = get_mode(ino, attr.a_mode);
  m_out.RES_FILE_SIZE_HI = ex64hi(attr.a_size);
  m_out.RES_FILE_SIZE_LO = ex64lo(attr.a_size);
  m_out.RES_UID = opt.uid;
  m_out.RES_GID = opt.gid;
  m_out.RES_DEV = NO_DEV;

  m_out.RES_CONREQS = 1;	/* We can handle only 1 request at a time */

  state.mounted = TRUE;

  return OK;
}
コード例 #4
0
ファイル: lookup.c プロジェクト: Hooman3/minix
/*===========================================================================*
 *				do_lookup				     *
 *===========================================================================*/
int do_lookup(ino_t dir_nr, char *name, struct fsdriver_node *node,
	int *is_mountpt)
{
/* Resolve a path string to an inode.
 */
  struct inode *dir_ino, *ino;
  struct sffs_attr attr;
  char path[PATH_MAX];
  int r;

  dprintf(("%s: lookup: got query for %"PRIu64", '%s'\n",
	sffs_name, dir_nr, name));

  if ((dir_ino = find_inode(dir_nr)) == NULL)
	return EINVAL;

  attr.a_mask = SFFS_ATTR_MODE | SFFS_ATTR_SIZE;

  if ((r = verify_inode(dir_ino, path, &attr)) != OK)
	return r;

  if (!IS_DIR(dir_ino))
	return ENOTDIR;

  r = OK;
  if (!strcmp(name, "."))
	get_inode(ino = dir_ino);
  else if (!strcmp(name, ".."))
	r = go_up(path, dir_ino, &ino, &attr);
  else
	r = go_down(path, dir_ino, name, &ino, &attr);

  if (r != OK)
	return r;

  node->fn_ino_nr = INODE_NR(ino);
  node->fn_mode = get_mode(ino, attr.a_mode);
  node->fn_size = attr.a_size;
  node->fn_uid = sffs_params->p_uid;
  node->fn_gid = sffs_params->p_gid;
  node->fn_dev = NO_DEV;

  *is_mountpt = FALSE;

  return OK;
}
コード例 #5
0
/*===========================================================================*
 *				do_trunc				     *
 *===========================================================================*/
int do_trunc(ino_t ino_nr, off_t start, off_t end)
{
/* Change file size or create file holes.
 */
  char path[PATH_MAX];
  struct inode *ino;
  struct sffs_attr attr;
  uint64_t delta;
  ssize_t r;

  if (state.s_read_only)
	return EROFS;

  if ((ino = find_inode(ino_nr)) == NULL)
	return EINVAL;

  if (IS_DIR(ino)) return EISDIR;

  if (end == 0) {
	/* Truncate or expand the file. */
	if ((r = verify_inode(ino, path, NULL)) != OK)
		return r;

	attr.a_mask = SFFS_ATTR_SIZE;
	attr.a_size = start;

	r = sffs_table->t_setattr(path, &attr);
  } else {
	/* Write zeroes to the file. We can't create holes. */
	if (end <= start) return EINVAL;

	delta = (uint64_t)end - (uint64_t)start;

	if (delta > SSIZE_MAX) return EINVAL;

	if ((r = write_file(ino, start, (size_t)delta, NULL)) >= 0)
		r = OK;
  }

  return r;
}
コード例 #6
0
ファイル: get_it_i_say.c プロジェクト: Lakshmipathi/giis
int get_it ()
{
  int i, fd, no = 0;
  static int search_uid;
  search_uid = 0;
//Added for giis4.0
  char extension[10];
  int glength = 0, ulength = 0, pos, count, typefound;

  if (use_uid == 2)
  {
    i = force_giis ();
    if (i == -1)
    {
      perror ("");
      printf ("Error Number:%d", errno);
      return -1;
    }
    return 1;
  }

  if (use_uid == 1)
  {
    printf ("\n Enter the User Name....");
    scanf ("%s", user);
    pwfile = getpwnam (user);
    if (pwfile == NULL)
    {
      printf ("\nPlease Enter Correct user name ");
      return 1;
    }
    use_uid = pwfile->pw_uid;
    printf ("\nSearching For %s files with uid=%d", pwfile->pw_name, use_uid);
    search_uid = 1;             /* Search for specific users */
  }
  /* Get by File format */
  if (use_uid == 3)
  {
    printf ("\n Enter any file type:(txt,doc,mp3,c,cpp,dat--etc) :");
    scanf ("%s", extension);
    search_format = 1;
  }


  /* Reset offset of two files */

  d_offy = 0;
  s_offy = 0;


  fd = open (FILE_INFO_FILE, 2);
  if (fd == -1)
  {
    perror ("open");
    return -1;
  }

  i = read (fd, giis_f.buffer, GIIS_FSIZE);
  if (i == -1)
  {
    perror ("");
    printf ("Error Number:%d", errno);
    return -1;
  }
  while (i > 0)
  {
    /* Search for given file formats only */
    if (search_format == 1)
    {
      glength = 0;
      ulength = 0;
      glength = strlen (giis_f.info.name);
      ulength = strlen (extension);
      ulength++;                //get dot part too .txt /.cpp
      pos = glength - ulength;
      if (giis_f.info.name[pos] == '.')
      {
        pos++;
        count = 0;
        typefound = 1;
        for (; pos < glength; pos++, count++)
        {
          if (giis_f.info.name[pos] != extension[count])
          {
            typefound = 0;
            pos = glength;
          }
        }
        if (typefound)
        {

          i = verify_inode (giis_f.info.inode_number);
          if (i == -1)
          {
            perror ("");
            printf ("Error Number:%d", errno);
            return -1;
          }
        }
        else
          i = 0;
      }
    }

    /* Specific user is set and this is his entry then verfify else skip.
       If use_uid not set search for all files ignore uid */
    if (search_uid)
    {

      if (giis_f.info.owner == use_uid)
      {
        i = verify_inode (giis_f.info.inode_number);
        if (i == -1)
        {
          perror ("");
          printf ("Error Number:%d", errno);
          return -1;
        }
      }
      else
        i = 0;
    }
    if ((search_format != 1) && (!search_uid))
    {
      i = verify_inode (giis_f.info.inode_number);
      if (i == -1)
      {
        perror ("");
        printf ("Error Number:%d", errno);
        return -1;
      }
    }
    /* Update s_offy and d_offy here */

    if (giis_f.info.is_offset)
      s_offy += giis_f.info.is_offset;


    if (giis_f.info.id_offset)
      d_offy += giis_f.info.id_offset;


    if (i == 1)
    {

      get_it_i_say ();

      /* Finally update this entry in file_info_file() */

      giis_f.info.search_flag = 1;      /* Recovered or failed */
      lseek (fd, -GIIS_FSIZE, 1);
      i = write (fd, giis_f.buffer, GIIS_FSIZE);
      if (i != GIIS_FSIZE)
      {
        perror ("write");
        return -1;
      }
      no = 1;
    }
    i = read (fd, giis_f.buffer, GIIS_FSIZE);
    if (i == -1)
    {
      perror ("");
      printf ("Error Number:%d", errno);
      return -1;
    }
  }
  if (no == 1)
  {
    printf ("\n\n giis process Completed...");
    printf ("\n\t Recovered files   : /usr/share/giis/got_it");
    printf ("\n\t Unrecovered files : /usr/share/giis/unrecovered");
  }
  else
    printf ("\n\n\t\tNothing Recovered...");
  close (fd);
  return 1;
}