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 version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
26 #include <linux/module.h>
27 #include <linux/errno.h>
29 #include <linux/file.h>
30 #include <linux/stat.h>
31 #include <linux/string.h>
32 #include <linux/sched.h>
33 #include <linux/inet.h>
34 #include <linux/idr.h>
44 * dt_type - return file type
45 * @mistat: mistat structure
49 static inline int dt_type(struct v9fs_stat
*mistat
)
51 unsigned long perm
= mistat
->mode
;
54 if (perm
& V9FS_DMDIR
)
56 if (perm
& V9FS_DMSYMLINK
)
63 * v9fs_dir_readdir - read a directory
64 * @filep: opened file structure
65 * @dirent: directory structure ???
66 * @filldir: function to populate directory structure ???
70 static int v9fs_dir_readdir(struct file
*filp
, void *dirent
, filldir_t filldir
)
72 struct v9fs_fcall
*fcall
= NULL
;
73 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
74 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(inode
);
75 struct v9fs_fid
*file
= filp
->private_data
;
79 struct v9fs_stat stat
;
82 dprintk(DEBUG_VFS
, "name %s\n", filp
->f_path
.dentry
->d_name
.name
);
86 if (file
->rdir_fcall
&& (filp
->f_pos
!= file
->rdir_pos
)) {
87 kfree(file
->rdir_fcall
);
88 file
->rdir_fcall
= NULL
;
91 if (file
->rdir_fcall
) {
92 n
= file
->rdir_fcall
->params
.rread
.count
;
95 s
= v9fs_deserialize_stat(
96 file
->rdir_fcall
->params
.rread
.data
+ i
,
97 n
- i
, &stat
, v9ses
->extended
);
101 "error while deserializing stat\n");
106 over
= filldir(dirent
, stat
.name
.str
, stat
.name
.len
,
107 filp
->f_pos
, v9fs_qid2ino(&stat
.qid
),
112 file
->rdir_pos
= filp
->f_pos
;
121 kfree(file
->rdir_fcall
);
122 file
->rdir_fcall
= NULL
;
127 ret
= v9fs_t_read(v9ses
, fid
, filp
->f_pos
,
128 v9ses
->maxdata
-V9FS_IOHDRSZ
, &fcall
);
130 dprintk(DEBUG_ERROR
, "error while reading: %d: %p\n",
139 s
= v9fs_deserialize_stat(fcall
->params
.rread
.data
+ i
,
140 n
- i
, &stat
, v9ses
->extended
);
144 "error while deserializing stat\n");
148 over
= filldir(dirent
, stat
.name
.str
, stat
.name
.len
,
149 filp
->f_pos
, v9fs_qid2ino(&stat
.qid
),
153 file
->rdir_fcall
= fcall
;
155 file
->rdir_pos
= filp
->f_pos
;
173 * v9fs_dir_release - close a directory
174 * @inode: inode of the directory
175 * @filp: file pointer to a directory
179 int v9fs_dir_release(struct inode
*inode
, struct file
*filp
)
181 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(inode
);
182 struct v9fs_fid
*fid
= filp
->private_data
;
185 dprintk(DEBUG_VFS
, "inode: %p filp: %p fid: %d\n", inode
, filp
,
189 filemap_write_and_wait(inode
->i_mapping
);
192 dprintk(DEBUG_VFS
, "fidopen: %d v9f->fid: %d\n", fid
->fidopen
,
195 if (v9fs_t_clunk(v9ses
, fidnum
))
196 dprintk(DEBUG_ERROR
, "clunk failed\n");
198 kfree(fid
->rdir_fcall
);
201 filp
->private_data
= NULL
;
207 const struct file_operations v9fs_dir_operations
= {
208 .read
= generic_read_dir
,
209 .readdir
= v9fs_dir_readdir
,
210 .open
= v9fs_file_open
,
211 .release
= v9fs_dir_release
,