LTP GCOV extension - code coverage report
Current view: directory - fs/isofs - export.c
Test: 2.6.14_rebootonly_gcov.info
Date: 2006-05-22 Instrumented lines: 105
Code covered: 0.0 % Executed lines: 0

       1                 : /*
       2                 :  * fs/isofs/export.c
       3                 :  *
       4                 :  *  (C) 2004  Paul Serice - The new inode scheme requires switching
       5                 :  *                          from iget() to iget5_locked() which means
       6                 :  *                          the NFS export operations have to be hand
       7                 :  *                          coded because the default routines rely on
       8                 :  *                          iget().
       9                 :  *
      10                 :  * The following files are helpful:
      11                 :  *
      12                 :  *     Documentation/filesystems/Exporting
      13                 :  *     fs/exportfs/expfs.c.
      14                 :  */
      15                 : 
      16                 : #include "isofs.h"
      17                 : 
      18                 : static struct dentry *
      19                 : isofs_export_iget(struct super_block *sb,
      20                 :                   unsigned long block,
      21                 :                   unsigned long offset,
      22                 :                   __u32 generation)
      23               0 : {
      24               0 :         struct inode *inode;
      25               0 :         struct dentry *result;
      26               0 :         if (block == 0)
      27               0 :                 return ERR_PTR(-ESTALE);
      28               0 :         inode = isofs_iget(sb, block, offset);
      29               0 :         if (inode == NULL)
      30               0 :                 return ERR_PTR(-ENOMEM);
      31               0 :         if (is_bad_inode(inode)
      32                 :             || (generation && inode->i_generation != generation))
      33                 :         {
      34               0 :                 iput(inode);
      35               0 :                 return ERR_PTR(-ESTALE);
      36                 :         }
      37               0 :         result = d_alloc_anon(inode);
      38               0 :         if (!result) {
      39               0 :                 iput(inode);
      40               0 :                 return ERR_PTR(-ENOMEM);
      41                 :         }
      42               0 :         return result;
      43                 : }
      44                 : 
      45                 : static struct dentry *
      46                 : isofs_export_get_dentry(struct super_block *sb, void *vobjp)
      47               0 : {
      48               0 :         __u32 *objp = vobjp;
      49               0 :         unsigned long block = objp[0];
      50               0 :         unsigned long offset = objp[1];
      51               0 :         __u32 generation = objp[2];
      52               0 :         return isofs_export_iget(sb, block, offset, generation);
      53                 : }
      54                 : 
      55                 : /* This function is surprisingly simple.  The trick is understanding
      56                 :  * that "child" is always a directory. So, to find its parent, you
      57                 :  * simply need to find its ".." entry, normalize its block and offset,
      58                 :  * and return the underlying inode.  See the comments for
      59                 :  * isofs_normalize_block_and_offset(). */
      60                 : static struct dentry *isofs_export_get_parent(struct dentry *child)
      61               0 : {
      62               0 :         unsigned long parent_block = 0;
      63               0 :         unsigned long parent_offset = 0;
      64               0 :         struct inode *child_inode = child->d_inode;
      65               0 :         struct iso_inode_info *e_child_inode = ISOFS_I(child_inode);
      66               0 :         struct inode *parent_inode = NULL;
      67               0 :         struct iso_directory_record *de = NULL;
      68               0 :         struct buffer_head * bh = NULL;
      69               0 :         struct dentry *rv = NULL;
      70                 : 
      71                 :         /* "child" must always be a directory. */
      72               0 :         if (!S_ISDIR(child_inode->i_mode)) {
      73               0 :                 printk(KERN_ERR "isofs: isofs_export_get_parent(): "
      74                 :                        "child is not a directory!\n");
      75               0 :                 rv = ERR_PTR(-EACCES);
      76               0 :                 goto out;
      77                 :         }
      78                 : 
      79                 :         /* It is an invariant that the directory offset is zero.  If
      80                 :          * it is not zero, it means the directory failed to be
      81                 :          * normalized for some reason. */
      82               0 :         if (e_child_inode->i_iget5_offset != 0) {
      83               0 :                 printk(KERN_ERR "isofs: isofs_export_get_parent(): "
      84                 :                        "child directory not normalized!\n");
      85               0 :                 rv = ERR_PTR(-EACCES);
      86               0 :                 goto out;
      87                 :         }
      88                 : 
      89                 :         /* The child inode has been normalized such that its
      90                 :          * i_iget5_block value points to the "." entry.  Fortunately,
      91                 :          * the ".." entry is located in the same block. */
      92               0 :         parent_block = e_child_inode->i_iget5_block;
      93                 : 
      94                 :         /* Get the block in question. */
      95               0 :         bh = sb_bread(child_inode->i_sb, parent_block);
      96               0 :         if (bh == NULL) {
      97               0 :                 rv = ERR_PTR(-EACCES);
      98               0 :                 goto out;
      99                 :         }
     100                 : 
     101                 :         /* This is the "." entry. */
     102               0 :         de = (struct iso_directory_record*)bh->b_data;
     103                 : 
     104                 :         /* The ".." entry is always the second entry. */
     105               0 :         parent_offset = (unsigned long)isonum_711(de->length);
     106               0 :         de = (struct iso_directory_record*)(bh->b_data + parent_offset);
     107                 : 
     108                 :         /* Verify it is in fact the ".." entry. */
     109               0 :         if ((isonum_711(de->name_len) != 1) || (de->name[0] != 1)) {
     110               0 :                 printk(KERN_ERR "isofs: Unable to find the \"..\" "
     111                 :                        "directory for NFS.\n");
     112               0 :                 rv = ERR_PTR(-EACCES);
     113               0 :                 goto out;
     114                 :         }
     115                 : 
     116                 :         /* Normalize */
     117               0 :         isofs_normalize_block_and_offset(de, &parent_block, &parent_offset);
     118                 : 
     119                 :         /* Get the inode. */
     120               0 :         parent_inode = isofs_iget(child_inode->i_sb,
     121                 :                                   parent_block,
     122                 :                                   parent_offset);
     123               0 :         if (parent_inode == NULL) {
     124               0 :                 rv = ERR_PTR(-EACCES);
     125               0 :                 goto out;
     126                 :         }
     127                 : 
     128                 :         /* Allocate the dentry. */
     129               0 :         rv = d_alloc_anon(parent_inode);
     130               0 :         if (rv == NULL) {
     131               0 :                 rv = ERR_PTR(-ENOMEM);
     132                 :                 goto out;
     133                 :         }
     134                 : 
     135                 :  out:
     136               0 :         if (bh) {
     137               0 :                 brelse(bh);
     138                 :         }
     139               0 :         return rv;
     140                 : }
     141                 : 
     142                 : static int
     143                 : isofs_export_encode_fh(struct dentry *dentry,
     144                 :                        __u32 *fh32,
     145                 :                        int *max_len,
     146                 :                        int connectable)
     147               0 : {
     148               0 :         struct inode * inode = dentry->d_inode;
     149               0 :         struct iso_inode_info * ei = ISOFS_I(inode);
     150               0 :         int len = *max_len;
     151               0 :         int type = 1;
     152               0 :         __u16 *fh16 = (__u16*)fh32;
     153                 : 
     154                 :         /*
     155                 :          * WARNING: max_len is 5 for NFSv2.  Because of this
     156                 :          * limitation, we use the lower 16 bits of fh32[1] to hold the
     157                 :          * offset of the inode and the upper 16 bits of fh32[1] to
     158                 :          * hold the offset of the parent.
     159                 :          */
     160                 : 
     161               0 :         if (len < 3 || (connectable && len < 5))
     162               0 :                 return 255;
     163                 : 
     164               0 :         len = 3;
     165               0 :         fh32[0] = ei->i_iget5_block;
     166               0 :         fh16[2] = (__u16)ei->i_iget5_offset;  /* fh16 [sic] */
     167               0 :         fh32[2] = inode->i_generation;
     168               0 :         if (connectable && !S_ISDIR(inode->i_mode)) {
     169               0 :                 struct inode *parent;
     170               0 :                 struct iso_inode_info *eparent;
     171               0 :                 spin_lock(&dentry->d_lock);
     172               0 :                 parent = dentry->d_parent->d_inode;
     173               0 :                 eparent = ISOFS_I(parent);
     174               0 :                 fh32[3] = eparent->i_iget5_block;
     175               0 :                 fh16[3] = (__u16)eparent->i_iget5_offset;  /* fh16 [sic] */
     176               0 :                 fh32[4] = parent->i_generation;
     177               0 :                 spin_unlock(&dentry->d_lock);
     178               0 :                 len = 5;
     179               0 :                 type = 2;
     180                 :         }
     181               0 :         *max_len = len;
     182               0 :         return type;
     183                 : }
     184                 : 
     185                 : 
     186                 : static struct dentry *
     187                 : isofs_export_decode_fh(struct super_block *sb,
     188                 :                        __u32 *fh32,
     189                 :                        int fh_len,
     190                 :                        int fileid_type,
     191                 :                        int (*acceptable)(void *context, struct dentry *de),
     192                 :                        void *context)
     193               0 : {
     194               0 :         __u16 *fh16 = (__u16*)fh32;
     195               0 :         __u32 child[3];   /* The child is what triggered all this. */
     196               0 :         __u32 parent[3];  /* The parent is just along for the ride. */
     197                 : 
     198               0 :         if (fh_len < 3 || fileid_type > 2)
     199               0 :                 return NULL;
     200                 : 
     201               0 :         child[0] = fh32[0];
     202               0 :         child[1] = fh16[2];  /* fh16 [sic] */
     203               0 :         child[2] = fh32[2];
     204                 : 
     205               0 :         parent[0] = 0;
     206               0 :         parent[1] = 0;
     207               0 :         parent[2] = 0;
     208               0 :         if (fileid_type == 2) {
     209               0 :                 if (fh_len > 2) parent[0] = fh32[3];
     210               0 :                 parent[1] = fh16[3];  /* fh16 [sic] */
     211               0 :                 if (fh_len > 4) parent[2] = fh32[4];
     212                 :         }
     213                 : 
     214               0 :         return sb->s_export_op->find_exported_dentry(sb, child, parent,
     215                 :                                                      acceptable, context);
     216                 : }
     217                 : 
     218                 : 
     219                 : struct export_operations isofs_export_ops = {
     220                 :         .decode_fh      = isofs_export_decode_fh,
     221                 :         .encode_fh      = isofs_export_encode_fh,
     222                 :         .get_dentry     = isofs_export_get_dentry,
     223                 :         .get_parent     = isofs_export_get_parent,
     224                 : };

Generated by: LTP GCOV extension version 1.4