Esempio n. 1
0
bool resolvepath(Stroka &folder, const Stroka &home)
{
    char *ptr = (char*)alloca(+folder + 3 + +home);
    if (resolvepath(ptr, ~folder, ~home)) {
        folder = ptr;
        return true;
    }
    return false;
}
Esempio n. 2
0
/*
 * This function is called when we receive a devfs add event.  This can be
 * either a disk event or a lofi event, and the behavior is slightly different
 * depending on which it is.
 */
static int
zfs_deliver_add(nvlist_t *nvl, boolean_t is_lofi)
{
	char *devpath, *devname;
	char path[PATH_MAX], realpath[PATH_MAX];
	char *colon, *raw;
	int ret;

	/*
	 * The main unit of operation is the physical device path.  For disks,
	 * this is the device node, as all minor nodes are affected.  For lofi
	 * devices, this includes the minor path.  Unfortunately, this isn't
	 * represented in the DEV_PHYS_PATH for various reasons.
	 */
	if (nvlist_lookup_string(nvl, DEV_PHYS_PATH, &devpath) != 0)
		return (-1);

	/*
	 * If this is a lofi device, then also get the minor instance name.
	 * Unfortunately, the current payload doesn't include an easy way to get
	 * this information.  So we cheat by resolving the 'dev_name' (which
	 * refers to the raw device) and taking the portion between ':(*),raw'.
	 */
	(void) strlcpy(realpath, devpath, sizeof (realpath));
	if (is_lofi) {
		if (nvlist_lookup_string(nvl, DEV_NAME,
		    &devname) == 0 &&
		    (ret = resolvepath(devname, path,
		    sizeof (path))) > 0) {
			path[ret] = '\0';
			colon = strchr(path, ':');
			if (colon != NULL)
				raw = strstr(colon + 1, ",raw");
			if (colon != NULL && raw != NULL) {
				*raw = '\0';
				(void) snprintf(realpath,
				    sizeof (realpath), "%s%s",
				    devpath, colon);
				*raw = ',';
			}
		}
	}

	/*
	 * Iterate over all vdevs with a matching devid, and then those with a
	 * matching /devices path.  For disks, we only want to pay attention to
	 * vdevs marked as whole disks.  For lofi, we don't care (because we're
	 * matching an exact minor name).
	 */
	if (!devid_iter(realpath, zfs_process_add, !is_lofi))
		(void) devpath_iter(realpath, zfs_process_add, !is_lofi);

	return (0);
}
Esempio n. 3
0
/*
 * by writing 0x00 0x00 to the end of the first block on a disk, will make
 * the disk unbootable.
 */
static void
nuke_it(char *device, int flag)
{
	int	fd;
	char 	*orig_dev;
//	const char *ln = "/dev/dsk/c0d0s0"; 
	char	buf[2];
	off_t	offset;
	char *devicepath;

	devicepath=malloc(256);
	memset(devicepath,'\0',256);
	
	devicepath=strcat(devicepath,"/dev/dsk/");
	devicepath=strcat(devicepath,(const char *)device);
	fprintf(stderr,"Disk Device is %s\n",devicepath);
	
	orig_dev=malloc(256);
	memset(orig_dev,'\0',256);

	if ( resolvepath(devicepath,orig_dev,256) != 0){
		perror("Could not resolve the device link\n");
	}

//	memset(orig_dev,'\0',256);
//	strcpy(orig_dev,"/devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:q"); 
//	printf("%s\n",orig_dev);

	if ((fd = open(orig_dev, O_WRONLY)) < 0) {
		perror("nuke_it:open failed\n");
		return;
	}

	offset = lseek(fd, 510, SEEK_SET);
//	printf("%d %d\n",flag,UNBOOTABLE);
//	printf("Offset = %d\n",(int)offset);
	if (flag == UNBOOTABLE) {
		buf[0] = 0x00;
		buf[1] = 0x00;
	} else {
		buf[0] = 0x55;
		buf[1] = 0xaa;
	}

	if (write(fd, buf, sizeof(buf)) < 0) {
		perror("nuke_it:write failed");
	}

	close(fd);	
	return;
}
Esempio n. 4
0
/*
 * Create labels for non-anon, non-heap mappings
 */
char *
make_name(struct ps_prochandle *Pr, int lflag, uintptr_t addr,
    const char *mapname, char *buf, size_t bufsz)
{
	const pstatus_t		*Psp = Pstatus(Pr);
	struct stat		statb;
	char			path[PATH_MAX];
	int			len;

	if (lflag || Pstate(Pr) == PS_DEAD) {
		if (Pobjname(Pr, addr, buf, bufsz) != NULL)
			return (buf);
	} else {
		if (Pobjname_resolved(Pr, addr, buf, bufsz) != NULL) {
			/* Verify that the path exists */
			if ((len = resolvepath(buf, buf, bufsz)) > 0) {
				buf[len] = '\0';
				return (buf);
			}
		}
	}

	if (Pstate(Pr) == PS_DEAD || *mapname == '\0')
		return (NULL);

	/* first see if we can find a path via /proc */
	(void) proc_snprintf(path, sizeof (path), "/proc/%d/path/%s",
	    (int)Psp->pr_pid, mapname);
	len = readlink(path, buf, bufsz - 1);
	if (len >= 0) {
		buf[len] = '\0';
		return (buf);
	}

	/* fall back to object information reported by /proc */
	(void) proc_snprintf(path, sizeof (path),
	    "/proc/%d/object/%s", (int)Psp->pr_pid, mapname);
	if (stat(path, &statb) == 0) {
		dev_t dev = statb.st_dev;
		ino_t ino = statb.st_ino;
		(void) snprintf(buf, bufsz, "dev:%lu,%lu ino:%lu",
		    (ulong_t)major(dev), (ulong_t)minor(dev), ino);
		return (buf);
	}

	return (NULL);
}
Esempio n. 5
0
void lsdir(char *o, size_t size, const char *path, int recurse, int want_ctime)
{
	struct jffs2_raw_dirent *dd;
	struct dir *d = NULL;

	uint32_t ino;

	dd = resolvepath(o, size, 1, path, &ino);

	if (ino == 0 ||
			(dd == NULL && ino == 0) || (dd != NULL && dd->type != DT_DIR))
		errmsg_die("%s: No such file or directory", path);

	d = collectdir(o, size, ino, d);
	printdir(o, size, d, path, recurse, want_ctime);
	freedir(d);
}
Esempio n. 6
0
void catfile(char *o, size_t size, char *path, char *b, size_t bsize,
		size_t * rsize)
{
	struct jffs2_raw_dirent *dd;
	struct jffs2_raw_inode *ri;
	uint32_t ino;

	dd = resolvepath(o, size, 1, path, &ino);

	if (ino == 0)
		errmsg_die("%s: No such file or directory", path);

	if (dd == NULL || dd->type != DT_REG)
		errmsg_die("%s: Not a regular file", path);

	ri = find_raw_inode(o, size, ino);
	putblock(b, bsize, rsize, ri);

	write(1, b, *rsize);
}
Esempio n. 7
0
int main (int argc, char **argv)
{
	int n;
	char buf1 [PATH_MAX];
	char buf2 [PATH_MAX];

	for (n = 1; n < argc; n++) {
		memset (buf1, 0, PATH_MAX);
		if (resolvepath (argv [n], buf1, PATH_MAX) == -1)
			err_msg ("resolvepath failed");

		if (realpath (argv [n], buf2) == NULL)
			err_msg ("realpath failed");

		printf ("%s:\n", argv [n]);
		printf ("  resolvepath = %s\n", buf1);
		printf ("  realpath = %s\n\n", buf2);
	}

	return (0);
}
Esempio n. 8
0
extern char*
realpath(const char* file, char* path)
{
    return resolvepath(file, path, PATH_MAX) > 0 ? path : (char*)0;
}
Esempio n. 9
0
bool correctpath(Stroka &folder) {
    return resolvepath(folder, "/");
}
Esempio n. 10
0
glibtop_map_entry *
glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf,	pid_t pid)
{
   	int fd, i, nmaps, pr_err, heap;
#if GLIBTOP_SOLARIS_RELEASE >= 50600
	prxmap_t *maps;
	struct ps_prochandle *Pr = NULL;
#else
	prmap_t *maps;
#endif

	/* A few defines, to make it shorter down there */

#ifdef HAVE_PROCFS_H
# define OFFSET  pr_offset
#else
# define OFFSET  pr_off
#endif

	glibtop_map_entry *entry;
	struct stat inode;
	char buffer[BUFSIZ];

	memset (buf, 0, sizeof (glibtop_proc_map));

#ifdef HAVE_PROCFS_H
	sprintf(buffer, "/proc/%d/xmap", (int)pid);
#else
	sprintf(buffer, "/proc/%d", (int)pid);
#endif
	if((fd = s_open(buffer, O_RDONLY)) < 0)
	{
	   	if (errno != EPERM && errno != EACCES)
		   	glibtop_warn_io_r(server, "open (%s)", buffer);
		return NULL;
	}
#ifdef HAVE_PROCFS_H
	if(fstat(fd, &inode) < 0)
	{
	   	if(errno != EOVERFLOW)
		   	glibtop_warn_io_r(server, "fstat (%s)", buffer);
		/* else call daemon for 64-bit support */
		s_close(fd);
		return NULL;
	}
	maps = g_alloca(inode.st_size);
	nmaps = inode.st_size / sizeof(prxmap_t);
	if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size)
	{
	   	glibtop_warn_io_r(server, "pread (%s)", buffer);
		s_close(fd);
		return NULL;
	}
#else
	if(ioctl(fd, PIOCNMAP, &nmaps) < 0)
	{
	   	glibtop_warn_io_r(server, "ioctl(%s, PIOCNMAP)", buffer);
		s_close(fd);
		return NULL;
	}
	maps = g_alloca((nmaps + 1) * sizeof(prmap_t));
	if(ioctl(fd, PIOCMAP, maps) < 0)
	{
	   	glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer);
		s_close(fd);
		return NULL;
	}
#endif
	buf->number = nmaps;
	buf->size = sizeof(glibtop_map_entry);
	buf->total = nmaps * sizeof(glibtop_map_entry);
	entry = g_malloc0(buf->total);

#if GLIBTOP_SOLARIS_RELEASE >= 50600

	if(server->machine->objname && server->machine->pgrab &&
	   server->machine->pfree)
	   Pr = (server->machine->pgrab)(pid, 1, &pr_err);
#endif
	for(heap = 0,i = 0; i < nmaps; ++i)
	{
	   	int len;

	   	entry[i].start = maps[i].pr_vaddr;
		entry[i].end = maps[i].pr_vaddr + maps[i].pr_size;

#if GLIBTOP_SOLARIS_RELEASE >= 50600

		if(maps[i].pr_dev != PRNODEV)
		{
		   entry[i].device = maps[i].pr_dev;
		   entry[i].inode = maps[i].pr_ino;
		   entry[i].flags |= _glibtop_sysdeps_map_device;
		}
#endif
		entry[i].offset = maps[i].OFFSET;
		if(maps[i].pr_mflags & MA_READ)
		   	entry[i].perm |= GLIBTOP_MAP_PERM_READ;
		if(maps[i].pr_mflags & MA_WRITE){
		   	entry[i].perm |= GLIBTOP_MAP_PERM_WRITE;
		   	entry[i].size = maps[i].pr_size;
		}
		if(maps[i].pr_mflags & MA_EXEC)
		   	entry[i].perm |= GLIBTOP_MAP_PERM_EXECUTE;
		if(maps[i].pr_mflags & MA_SHARED)
		   	entry[i].perm |= GLIBTOP_MAP_PERM_SHARED;
		else
		   	entry[i].perm |= GLIBTOP_MAP_PERM_PRIVATE;
		entry[i].flags = _glibtop_sysdeps_map_entry;

#if GLIBTOP_SOLARIS_RELEASE >= 50600

		if(maps[i].pr_mflags & MA_ANON)
		{
		   if(!heap)
		   {
		      ++heap;
		      strcpy(entry[i].filename, "[ heap ]");
		   }
		   else
		      if(i == nmaps - 1)
			 strcpy(entry[i].filename, "[ stack ]");
		      else
			 strcpy(entry[i].filename, "[ anon ]");
		   entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
		}
		else
		   if(Pr)
		   {
		      server->machine->objname(Pr, maps[i].pr_vaddr, buffer,
					      BUFSIZ);
		      if((len = resolvepath(buffer, entry[i].filename,
					    GLIBTOP_MAP_FILENAME_LEN)) > 0)
		      {
			 entry[i].filename[len] = 0;
			 entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
		      }
		   }
#endif
	}

#if GLIBTOP_SOLARIS_RELEASE >= 50600

	if(Pr)
	   	server->machine->pfree(Pr);
#endif
	buf->flags = _glibtop_sysdeps_proc_map;
	s_close(fd);
	return entry;
}
Esempio n. 11
0
char *
canonicalize_file_name (const char *name)
{
# if HAVE_RESOLVEPATH

  char *resolved, *extra_buf = NULL;
  size_t resolved_size;
  ssize_t resolved_len;

  if (name == NULL)
    {
      __set_errno (EINVAL);
      return NULL;
    }

  if (name[0] == '\0')
    {
      __set_errno (ENOENT);
      return NULL;
    }

  /* All known hosts with resolvepath (e.g. Solaris 7) don't turn
     relative names into absolute ones, so prepend the working
     directory if the file name is not absolute.  */
  if (name[0] != '/')
    {
      char *wd;

      if (!(wd = xgetcwd ()))
	return NULL;

      extra_buf = file_name_concat (wd, name, NULL);
      name = extra_buf;
      free (wd);
    }

  resolved_size = strlen (name);
  while (1)
    {
      resolved_size = 2 * resolved_size + 1;
      resolved = xmalloc (resolved_size);
      resolved_len = resolvepath (name, resolved, resolved_size);
      if (resolved_len < 0)
	{
	  free (resolved);
	  free (extra_buf);
	  return NULL;
	}
      if (resolved_len < resolved_size)
	break;
      free (resolved);
    }

  free (extra_buf);

  /* NUL-terminate the resulting name.  */
  resolved[resolved_len] = '\0';

  return resolved;

# else

  return canonicalize_filename_mode (name, CAN_EXISTING);

# endif /* !HAVE_RESOLVEPATH */
}