Whamcloud - gitweb
land b_groups onto HEAD:
[fs/lustre-release.git] / lustre / smfs / dir.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2004 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #define DEBUG_SUBSYSTEM S_SM
24
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/string.h>
28 #include <linux/slab.h>
29 #include <linux/stat.h>
30 #include <linux/unistd.h>
31 #include <linux/smp_lock.h>
32 #include <linux/obd_class.h>
33 #include <linux/obd_support.h>
34 #include <linux/lustre_lib.h>
35 #include <linux/lustre_idl.h>
36 #include <linux/lustre_fsfilt.h>
37 #include <linux/lustre_smfs.h>
38 #include <linux/lustre_snap.h>
39
40 #include "smfs_internal.h"
41
42 #define NAME_ALLOC_LEN(len)     ((len+16) & ~15)
43
44 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
45 static int smfs_create(struct inode *dir, struct dentry *dentry,
46                        int mode)
47 #else
48 static int smfs_create(struct inode *dir, struct dentry *dentry,
49                        int mode, struct nameidata *nd)
50 #endif
51 {
52         struct inode  *inode = NULL;
53         struct inode  *cache_dir = NULL;
54         struct dentry *cache_dentry = NULL;
55         struct dentry *cache_parent = NULL;
56         void *handle = NULL;
57         int rc = 0;
58
59         ENTRY;
60
61         cache_dir = I2CI(dir);
62         if (!cache_dir)
63                 RETURN(-ENOENT);
64
65         handle = smfs_trans_start(dir, FSFILT_OP_CREATE, NULL);
66         if (IS_ERR(handle))
67                        RETURN(-ENOSPC);
68         
69         lock_kernel();
70         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_CREATE, handle, PRE_HOOK, rc, 
71                   exit); 
72         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
73         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
74
75         if (!cache_dentry || !cache_parent)
76                 GOTO(exit, rc = -ENOMEM);
77        
78         pre_smfs_inode(dir, cache_dir);
79 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
80         if (cache_dir && cache_dir->i_op->create)
81                 rc = cache_dir->i_op->create(cache_dir, cache_dentry,
82                                              mode);
83 #else
84         if (cache_dir && cache_dir->i_op->create)
85                 rc = cache_dir->i_op->create(cache_dir, cache_dentry,
86                                              mode, nd);
87 #endif
88         if (rc)
89                 GOTO(exit, rc);
90         
91         SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
92
93         d_instantiate(dentry, inode);
94         post_smfs_inode(dir, cache_dir);
95         
96         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_CREATE, handle, POST_HOOK, rc, 
97                   exit); 
98 exit:
99         unlock_kernel();
100         post_smfs_dentry(cache_dentry);
101         post_smfs_dentry(cache_parent);
102         smfs_trans_commit(dir, handle, 0);
103         RETURN(rc);
104 }
105
106 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
107 static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry)
108 #else
109 static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry,
110                                   struct nameidata *nd)
111 #endif
112 {
113         struct inode *cache_dir;
114         struct inode *cache_inode;
115         struct inode *inode = NULL;
116         struct dentry *cache_dentry = NULL;
117         struct dentry *cache_parent = NULL;
118         struct dentry *rc = NULL;
119         void *handle = NULL;
120         int rc2 = 0;
121
122         ENTRY;
123
124         if (!(cache_dir = I2CI(dir)))
125                 RETURN(ERR_PTR(-ENOENT));
126
127         /* preparing artificial backing fs dentries. */
128         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
129         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
130
131         if (!cache_dentry || !cache_parent)
132                 GOTO(exit, rc = ERR_PTR(-ENOMEM));
133
134         if (!cache_dir && cache_dir->i_op->lookup)
135                 GOTO(exit, rc = ERR_PTR(-ENOENT));
136
137         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_LOOKUP, handle, 
138                   PRE_HOOK, rc2, exit); 
139
140         /* perform lookup in backing fs. */
141 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
142         rc = cache_dir->i_op->lookup(cache_dir, cache_dentry);
143 #else
144         rc = cache_dir->i_op->lookup(cache_dir, cache_dentry, nd);
145 #endif
146         if (rc && IS_ERR(rc))
147                 GOTO(exit, rc);
148         
149         if ((cache_inode = rc ? rc->d_inode : cache_dentry->d_inode)) {
150                 if (IS_ERR(cache_inode)) {
151                         dentry->d_inode = cache_inode;
152                         GOTO(exit, rc = NULL);
153                 }
154                 SMFS_GET_INODE(dir->i_sb, cache_inode, dir, inode, rc2, exit);
155         }
156
157         d_add(dentry, inode);
158         rc = NULL;
159
160         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_LOOKUP, handle, POST_HOOK, rc2, 
161                   exit); 
162 exit:
163         if (rc2 < 0)
164                 rc = ERR_PTR(rc2);
165         post_smfs_dentry(cache_dentry);
166         post_smfs_dentry(cache_parent);
167         smfs_trans_commit(dir, handle, 0);
168         RETURN(rc);
169 }
170
171 static int smfs_link(struct dentry * old_dentry,
172                      struct inode * dir, struct dentry *dentry)
173 {
174         struct        inode *cache_old_inode = NULL;
175         struct        inode *cache_dir = I2CI(dir);
176         struct        inode *inode = NULL;
177         struct  dentry *cache_dentry = NULL;
178         struct  dentry *cache_old_dentry = NULL;
179         struct  dentry *cache_parent = NULL;
180         void        *handle = NULL;
181         int        rc = 0;
182
183         inode = old_dentry->d_inode;
184
185         cache_old_inode = I2CI(inode);
186
187         handle = smfs_trans_start(dir, FSFILT_OP_LINK, NULL);
188         if (IS_ERR(handle))
189                  RETURN(-ENOSPC);
190         
191         lock_kernel();
192         SMFS_HOOK(dir, old_dentry, NULL, NULL, HOOK_LINK, handle, PRE_HOOK, rc, 
193                   exit); 
194         
195         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
196         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
197
198         if (!cache_parent || !cache_dentry)
199                 GOTO(exit, rc = -ENOMEM);
200
201         cache_old_dentry = pre_smfs_dentry(NULL, cache_old_inode, old_dentry);
202         if (!cache_old_dentry)
203                 GOTO(exit, rc = -ENOMEM);
204
205         pre_smfs_inode(dir, cache_dir);
206         pre_smfs_inode(inode, cache_old_dentry->d_inode);
207
208         if (cache_dir->i_op->link)
209                 rc = cache_dir->i_op->link(cache_old_dentry, cache_dir,
210                                            cache_dentry);
211         if (rc)
212                 GOTO(exit, rc);
213
214         atomic_inc(&inode->i_count);
215         post_smfs_inode(inode, cache_old_dentry->d_inode);
216         d_instantiate(dentry, inode);
217         post_smfs_inode(dir, cache_dir);
218
219         SMFS_HOOK(dir, old_dentry, dentry, NULL, HOOK_LINK, handle, POST_HOOK, 
220                   rc, exit); 
221 exit:
222         unlock_kernel();
223         post_smfs_dentry(cache_dentry);
224         post_smfs_dentry(cache_parent);
225         post_smfs_dentry(cache_old_dentry);
226         smfs_trans_commit(dir, handle, 0);
227         RETURN(rc);
228 }
229
230 static int smfs_unlink(struct inode * dir,
231                        struct dentry *dentry)
232 {
233         struct inode *cache_dir = I2CI(dir);
234         struct inode *cache_inode = I2CI(dentry->d_inode);
235         struct dentry *cache_dentry;
236         struct dentry *cache_parent;
237         void   *handle = NULL;
238         int    rc = 0;
239         int    mode = 0;
240
241         if (!cache_dir || !cache_inode)
242                 RETURN(-ENOENT);
243
244         handle = smfs_trans_start(dir, FSFILT_OP_UNLINK, NULL);
245         if (IS_ERR(handle))
246                 RETURN(-ENOSPC);
247
248         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_UNLINK, handle, PRE_HOOK, rc, 
249                   exit); 
250         
251         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
252         cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
253
254         if (!cache_parent || !cache_dentry)
255                 GOTO(exit, rc = -ENOMEM);
256                 
257         lock_kernel();
258         pre_smfs_inode(dir, cache_dir);
259         pre_smfs_inode(dentry->d_inode, cache_inode);
260         if (cache_dir->i_op->unlink)
261                 rc = cache_dir->i_op->unlink(cache_dir, cache_dentry);
262         post_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
263         post_smfs_inode(dir, cache_dir);
264         unlock_kernel();
265         
266         SMFS_HOOK(dir, dentry, &mode, NULL, HOOK_UNLINK, handle, POST_HOOK, 
267                   rc, exit); 
268 exit:
269         post_smfs_dentry(cache_dentry);
270         post_smfs_dentry(cache_parent);
271         smfs_trans_commit(dir, handle, 0);
272         RETURN(rc);
273 }
274
275 static int smfs_symlink(struct inode *dir, struct dentry *dentry,
276                         const char *symname)
277 {
278         struct inode *cache_dir = I2CI(dir);
279         struct inode *inode = NULL;
280         struct dentry *cache_dentry;
281         struct dentry *cache_parent;
282         void   *handle = NULL;
283         int    rc = 0, tgt_len;
284
285         if (!cache_dir)
286                 RETURN(-ENOENT);
287
288         handle = smfs_trans_start(dir, FSFILT_OP_SYMLINK, NULL);
289         if (IS_ERR(handle))
290                 RETURN(-ENOSPC);
291         
292         lock_kernel();
293         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_SYMLINK, handle, PRE_HOOK, rc, 
294                   exit); 
295
296         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
297         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
298
299         if (!cache_parent || !cache_dentry)
300                 GOTO(exit, rc = -ENOMEM);
301        
302         pre_smfs_inode(dir, cache_dir);
303         if (cache_dir->i_op->symlink)
304                 rc = cache_dir->i_op->symlink(cache_dir, cache_dentry, symname);
305
306         post_smfs_inode(dir, cache_dir);
307         
308         SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
309         if (inode)
310                 d_instantiate(dentry, inode);
311         else
312                 rc = -ENOENT;
313
314         tgt_len = strlen(symname) + 1;
315         
316         SMFS_HOOK(dir, dentry, (char *)symname, &tgt_len, HOOK_SYMLINK, handle, 
317                   POST_HOOK, rc, exit); 
318 exit:
319         unlock_kernel();
320         post_smfs_dentry(cache_dentry);
321         post_smfs_dentry(cache_parent);
322         smfs_trans_commit(dir, handle, 0);
323         RETURN(rc);
324 }
325
326 static int smfs_mkdir(struct inode *dir, struct dentry *dentry,
327                       int mode)
328 {
329         struct inode *cache_dir = I2CI(dir);
330         struct inode *inode = NULL;
331         struct dentry *cache_dentry;
332         struct dentry *cache_parent;
333         void   *handle = NULL;
334         int    rc = 0;
335
336         if (!cache_dir)
337                 RETURN(-ENOENT);
338
339         handle = smfs_trans_start(dir, FSFILT_OP_MKDIR, NULL);
340         if (IS_ERR(handle))
341                 RETURN(-ENOSPC);
342
343         lock_kernel();
344         
345         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKDIR, handle, PRE_HOOK, rc, 
346                   exit); 
347         
348         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
349         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
350
351         if (!cache_parent || !cache_dentry)
352                 GOTO(exit, rc = -ENOMEM);
353
354         pre_smfs_inode(dir, cache_dir);
355
356         if (cache_dir->i_op->mkdir)
357                 rc = cache_dir->i_op->mkdir(cache_dir, cache_dentry, mode);
358
359         if (rc)
360                 GOTO(exit, rc);
361   
362         SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
363         d_instantiate(dentry, inode);
364         post_smfs_inode(dir, cache_dir);
365
366         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKDIR, handle, POST_HOOK, rc,
367                   exit); 
368 exit:
369         unlock_kernel();
370         post_smfs_dentry(cache_dentry);
371         post_smfs_dentry(cache_parent);
372         smfs_trans_commit(dir, handle, 0);
373         RETURN(rc);
374 }
375
376 static int smfs_rmdir(struct inode *dir, struct dentry *dentry)
377 {
378         struct inode *cache_dir = I2CI(dir);
379         struct inode *cache_inode = I2CI(dentry->d_inode);
380         struct dentry *cache_dentry = NULL;
381         struct dentry *cache_parent = NULL;
382         void *handle = NULL;
383         int    rc = 0, mode = S_IFDIR;
384
385         if (!cache_dir)
386                 RETURN(-ENOENT);
387
388         handle = smfs_trans_start(dir, FSFILT_OP_RMDIR, NULL);
389         if (IS_ERR(handle) ) {
390                 CERROR("smfs_do_mkdir: no space for transaction\n");
391                 RETURN(-ENOSPC);
392         }
393
394         lock_kernel();
395
396         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_RMDIR, handle, PRE_HOOK, rc, 
397                   exit); 
398
399         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry);
400         cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
401
402         if (!cache_parent || !cache_dentry)
403                 GOTO(exit, rc = -ENOMEM);
404
405         pre_smfs_inode(dir, cache_dir);
406         pre_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
407         if (cache_dir->i_op->rmdir)
408                 rc = cache_dir->i_op->rmdir(cache_dir, cache_dentry);
409
410         post_smfs_inode(dir, cache_dir);
411         post_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
412         unlock_kernel();
413         
414         SMFS_HOOK(dir, dentry, &mode, NULL, HOOK_RMDIR, handle, POST_HOOK, 
415                   rc, exit); 
416 exit:
417         post_smfs_dentry(cache_dentry);
418         post_smfs_dentry(cache_parent);
419         smfs_trans_commit(dir, handle, 0);
420         RETURN(rc);
421 }
422
423 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
424 static int smfs_mknod(struct inode *dir, struct dentry *dentry,
425                       int mode, int rdev)
426 #else
427 static int smfs_mknod(struct inode *dir, struct dentry *dentry,
428                       int mode, dev_t rdev)
429 #endif
430 {
431         struct inode *cache_dir = I2CI(dir);
432         struct inode *inode = NULL;
433         struct dentry *cache_dentry = NULL;
434         struct dentry *cache_parent = NULL;
435         void *handle = NULL;
436         int rc = 0;
437
438         if (!cache_dir)
439                 RETURN(-ENOENT);
440
441         handle = smfs_trans_start(dir, FSFILT_OP_MKNOD, NULL);
442         if (IS_ERR(handle)) {
443                 CERROR("smfs_do_mkdir: no space for transaction\n");
444                 RETURN(-ENOSPC);
445         }
446
447         lock_kernel();
448         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKNOD, handle, PRE_HOOK, rc, 
449                   exit); 
450         
451         cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
452         cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry);
453         if (!cache_parent || !cache_dentry)
454                 GOTO(exit, rc = -ENOMEM);
455
456         pre_smfs_inode(dir, cache_dir);
457         pre_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
458
459         if (!cache_dir->i_op->mknod)
460                 RETURN(-ENOENT);
461
462         if ((rc = cache_dir->i_op->mknod(cache_dir, cache_dentry,
463                                          mode, rdev)))
464                 GOTO(exit, rc);
465
466         SMFS_GET_INODE(dir->i_sb, cache_dentry->d_inode, dir, inode, rc, exit); 
467
468         d_instantiate(dentry, inode);
469
470         pre_smfs_inode(dir, cache_dir);
471         pre_smfs_inode(dentry->d_inode, cache_dentry->d_inode);
472
473         SMFS_HOOK(dir, dentry, NULL, NULL, HOOK_MKNOD, handle, POST_HOOK, rc, 
474                   exit); 
475         
476 exit:
477         unlock_kernel();
478         post_smfs_dentry(cache_dentry);
479         post_smfs_dentry(cache_parent);
480         smfs_trans_commit(dir, handle, 0);
481         RETURN(rc);
482 }
483
484 static int smfs_rename(struct inode * old_dir, struct dentry *old_dentry,
485                        struct inode * new_dir,struct dentry *new_dentry)
486 {
487         struct inode *cache_old_dir = I2CI(old_dir);
488         struct inode *cache_new_dir = I2CI(new_dir);
489         struct inode *cache_old_inode = I2CI(old_dentry->d_inode);
490
491         struct inode *cache_new_inode = new_dentry->d_inode ?
492             I2CI(new_dentry->d_inode) : NULL;
493
494         struct dentry *cache_old_dentry = NULL;
495         struct dentry *cache_new_dentry = NULL;
496         struct dentry *cache_new_parent = NULL;
497         struct dentry *cache_old_parent = NULL;
498         void *handle = NULL;
499         int    rc = 0;
500
501         if (!cache_old_dir || !cache_new_dir || !cache_old_inode)
502                 RETURN(-ENOENT);
503
504         handle = smfs_trans_start(old_dir, FSFILT_OP_RENAME, NULL);
505         if (IS_ERR(handle)) {
506                 CERROR("smfs_do_mkdir: no space for transaction\n");
507                 RETURN(-ENOSPC);
508         }
509         lock_kernel();
510
511         
512         SMFS_HOOK(old_dir, old_dentry, new_dir, new_dentry, HOOK_RENAME, handle, 
513                   PRE_HOOK, rc, exit); 
514         
515         cache_old_parent = pre_smfs_dentry(NULL, cache_old_dir, old_dentry);
516         cache_old_dentry = pre_smfs_dentry(cache_old_parent, cache_old_inode,
517                                            old_dentry);
518         if (!cache_old_parent || !cache_old_dentry)
519                 GOTO(exit, rc = -ENOMEM);
520
521         cache_new_parent = pre_smfs_dentry(NULL, cache_new_dir, new_dentry);
522         cache_new_dentry = pre_smfs_dentry(cache_new_parent, cache_new_inode,
523                                            new_dentry);
524         if (!cache_new_parent || !cache_new_dentry)
525                 GOTO(exit, rc = -ENOMEM);
526
527         pre_smfs_inode(old_dir, cache_old_dir);
528         pre_smfs_inode(new_dir, cache_new_dir);
529
530         if (cache_old_dir->i_op->rename)
531                 rc = cache_old_dir->i_op->rename(cache_old_dir, cache_old_dentry,
532                                                  cache_new_dir, cache_new_dentry);
533         
534         post_smfs_inode(old_dir, cache_old_dir);
535         post_smfs_inode(new_dir, cache_new_dir);
536
537         SMFS_HOOK(old_dir, old_dentry, new_dir, new_dentry, HOOK_RENAME, handle, 
538                   POST_HOOK, rc, exit); 
539         
540         if (new_dentry->d_inode)
541                 post_smfs_inode(new_dentry->d_inode, cache_new_dentry->d_inode);
542 exit:
543         unlock_kernel();
544         post_smfs_dentry(cache_old_dentry);
545         post_smfs_dentry(cache_old_parent);
546         post_smfs_dentry(cache_new_dentry);
547         post_smfs_dentry(cache_new_parent);
548         smfs_trans_commit(old_dir, handle, 0);
549         RETURN(rc);
550 }
551
552 struct inode_operations smfs_dir_iops = {
553         create:         smfs_create,
554         lookup:         smfs_lookup,
555         link:           smfs_link,              /* BKL held */
556         unlink:         smfs_unlink,            /* BKL held */
557         symlink:        smfs_symlink,           /* BKL held */
558         mkdir:          smfs_mkdir,             /* BKL held */
559         rmdir:          smfs_rmdir,             /* BKL held */
560         mknod:          smfs_mknod,             /* BKL held */
561         rename:         smfs_rename,            /* BKL held */
562         setxattr:       smfs_setxattr,          /* BKL held */
563         getxattr:       smfs_getxattr,          /* BKL held */
564         listxattr:      smfs_listxattr,         /* BKL held */
565         removexattr:    smfs_removexattr,       /* BKL held */
566 };
567
568 static ssize_t smfs_read_dir(struct file *filp, char *buf,
569                              size_t size, loff_t *ppos)
570 {
571         struct dentry *dentry = filp->f_dentry;
572         struct inode *cache_inode = NULL;
573         struct smfs_file_info *sfi = NULL;
574         loff_t tmp_ppos;
575         loff_t *cache_ppos;
576         int    rc = 0;
577
578         cache_inode = I2CI(dentry->d_inode);
579
580         if (!cache_inode)
581                 RETURN(-EINVAL);
582
583         sfi = F2SMFI(filp);
584         if (sfi->magic != SMFS_FILE_MAGIC) BUG();
585
586         if (ppos != &(filp->f_pos))
587                 cache_ppos = &tmp_ppos;
588         else
589                 cache_ppos = &sfi->c_file->f_pos;
590         *cache_ppos = *ppos;
591
592         if (cache_inode->i_fop->read)
593                 rc = cache_inode->i_fop->read(sfi->c_file, buf, size,
594                                               cache_ppos);
595         *ppos = *cache_ppos;
596         duplicate_file(filp, sfi->c_file);
597         RETURN(rc);
598 }
599
600 static int smfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
601 {
602         struct dentry *dentry = filp->f_dentry;
603         struct inode *cache_inode = NULL;
604         struct smfs_file_info *sfi = NULL;
605         int    rc = 0;
606
607         cache_inode = I2CI(dentry->d_inode);
608         if (!cache_inode)
609                 RETURN(-EINVAL);
610
611         sfi = F2SMFI(filp);
612         if (sfi->magic != SMFS_FILE_MAGIC) BUG();
613
614         SMFS_HOOK(dentry->d_inode, filp, dirent, filldir, HOOK_READDIR, NULL, 
615                   PRE_HOOK, rc, exit); 
616         
617         if (cache_inode->i_fop->readdir)
618                 rc = cache_inode->i_fop->readdir(sfi->c_file, dirent, filldir);
619
620         SMFS_HOOK(dentry->d_inode, filp, dirent, filldir, HOOK_READDIR, NULL, 
621                   POST_HOOK, rc, exit);
622         
623         duplicate_file(filp, sfi->c_file);
624 exit:
625         if (rc > 0)
626                 rc = 0;
627         RETURN(rc);
628 }
629
630 struct file_operations smfs_dir_fops = {
631         read:           smfs_read_dir,
632         readdir:        smfs_readdir,           /* BKL held */
633         ioctl:          smfs_ioctl,             /* BKL held */
634         fsync:          smfs_fsync,         /* BKL held */
635         open:           smfs_open,
636         release:        smfs_release,
637 };