The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/efs/namei.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * namei.c
    3  *
    4  * Copyright (c) 1999 Al Smith
    5  *
    6  * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
    7  */
    8 
    9 #include <linux/string.h>
   10 #include <linux/efs_fs.h>
   11 
   12 static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len) {
   13         struct buffer_head *bh;
   14 
   15         int                     slot, namelen;
   16         char                    *nameptr;
   17         struct efs_dir          *dirblock;
   18         struct efs_dentry       *dirslot;
   19         efs_ino_t               inodenum;
   20         efs_block_t             block;
   21  
   22         if (inode->i_size & (EFS_DIRBSIZE-1))
   23                 printk(KERN_WARNING "EFS: WARNING: find_entry(): directory size not a multiple of EFS_DIRBSIZE\n");
   24 
   25         for(block = 0; block < inode->i_blocks; block++) {
   26 
   27                 bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
   28                 if (!bh) {
   29                         printk(KERN_ERR "EFS: find_entry(): failed to read dir block %d\n", block);
   30                         return 0;
   31                 }
   32     
   33                 dirblock = (struct efs_dir *) bh->b_data;
   34 
   35                 if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
   36                         printk(KERN_ERR "EFS: find_entry(): invalid directory block\n");
   37                         brelse(bh);
   38                         return(0);
   39                 }
   40 
   41                 for(slot = 0; slot < dirblock->slots; slot++) {
   42                         dirslot  = (struct efs_dentry *) (((char *) bh->b_data) + EFS_SLOTAT(dirblock, slot));
   43 
   44                         namelen  = dirslot->namelen;
   45                         nameptr  = dirslot->name;
   46 
   47                         if ((namelen == len) && (!memcmp(name, nameptr, len))) {
   48                                 inodenum = be32_to_cpu(dirslot->inode);
   49                                 brelse(bh);
   50                                 return(inodenum);
   51                         }
   52                 }
   53                 brelse(bh);
   54         }
   55         return(0);
   56 }
   57 
   58 struct dentry *efs_lookup(struct inode *dir, struct dentry *dentry) {
   59         efs_ino_t inodenum;
   60         struct inode * inode;
   61 
   62         if (!dir || !S_ISDIR(dir->i_mode))
   63                 return ERR_PTR(-ENOENT);
   64 
   65         inode = NULL;
   66 
   67         inodenum = efs_find_entry(dir, dentry->d_name.name, dentry->d_name.len);
   68         if (inodenum) {
   69                 if (!(inode = iget(dir->i_sb, inodenum)))
   70                         return ERR_PTR(-EACCES);
   71         }
   72 
   73         d_add(dentry, inode);
   74         return NULL;
   75 }
   76 

Cache object: 5d03f97166362c395935f1c84cc47200


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.