-static int l_filldir(void *__buf, const char *name, int namlen, loff_t offset,
- u64 ino, unsigned int d_type)
-{
- struct l_linux_dirent *dirent;
- struct l_readdir_callback *buf = (struct l_readdir_callback *)__buf;
-
- dirent = buf->lrc_dirent;
- if (dirent)
- dirent->lld_off = offset;
-
- OBD_ALLOC(dirent, sizeof(*dirent));
-
- if (!dirent)
- return -ENOMEM;
-
- cfs_list_add_tail(&dirent->lld_list, buf->lrc_list);
-
- buf->lrc_dirent = dirent;
- dirent->lld_ino = ino;
- LASSERT(sizeof(dirent->lld_name) >= namlen + 1);
- memcpy(dirent->lld_name, name, namlen);
-
- return 0;
-}
-
-long l_readdir(struct file *file, cfs_list_t *dentry_list)
-{
- struct l_linux_dirent *lastdirent;
- struct l_readdir_callback buf;
- int error;
-
- buf.lrc_dirent = NULL;
- buf.lrc_list = dentry_list;
-
- error = vfs_readdir(file, l_filldir, &buf);
- if (error < 0)
- return error;
-
- lastdirent = buf.lrc_dirent;
- if (lastdirent)
- lastdirent->lld_off = file->f_pos;
-
- return 0;
-}
-EXPORT_SYMBOL(l_readdir);
-
-int l_notify_change(struct vfsmount *mnt, struct dentry *dchild,
- struct iattr *newattrs)
-{
- int rc;
-
- mutex_lock(&dchild->d_inode->i_mutex);
-#ifdef HAVE_SECURITY_PLUG
- rc = notify_change(dchild, mnt, newattrs);
-#else
- rc = notify_change(dchild, newattrs);
-#endif
- mutex_unlock(&dchild->d_inode->i_mutex);
- return rc;
-}
-EXPORT_SYMBOL(l_notify_change);
-
-/* utility to truncate a file */
-int simple_truncate(struct dentry *dir, struct vfsmount *mnt,
- char *name, loff_t length)
-{
- struct dentry *dchild;
- struct iattr newattrs;
- int err = 0;
- ENTRY;
-
- CDEBUG(D_INODE, "truncating file %.*s to %lld\n", (int)strlen(name),
- name, (long long)length);
- dchild = ll_lookup_one_len(name, dir, strlen(name));
- if (IS_ERR(dchild))
- GOTO(out, err = PTR_ERR(dchild));
-
- if (dchild->d_inode) {
- int old_mode = dchild->d_inode->i_mode;
- if (S_ISDIR(old_mode)) {
- CERROR("found %s (%lu/%u) is mode %o\n", name,
- dchild->d_inode->i_ino,
- dchild->d_inode->i_generation, old_mode);
- GOTO(out_dput, err = -EISDIR);
- }
-
- newattrs.ia_size = length;
- newattrs.ia_valid = ATTR_SIZE;
- err = l_notify_change(mnt, dchild, &newattrs);
- }
- EXIT;
-out_dput:
- dput(dchild);
-out:
- return err;
-}
-EXPORT_SYMBOL(simple_truncate);
-