Пример #1
0
/* The user must define this function.  Read from the locked file NP
   for user CRED starting at OFFSET and continuing for up to *LEN
   bytes.  Put the data at DATA.  Set *LEN to the amount successfully
   read upon return.  */
error_t netfs_attempt_read (struct iouser *cred, struct node *np,
			    loff_t offset, size_t *len, void *data)
{
  char *contents;
  ssize_t contents_len;
  error_t err;

  if (offset == 0)
    procfs_refresh (np);

  err = procfs_get_contents (np, &contents, &contents_len);
  if (err)
    return err;

  contents += offset;
  contents_len -= offset;

  if (*len > contents_len)
    *len = contents_len;
  if (*len < 0)
    *len = 0;

  memcpy (data, contents, *len);
  return 0;
}
Пример #2
0
void procfs_cleanup (struct node *np)
{
  procfs_refresh (np);

  if (np->nn->ops->cleanup)
    np->nn->ops->cleanup (np->nn->hook);

  if (np->nn->parent)
    netfs_nrele (np->nn->parent);

  free (np->nn);
}
Пример #3
0
/* The user must define this function.  Fill the array *DATA of size
   BUFSIZE with up to NENTRIES dirents from DIR (which is locked)
   starting with entry ENTRY for user CRED.  The number of entries in
   the array is stored in *AMT and the number of bytes in *DATACNT.
   If the supplied buffer is not large enough to hold the data, it
   should be grown.  */
error_t netfs_get_dirents (struct iouser *cred, struct node *dir,
                           int entry, int nentries, char **data,
			   mach_msg_type_number_t *datacnt,
			   vm_size_t bufsize, int *amt)
{
  char *contents;
  ssize_t contents_len;
  error_t err;

  if (entry == 0)
    procfs_refresh (dir);
 
  err = procfs_get_contents (dir, &contents, &contents_len);
  if (err)
    return err;

  /* We depend on the fact that CONTENTS is terminated. */
  assert (contents_len == 0 || contents[contents_len - 1] == '\0');

  /* Skip to the first requested entry. */
  while (contents_len && entry--)
    {
      int ofs = strlen (contents) + 1;
      contents += ofs;
      contents_len -= ofs;
    }

  /* Allocate a buffer if necessary. */
  putentries (contents, contents_len, nentries, NULL, datacnt);
  if (bufsize < *datacnt)
    {
      char *n = mmap (0, *datacnt, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, 0, 0);
      if (n == MAP_FAILED)
	return ENOMEM;

      *data = n;
    }

  /* Do the actual conversion. */
  *amt = putentries (contents, contents_len, nentries, *data, datacnt);

  return 0;
}