root/fs/minix/dir.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. minix_dir_read
  2. minix_readdir

   1 /*
   2  *  linux/fs/minix/dir.c
   3  *
   4  *  Copyright (C) 1991, 1992 Linus Torvalds
   5  *
   6  *  minix directory handling functions
   7  */
   8 
   9 #include <asm/segment.h>
  10 
  11 #include <linux/errno.h>
  12 #include <linux/fs.h>
  13 #include <linux/minix_fs.h>
  14 #include <linux/stat.h>
  15 
  16 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
  17 #define ROUND_UP(x) (((x)+3) & ~3)
  18 
  19 static int minix_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21         return -EISDIR;
  22 }
  23 
  24 static int minix_readdir(struct inode *, struct file *, struct dirent *, int);
  25 
  26 static struct file_operations minix_dir_operations = {
  27         NULL,                   /* lseek - default */
  28         minix_dir_read,         /* read */
  29         NULL,                   /* write - bad */
  30         minix_readdir,          /* readdir */
  31         NULL,                   /* select - default */
  32         NULL,                   /* ioctl - default */
  33         NULL,                   /* mmap */
  34         NULL,                   /* no special open code */
  35         NULL,                   /* no special release code */
  36         file_fsync              /* default fsync */
  37 };
  38 
  39 /*
  40  * directories can handle most operations...
  41  */
  42 struct inode_operations minix_dir_inode_operations = {
  43         &minix_dir_operations,  /* default directory file-ops */
  44         minix_create,           /* create */
  45         minix_lookup,           /* lookup */
  46         minix_link,             /* link */
  47         minix_unlink,           /* unlink */
  48         minix_symlink,          /* symlink */
  49         minix_mkdir,            /* mkdir */
  50         minix_rmdir,            /* rmdir */
  51         minix_mknod,            /* mknod */
  52         minix_rename,           /* rename */
  53         NULL,                   /* readlink */
  54         NULL,                   /* follow_link */
  55         NULL,                   /* bmap */
  56         minix_truncate,         /* truncate */
  57         NULL                    /* permission */
  58 };
  59 
  60 static int minix_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  61         struct dirent * dirent, int count)
  62 {
  63         unsigned int offset,i,ret;
  64         int version;
  65         char c;
  66         struct buffer_head * bh;
  67         struct minix_dir_entry * de;
  68         struct minix_sb_info * info;
  69 
  70         if (!inode || !inode->i_sb || !S_ISDIR(inode->i_mode))
  71                 return -EBADF;
  72         info = &inode->i_sb->u.minix_sb;
  73         if (filp->f_pos & (info->s_dirsize - 1))
  74                 return -EBADF;
  75         ret = 0;
  76         while (!ret && filp->f_pos < inode->i_size) {
  77                 offset = filp->f_pos & 1023;
  78                 bh = minix_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
  79                 if (!bh) {
  80                         filp->f_pos += 1024-offset;
  81                         continue;
  82                 }
  83                 while (!ret && offset < 1024 && filp->f_pos < inode->i_size) {
  84                         de = (struct minix_dir_entry *) (offset + bh->b_data);
  85                         offset += info->s_dirsize;
  86                         filp->f_pos += info->s_dirsize;
  87 retry:
  88                         if (de->inode) {
  89                                 version = inode->i_version;
  90                                 for (i = 0; i < info->s_namelen; i++)
  91                                         if ((c = de->name[i]) != 0)
  92                                                 put_fs_byte(c,i+dirent->d_name);
  93                                         else
  94                                                 break;
  95                                 if (i) {
  96                                         put_fs_long(de->inode,&dirent->d_ino);
  97                                         put_fs_byte(0,i+dirent->d_name);
  98                                         put_fs_word(i,&dirent->d_reclen);
  99                                         if (version != inode->i_version)
 100                                                 goto retry;
 101                                         ret = ROUND_UP(NAME_OFFSET(dirent)+i+1);
 102                                 }
 103                         }
 104                 }
 105                 brelse(bh);
 106         }
 107         return ret;
 108 }

/* [previous][next][first][last][top][bottom][index][help] */