Exemplo n.º 1
0
int
sfs_unlink(struct inode *dp, char *name){
  struct inode *ip;
  struct sfs_dirent de;
  uint off;

  vop_ilock(dp);
  // Cannot unlink "." or "..".
  if(namecmp(name, ".") == 0 || namecmp(name, "..") == 0)
    goto bad;

  if((ip = vop_dirlookup(dp, name, &off)) == 0)
    goto bad;
  vop_ilock(ip);

  if(vop_getnlink(ip) < 1)
    panic("unlink: nlink < 1");
  if(vop_gettype(ip) == T_DIR && !vop_isdirempty(ip)){
    vop_iunlockput(ip);
    goto bad;
  }

  memset(&de, 0, sizeof(de));
  if(vop_write(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
    panic("unlink: writei");
  if(vop_gettype(ip) == T_DIR){
    vop_link_dec(dp);
    vop_iupdate(dp);
  }
  vop_iunlockput(dp);

  vop_link_dec(ip);
  vop_iupdate(ip);
  vop_iunlockput(ip);
  return 0;

  bad:
    vop_iunlockput(dp);
    return -1;
}
Exemplo n.º 2
0
int file_write(int fd, void *base, size_t len, size_t * copied_store)
{
	int ret;
	struct file *file;
	*copied_store = 0;
	if ((ret = fd2file(fd, &file)) != 0) {
		return ret;
	}
	if (!file->writable) {
		return -E_INVAL;
	}
	filemap_acquire(file);

	struct iobuf __iob, *iob = iobuf_init(&__iob, base, len, file->pos);
	ret = vop_write(file->node, iob, file->io_flags);

	size_t copied = iobuf_used(iob);
	file->pos += copied;
	*copied_store = copied;
	filemap_release(file);
	return ret;
}
Exemplo n.º 3
0
// write file
int
file_write(int fd, void *base, size_t len, size_t *copied_store) {
    int ret;
    struct file *file;
    *copied_store = 0;
    if ((ret = fd2file(fd, &file)) != 0) {
        return ret;
    }
    if (!file->writable) {
        return -E_INVAL;
    }
    fd_array_acquire(file);

    struct iobuf __iob, *iob = iobuf_init(&__iob, base, len, file->pos);
    ret = vop_write(file->node, iob);

    size_t copied = iobuf_used(iob);
    if (file->status == FD_OPENED) {
        file->pos += copied;
    }
    *copied_store = copied;
    fd_array_release(file);
    return ret;
}