Esempio n. 1
0
static int fat_probe(struct device_d *dev)
{
	struct fs_device_d *fsdev = dev_to_fs_device(dev);
	struct fat_priv *priv = xzalloc(sizeof(struct fat_priv));
	char *backingstore = fsdev->backingstore;
	int ret;

	dev->priv = priv;

	if (!strncmp(backingstore , "/dev/", 5))
		backingstore += 5;

	priv->cdev = cdev_open(backingstore, O_RDWR);
	if (!priv->cdev) {
		ret = -ENOENT;
		goto err_open;
	}

	priv->fat.userdata = priv;
	ret = f_mount(&priv->fat);
	if (ret)
		goto err_mount;

	return 0;

err_mount:
	cdev_close(priv->cdev);
err_open:
	free(priv);

	return ret;
}
Esempio n. 2
0
static void fat_remove(struct device_d *dev)
{
	struct fat_priv *priv = dev->priv;

	cdev_close(priv->cdev);

	free(dev->priv);
}
Esempio n. 3
0
int mxs_ocotp_read(void *buf, int count, int offset)
{
	struct cdev *cdev;
	int ret;

	cdev = cdev_open(DRIVERNAME, O_RDONLY);
	if (!cdev)
		return -ENODEV;

	ret = cdev_read(cdev, buf, count, offset, 0);

	cdev_close(cdev);

	return ret;
}
Esempio n. 4
0
static void *read_image_head(const char *name)
{
	void *header = xmalloc(ARM_HEAD_SIZE);
	struct cdev *cdev;
	int ret;

	cdev = cdev_open(name, O_RDONLY);
	if (!cdev) {
		printf("failed to open %s\n", name);
		return NULL;
	}

	ret = cdev_read(cdev, header, ARM_HEAD_SIZE, 0, 0);
	cdev_close(cdev);

	if (ret != ARM_HEAD_SIZE) {
		printf("failed to read from %s\n", name);
		return NULL;
	}

	return header;
}
Esempio n. 5
0
static int do_imx_nand_bbm(int argc, char *argv[])
{
	int opt, ret;
	struct cdev *cdev;
	struct mtd_info *mtd;
	int yes = 0;
	void *bbt;

	while ((opt = getopt(argc, argv, "y")) > 0) {
		switch (opt) {
		case 'y':
			yes = 1;
			break;
		default:
			return COMMAND_ERROR_USAGE;
		}
	}

	cdev = cdev_open("nand0", O_RDWR);
	if (!cdev)
		return -ENOENT;

	mtd = cdev->mtd;
	if (!mtd)
		return -EINVAL;

	if (strcmp(mtd->name, "imx_nand")) {
		printf("This is not an i.MX nand but a %s\n", mtd->name);
		ret = -EINVAL;
		goto out;
	}

	switch (mtd->writesize) {
	case 512:
		printf("writesize is 512. This command is not needed\n");
		ret = 1;
		goto out;
	case 2048:
		break;
	default:
		printf("not implemented for writesize %d\n", mtd->writesize);
		ret = 1;
		goto out;
	}

	bbt = create_bbt(mtd);
	if (IS_ERR(bbt)) {
		ret = 1;
		goto out;
	}

	if (!yes) {
		int c;

		printf("create flash bbt (y/n)?");
		c = getc();
		if (c == 'y')
			yes = 1;
		printf("\n");
	}

	if (!yes) {
		free(bbt);
		ret = 1;

		goto out;
	}

	ret = attach_bbt(mtd, bbt);
	if (!ret)
		printf("bbt successfully added\n");
	else
		free(bbt);

out:
	cdev_close(cdev);

	return ret;
}
Esempio n. 6
0
File: misc.c Progetto: Hooman3/minix
/*===========================================================================*
 *				free_proc				     *
 *===========================================================================*/
static void free_proc(int flags)
{
  int i;
  register struct fproc *rfp;
  register struct filp *rfilp;
  register struct vnode *vp;
  dev_t dev;

  if (fp->fp_endpoint == NONE)
	panic("free_proc: already free");

  if (fp_is_blocked(fp))
	unpause();

  /* Loop on file descriptors, closing any that are open. */
  for (i = 0; i < OPEN_MAX; i++) {
	(void) close_fd(fp, i);
  }

  /* Release root and working directories. */
  if (fp->fp_rd) { put_vnode(fp->fp_rd); fp->fp_rd = NULL; }
  if (fp->fp_wd) { put_vnode(fp->fp_wd); fp->fp_wd = NULL; }

  /* The rest of these actions is only done when processes actually exit. */
  if (!(flags & FP_EXITING)) return;

  fp->fp_flags |= FP_EXITING;

  /* Check if any process is SUSPENDed on this driver.
   * If a driver exits, unmap its entries in the dmap table.
   * (unmapping has to be done after the first step, because the
   * dmap table is used in the first step.)
   */
  unsuspend_by_endpt(fp->fp_endpoint);
  dmap_unmap_by_endpt(fp->fp_endpoint);

  worker_stop_by_endpt(fp->fp_endpoint); /* Unblock waiting threads */
  vmnt_unmap_by_endpt(fp->fp_endpoint); /* Invalidate open files if this
					     * was an active FS */

  /* If a session leader exits and it has a controlling tty, then revoke
   * access to its controlling tty from all other processes using it.
   */
  if ((fp->fp_flags & FP_SESLDR) && fp->fp_tty != 0) {
      dev = fp->fp_tty;
      for (rfp = &fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
	  if(rfp->fp_pid == PID_FREE) continue;
          if (rfp->fp_tty == dev) rfp->fp_tty = 0;

          for (i = 0; i < OPEN_MAX; i++) {
		if ((rfilp = rfp->fp_filp[i]) == NULL) continue;
		if (rfilp->filp_mode == FILP_CLOSED) continue;
		vp = rfilp->filp_vno;
		if (!S_ISCHR(vp->v_mode)) continue;
		if (vp->v_sdev != dev) continue;
		lock_filp(rfilp, VNODE_READ);
		(void) cdev_close(dev); /* Ignore any errors. */
		/* FIXME: missing select check */
		rfilp->filp_mode = FILP_CLOSED;
		unlock_filp(rfilp);
          }
      }
  }

  /* Exit done. Mark slot as free. */
  fp->fp_endpoint = NONE;
  fp->fp_pid = PID_FREE;
  fp->fp_flags = FP_NOFLAGS;
}