2 * linux/fs/9p/vfs_dir.c
4 * This file contains vfs directory ops for the 9P2000 protocol.
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
27 #include <linux/module.h>
28 #include <linux/errno.h>
30 #include <linux/file.h>
31 #include <linux/stat.h>
32 #include <linux/string.h>
33 #include <linux/smp_lock.h>
34 #include <linux/inet.h>
35 #include <linux/idr.h>
45 * dt_type - return file type
46 * @mistat: mistat structure
50 static inline int dt_type(struct v9fs_stat *mistat)
52 unsigned long perm = mistat->mode;
55 if (perm & V9FS_DMDIR)
57 if (perm & V9FS_DMSYMLINK)
64 * v9fs_dir_readdir - read a directory
65 * @filep: opened file structure
66 * @dirent: directory structure ???
67 * @filldir: function to populate directory structure ???
71 static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
73 struct v9fs_fcall *fcall = NULL;
74 struct inode *inode = filp->f_dentry->d_inode;
75 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
76 struct v9fs_fid *file = filp->private_data;
80 struct v9fs_stat *mi = NULL;
83 dprintk(DEBUG_VFS, "name %s\n", filp->f_dentry->d_name.name);
87 mi = kmalloc(v9ses->maxdata, GFP_KERNEL);
91 if (file->rdir_fcall && (filp->f_pos != file->rdir_pos)) {
92 kfree(file->rdir_fcall);
93 file->rdir_fcall = NULL;
96 if (file->rdir_fcall) {
97 n = file->rdir_fcall->params.rread.count;
100 int s = v9fs_deserialize_stat(v9ses,
101 file->rdir_fcall->params.rread.data + i,
102 n - i, mi, v9ses->maxdata);
106 "error while deserializing mistat\n");
111 over = filldir(dirent, mi->name, strlen(mi->name),
112 filp->f_pos, v9fs_qid2ino(&mi->qid),
117 file->rdir_pos = filp->f_pos;
126 kfree(file->rdir_fcall);
127 file->rdir_fcall = NULL;
132 ret = v9fs_t_read(v9ses, fid, filp->f_pos,
133 v9ses->maxdata-V9FS_IOHDRSZ, &fcall);
135 dprintk(DEBUG_ERROR, "error while reading: %d: %p\n",
144 int s = v9fs_deserialize_stat(v9ses,
145 fcall->params.rread.data + i, n - i, mi,
150 "error while deserializing mistat\n");
154 over = filldir(dirent, mi->name, strlen(mi->name),
155 filp->f_pos, v9fs_qid2ino(&mi->qid),
159 file->rdir_fcall = fcall;
161 file->rdir_pos = filp->f_pos;
180 * v9fs_dir_release - close a directory
181 * @inode: inode of the directory
182 * @filp: file pointer to a directory
186 int v9fs_dir_release(struct inode *inode, struct file *filp)
188 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
189 struct v9fs_fid *fid = filp->private_data;
192 dprintk(DEBUG_VFS, "inode: %p filp: %p fid: %d\n", inode, filp,
196 filemap_fdatawrite(inode->i_mapping);
197 filemap_fdatawait(inode->i_mapping);
200 dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen,
203 if (v9fs_t_clunk(v9ses, fidnum, NULL))
204 dprintk(DEBUG_ERROR, "clunk failed\n");
206 v9fs_put_idpool(fid->fid, &v9ses->fidpool);
208 kfree(fid->rdir_fcall);
211 filp->private_data = NULL;
214 d_drop(filp->f_dentry);
218 struct file_operations v9fs_dir_operations = {
219 .read = generic_read_dir,
220 .readdir = v9fs_dir_readdir,
221 .open = v9fs_file_open,
222 .release = v9fs_dir_release,