当前位置: 首页>>代码示例>>C++>>正文


C++ do_truncate函数代码示例

本文整理汇总了C++中do_truncate函数的典型用法代码示例。如果您正苦于以下问题:C++ do_truncate函数的具体用法?C++ do_truncate怎么用?C++ do_truncate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了do_truncate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: set_runlog_func

static int
set_runlog_func(
        struct rldb_plugin_cnts *cdata,
        int total_entries,
        struct run_entry *entries)
{
  struct rldb_file_cnts *cs = (struct rldb_file_cnts*) cdata;
  struct runlog_state *rls = cs->rl_state;
  int i;
  size_t size;

  if (total_entries > rls->run_a) {
    if (!rls->run_a) rls->run_a = 128;
    xfree(rls->runs);
    while (total_entries > rls->run_a) rls->run_a *= 2;
    XCALLOC(rls->runs, rls->run_a);
  } else {
    XMEMZERO(rls->runs, rls->run_a);
  }
  for (i = 0; i < rls->run_a; ++i)
    rls->runs[i].status = RUN_EMPTY;
  rls->run_u = total_entries;
  size = rls->run_u * sizeof(rls->runs[0]);
  if (rls->run_u > 0) memcpy(rls->runs, entries, size);
  sf_lseek(cs->run_fd, sizeof(struct run_header), SEEK_SET, "run");
  do_write(cs->run_fd, rls->runs, size);
  if (do_truncate(cs) < 0) return -1;
  return 0;
}
开发者ID:NUOG,项目名称:ejudge,代码行数:29,代码来源:rldb_plugin_file.c

示例2: do_sys_truncate

static inline long do_sys_truncate(const char * path, loff_t length)
{
    struct nameidata nd;
    struct inode * inode;
    int error;

    error = -EINVAL;
    if (length < 0)	/* sorry, but loff_t says... */
        goto out;

    error = user_path_walk(path, &nd);
    if (error)
        goto out;
    inode = nd.dentry->d_inode;

    /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
    error = -EISDIR;
    if (S_ISDIR(inode->i_mode))
        goto dput_and_out;

    error = -EINVAL;
    if (!S_ISREG(inode->i_mode))
        goto dput_and_out;

    error = permission(inode,MAY_WRITE);
    if (error)
        goto dput_and_out;

    error = -EROFS;
    if (IS_RDONLY(inode))
        goto dput_and_out;

    error = -EPERM;
    if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
        goto dput_and_out;

    /*
     * Make sure that there are no leases.
     */
    error = get_lease(inode, FMODE_WRITE);
    if (error)
        goto dput_and_out;

    error = get_write_access(inode);
    if (error)
        goto dput_and_out;

    error = locks_verify_truncate(inode, NULL, length);
    if (!error)
    {
        DQUOT_INIT(inode);
        error = do_truncate(nd.dentry, length);
    }
    put_write_access(inode);

dput_and_out:
    path_release(&nd);
out:
    return error;
}
开发者ID:rroart,项目名称:freevms,代码行数:60,代码来源:open.c

示例3: vfsub_trunc

/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
		struct file *h_file)
{
	int err;
	struct inode *h_inode;
	struct super_block *h_sb;

	if (!h_file) {
		err = vfsub_truncate(h_path, length);
		goto out;
	}

	h_inode = h_path->dentry->d_inode;
	h_sb = h_inode->i_sb;
	lockdep_off();
	sb_start_write(h_sb);
	lockdep_on();
	err = locks_verify_truncate(h_inode, h_file, length);
	if (!err)
		err = security_path_truncate(h_path);
	if (!err) {
		lockdep_off();
		err = do_truncate(h_path->dentry, length, attr, h_file);
		lockdep_on();
	}
	lockdep_off();
	sb_end_write(h_sb);
	lockdep_on();

out:
	return err;
}
开发者ID:rice-american,项目名称:abuilds,代码行数:33,代码来源:vfsub.c

示例4: do_sys_ftruncate

static inline long do_sys_ftruncate(unsigned int fd, loff_t length)
{
	struct inode * inode;
	struct dentry *dentry;
	struct file * file;
	int error;

	error = -EINVAL;
	if (length < 0)
		goto out;
	error = -EBADF;
	file = fget(fd);
	if (!file)
		goto out;
	dentry = file->f_dentry;
	inode = dentry->d_inode;
	error = -EACCES;
	if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE))
		goto out_putf;
	error = -EPERM;
	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
		goto out_putf;

	error = locks_verify_truncate(inode, file, length);
	if (!error)
		error = do_truncate(dentry, length);
out_putf:
	fput(file);
out:
	return error;
}
开发者ID:EmbolismSoil,项目名称:Linux-2.4.0-,代码行数:31,代码来源:open.c

示例5: sys_truncate

int sys_truncate(char *path, loff_t length)
{
    struct inode *inode;
    register struct inode *inodep;
    int error;

    error = namei(path, &inode, NOT_DIR, MAY_WRITE);
    inodep = inode;
    if (error)
	return error;
    if (IS_RDONLY(inodep)) {
	iput(inodep);
	return -EROFS;
    }
#ifdef BLOAT_FS
    error = get_write_access(inodep);
    if (error) {
	iput(inodep);
	return error;
    }
#endif
    error = do_truncate(inodep, length);
    put_write_access(inodep);
    iput(inodep);
    return error;
}
开发者ID:Edwin-Edward,项目名称:elks,代码行数:26,代码来源:open.c

示例6: do_sys_truncate

static long do_sys_truncate(const char __user *pathname, loff_t length)
{
	struct path path;
	struct inode *inode;
	int error;

	error = -EINVAL;
	if (length < 0)	
		goto out;

	error = user_path(pathname, &path);
	if (error)
		goto out;
	inode = path.dentry->d_inode;

	
	error = -EISDIR;
	if (S_ISDIR(inode->i_mode))
		goto dput_and_out;

	error = -EINVAL;
	if (!S_ISREG(inode->i_mode))
		goto dput_and_out;

	error = mnt_want_write(path.mnt);
	if (error)
		goto dput_and_out;

	error = inode_permission(inode, MAY_WRITE);
	if (error)
		goto mnt_drop_write_and_out;

	error = -EPERM;
	if (IS_APPEND(inode))
		goto mnt_drop_write_and_out;

	error = get_write_access(inode);
	if (error)
		goto mnt_drop_write_and_out;

	error = break_lease(inode, O_WRONLY);
	if (error)
		goto put_write_and_out;

	error = locks_verify_truncate(inode, NULL, length);
	if (!error)
		error = security_path_truncate(&path);
	if (!error)
		error = do_truncate(path.dentry, length, 0, NULL);

put_write_and_out:
	put_write_access(inode);
mnt_drop_write_and_out:
	mnt_drop_write(path.mnt);
dput_and_out:
	path_put(&path);
out:
	return error;
}
开发者ID:kuzetsa,项目名称:B1RB_htc_msm8974,代码行数:59,代码来源:open.c

示例7: squeeze_func

static int
squeeze_func(struct rldb_plugin_cnts *cdata)
{
  struct rldb_file_cnts *cs = (struct rldb_file_cnts*) cdata;
  struct runlog_state *rls = cs->rl_state;

  int i, j, retval, first_moved = -1, w;
  unsigned char *ptr;
  size_t tot;

  for (i = 0, j = 0; i < rls->run_u; i++) {
    if (rls->runs[i].status == RUN_EMPTY) continue;
    if (i != j) {
      if (first_moved < 0) first_moved = j;
      memcpy(&rls->runs[j], &rls->runs[i], sizeof(rls->runs[j]));
      rls->runs[j].run_id = j;
    }
    j++;
  }
  if  (rls->run_u == j) {
    // no runs were removed
    ASSERT(first_moved == -1);
    return 0;
  }

  retval = rls->run_u - j;
  rls->run_u = j;
  if (rls->run_u < rls->run_a) {
    memset(&rls->runs[rls->run_u], 0,
           (rls->run_a - rls->run_u) * sizeof(rls->runs[0]));
  }

  // update log on disk
  if (do_truncate(cs) < 0) return -1;
  if (first_moved == -1) {
    // no entries were moved because the only entries empty were the last
    return retval;
  }
  ASSERT(first_moved >= 0 && first_moved < rls->run_u);
  if (sf_lseek(cs->run_fd,
               sizeof(rls->head) + first_moved * sizeof(rls->runs[0]),
               SEEK_SET, "run") == (off_t) -1)
    return -1;
  tot = (rls->run_u - first_moved) * sizeof(rls->runs[0]);
  ptr = (unsigned char *) &rls->runs[first_moved];
  while (tot > 0) {
    w = write(cs->run_fd, ptr, tot);
    if (w <= 0) {
      err("run_squeeze_log: write error: %s", os_ErrorMsg());
      return -1;
    }
    tot -= w;
    ptr += w;
  }
  return retval;
}
开发者ID:NUOG,项目名称:ejudge,代码行数:56,代码来源:rldb_plugin_file.c

示例8: ghostfs_truncate

int ghostfs_truncate(struct ghostfs *gfs, const char *path, off_t new_size)
{
	struct dir_iter it;
	int ret;

	ret = dir_iter_lookup(gfs, &it, path, false);
	if (ret < 0)
		return ret;

	return do_truncate(gfs, &it, new_size);
}
开发者ID:mukadr,项目名称:ghostfs,代码行数:11,代码来源:fs.c

示例9: return

/*
 * shmem_file_setup - get an unlinked file living in tmpfs
 *
 * @name: name for dentry (to be seen in /proc/<pid>/maps
 * @size: size to be set for the file
 *
 */
struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
{
	int error;
	struct file *file;
	struct inode *inode;
	struct dentry *dentry, *root;
	struct qstr this;

	if (IS_ERR(shm_mnt))
		return (void *)shm_mnt;

	error = -ENOMEM;
	this.name = name;
	this.len = strlen(name);
	this.hash = 0; /* will go */
	root = shm_mnt->mnt_root;
	dentry = d_alloc(root, &this);
	if (!dentry)
		goto put_memory;

	error = -ENFILE;
	file = get_empty_filp();
	if (!file)
		goto put_dentry;

	error = -ENOSPC;
	inode = ramfs_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0);
	if (!inode)
		goto close_file;

	d_instantiate(dentry, inode);
	inode->i_nlink = 0;	/* It is unlinked */

	file->f_path.mnt = mntget(shm_mnt);
	file->f_path.dentry = dentry;
	file->f_mapping = inode->i_mapping;
	file->f_op = &ramfs_file_operations;
	file->f_mode = FMODE_WRITE | FMODE_READ;

	/* notify everyone as to the change of file size */
	error = do_truncate(dentry, size, 0, file);
	if (error < 0)
		goto close_file;

	return file;

close_file:
	put_filp(file);
put_dentry:
	dput(dentry);
put_memory:
	return ERR_PTR(error);
}
开发者ID:3sOx,项目名称:asuswrt-merlin,代码行数:60,代码来源:tiny-shmem.c

示例10: vfs_truncate

long vfs_truncate(struct path *path, loff_t length)
{
	struct inode *inode;
	long error;

	inode = path->dentry->d_inode;

	/* For directories it's -EISDIR, for other non-regulars - -EINVAL */
	if (S_ISDIR(inode->i_mode))
		return -EISDIR;
	if (!S_ISREG(inode->i_mode))
		return -EINVAL;

	error = mnt_want_write(path->mnt);
	if (error)
		goto out;

	error = inode_permission(inode, MAY_WRITE);
	if (error)
		goto mnt_drop_write_and_out;

	error = -EPERM;
	if (IS_APPEND(inode))
		goto mnt_drop_write_and_out;

	error = get_write_access(inode);
	if (error)
		goto mnt_drop_write_and_out;

	/*
	 * Make sure that there are no leases.  get_write_access() protects
	 * against the truncate racing with a lease-granting setlease().
	 */
	error = break_lease(inode, O_WRONLY);
	if (error)
		goto put_write_and_out;

	error = locks_verify_truncate(inode, NULL, length);
	if (!error)
		error = security_path_truncate(path, length, 0);
	if (!error) {
		vfs_dq_init(inode);
		error = do_truncate(path->dentry, length, 0, NULL);
	}

put_write_and_out:
	put_write_access(inode);
mnt_drop_write_and_out:
	mnt_drop_write(path->mnt);
out:
	return error;
}
开发者ID:3null,项目名称:fastsocket,代码行数:52,代码来源:open.c

示例11: sys_ftruncate

int sys_ftruncate(unsigned int fd, loff_t length)
{
    register struct inode *inode;
    register struct file *file;

    if (fd >= NR_OPEN || !(file = current->files.fd[fd]))
	return -EBADF;
    if (!(inode = file->f_inode))
	return -ENOENT;
    if (S_ISDIR(inode->i_mode) || !(file->f_mode & FMODE_WRITE))
	return -EACCES;
    return do_truncate(inode, length);
}
开发者ID:Edwin-Edward,项目名称:elks,代码行数:13,代码来源:open.c

示例12: ghostfs_write

int ghostfs_write(struct ghostfs *gfs, struct ghostfs_entry *gentry, const char *buf,
		  size_t size, off_t offset)
{
	struct dir_entry *entry = gentry->it.entry;
	struct cluster *c;
	int ret;
	int written = 0;

	if (offset < 0)
		return -EINVAL;

	if (size + offset < size)
		return -EOVERFLOW;

	if (entry->size < offset + size) {
		ret = do_truncate(gfs, &gentry->it, offset + size);
		if (ret < 0)
			return ret;
	}

	ret = cluster_at(gfs, entry->cluster, offset/CLUSTER_DATA, &c);
	if (ret < 0)
		return ret;

	offset %= CLUSTER_DATA;

	for (;;) {
		int w = min(size, CLUSTER_DATA);
		if (offset + w > CLUSTER_DATA)
			w -= (offset + w) - CLUSTER_DATA;

		memcpy(c->data + offset, buf, w);
		cluster_set_dirty(c, true);

		size -= w;
		buf += w;
		written += w;
		offset = 0;

		if (!size)
			break;

		ret = cluster_get_next(gfs, &c);
		if (ret < 0)
			return ret;
	}

	return written;
}
开发者ID:mukadr,项目名称:ghostfs,代码行数:49,代码来源:fs.c

示例13: do_sys_ftruncate

static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
{
	struct inode * inode;
	struct dentry *dentry;
	struct file * file;
	int error;

	error = -EINVAL;
	if (length < 0)
		goto out;
	error = -EBADF;
	file = fget(fd);
	if (!file)
		goto out;

	/* explicitly opened as large or we are on 64-bit box */
	if (file->f_flags & O_LARGEFILE)
		small = 0;

	dentry = file->f_path.dentry;
	inode = dentry->d_inode;
	error = -EINVAL;
	if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE))
		goto out_putf;

	error = -EINVAL;
	/* Cannot ftruncate over 2^31 bytes without large file support */
	if (small && length > MAX_NON_LFS)
		goto out_putf;

	error = -EPERM;
	if (IS_APPEND(inode))
		goto out_putf;

	sb_start_write(inode->i_sb);
	error = locks_verify_truncate(inode, file, length);
	if (!error)
		error = security_path_truncate(&file->f_path, length,
					       ATTR_MTIME|ATTR_CTIME);
	if (!error)
		error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
	sb_end_write(inode->i_sb);
out_putf:
	fput(file);
out:
	return error;
}
开发者ID:3null,项目名称:fastsocket,代码行数:47,代码来源:open.c

示例14: do_sys_ftruncate

static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
{
	struct inode *inode;
	struct dentry *dentry;
	struct fd f;
	int error;

	error = -EINVAL;
	if (length < 0)
		goto out;
	error = -EBADF;
	f = fdget(fd);
	if (!f.file)
		goto out;

	
	if (f.file->f_flags & O_LARGEFILE)
		small = 0;

	dentry = f.file->f_path.dentry;
	inode = dentry->d_inode;
	error = -EINVAL;
	if (!S_ISREG(inode->i_mode) || !(f.file->f_mode & FMODE_WRITE))
		goto out_putf;

	error = -EINVAL;
	
	if (small && length > MAX_NON_LFS)
		goto out_putf;

	error = -EPERM;
	if (IS_APPEND(inode))
		goto out_putf;

	sb_start_write(inode->i_sb);
	error = locks_verify_truncate(inode, f.file, length);
	if (!error)
		error = security_path_truncate(&f.file->f_path);
	if (!error)
		error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
	sb_end_write(inode->i_sb);
out_putf:
	fdput(f);
out:
	return error;
}
开发者ID:Clumsy-Kernel-Development,项目名称:M9_Kernel,代码行数:46,代码来源:open.c

示例15: vfs_truncate

long vfs_truncate(struct path *path, loff_t length)
{
	struct inode *inode;
	long error;

	inode = path->dentry->d_inode;

	
	if (S_ISDIR(inode->i_mode))
		return -EISDIR;
	if (!S_ISREG(inode->i_mode))
		return -EINVAL;

	error = mnt_want_write(path->mnt);
	if (error)
		goto out;

	error = inode_permission(inode, MAY_WRITE);
	if (error)
		goto mnt_drop_write_and_out;

	error = -EPERM;
	if (IS_APPEND(inode))
		goto mnt_drop_write_and_out;

	error = get_write_access(inode);
	if (error)
		goto mnt_drop_write_and_out;

	error = break_lease(inode, O_WRONLY);
	if (error)
		goto put_write_and_out;

	error = locks_verify_truncate(inode, NULL, length);
	if (!error)
		error = security_path_truncate(path);
	if (!error)
		error = do_truncate(path->dentry, length, 0, NULL);

put_write_and_out:
	put_write_access(inode);
mnt_drop_write_and_out:
	mnt_drop_write(path->mnt);
out:
	return error;
}
开发者ID:Clumsy-Kernel-Development,项目名称:M9_Kernel,代码行数:46,代码来源:open.c


注:本文中的do_truncate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。