root/fs/msdos/dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. msdos_dir_read
  2. msdos_readdir

   1 /*
   2  *  linux/fs/msdos/dir.c
   3  *
   4  *  Written 1992 by Werner Almesberger
   5  *
   6  *  MS-DOS directory handling functions
   7  */
   8 
   9 #include <asm/segment.h>
  10 
  11 #include <linux/sched.h>
  12 #include <linux/fs.h>
  13 #include <linux/msdos_fs.h>
  14 #include <linux/errno.h>
  15 #include <linux/stat.h>
  16 
  17 static int msdos_dir_read(struct inode * inode,struct file * filp, char * buf,int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19         return -EISDIR;
  20 }
  21 
  22 static int msdos_readdir(struct inode *inode,struct file *filp,
  23     struct dirent *dirent,int count);
  24 
  25 static struct file_operations msdos_dir_operations = {
  26         NULL,                   /* lseek - default */
  27         msdos_dir_read,         /* read */
  28         NULL,                   /* write - bad */
  29         msdos_readdir,          /* readdir */
  30         NULL,                   /* select - default */
  31         NULL,                   /* ioctl - default */
  32         NULL,                   /* mmap */
  33         NULL,                   /* no special open code */
  34         NULL                    /* no special release code */
  35 };
  36 
  37 struct inode_operations msdos_dir_inode_operations = {
  38         &msdos_dir_operations,  /* default directory file-ops */
  39         msdos_create,           /* create */
  40         msdos_lookup,           /* lookup */
  41         NULL,                   /* link */
  42         msdos_unlink,           /* unlink */
  43         NULL,                   /* symlink */
  44         msdos_mkdir,            /* mkdir */
  45         msdos_rmdir,            /* rmdir */
  46         NULL,                   /* mknod */
  47         msdos_rename,           /* rename */
  48         NULL,                   /* readlink */
  49         NULL,                   /* follow_link */
  50         msdos_bmap,             /* bmap */
  51         NULL                    /* truncate */
  52 };
  53 
  54 static int msdos_readdir(struct inode *inode,struct file *filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  55     struct dirent *dirent,int count)
  56 {
  57         int ino,i,i2,last;
  58         char c,*walk;
  59         struct buffer_head *bh;
  60         struct msdos_dir_entry *de;
  61 
  62         if (!inode || !S_ISDIR(inode->i_mode)) return -EBADF;
  63         if (inode->i_ino == MSDOS_ROOT_INO) {
  64 /* Fake . and .. for the root directory. */
  65                 if (filp->f_pos == 2) filp->f_pos = 0;
  66                 else if (filp->f_pos < 2) {
  67                                 walk = filp->f_pos++ ? ".." : ".";
  68                                 for (i = 0; *walk; walk++)
  69                                         put_fs_byte(*walk,dirent->d_name+i++);
  70                                 put_fs_long(MSDOS_ROOT_INO,&dirent->d_ino);
  71                                 put_fs_byte(0,dirent->d_name+i);
  72                                 put_fs_word(i,&dirent->d_reclen);
  73                                 return i;
  74                         }
  75         }
  76         if (filp->f_pos & (sizeof(struct msdos_dir_entry)-1)) return -ENOENT;
  77         bh = NULL;
  78         while ((ino = msdos_get_entry(inode,&filp->f_pos,&bh,&de)) > -1) {
  79                 if (de->name[0] && ((unsigned char *) (de->name))[0] !=
  80                     DELETED_FLAG && !(de->attr & ATTR_VOLUME)) {
  81                         for (i = last = 0; i < 8; i++) {
  82                                 if (!(c = de->name[i])) break;
  83                                 if (c >= 'A' && c <= 'Z') c += 32;
  84                                 if (c != ' ') last = i+1;
  85                                 put_fs_byte(c,i+dirent->d_name);
  86                         }
  87                         i = last;
  88                         put_fs_byte('.',i+dirent->d_name);
  89                         i++;
  90                         for (i2 = 0; i2 < 3; i2++) {
  91                                 if (!(c = de->ext[i2])) break;
  92                                 if (c >= 'A' && c <= 'Z') c += 32;
  93                                 if (c != ' ') last = i+1;
  94                                 put_fs_byte(c,i+dirent->d_name);
  95                                 i++;
  96                         }
  97                         if ((i = last) != 0) {
  98                                 if (!strcmp(de->name,MSDOS_DOT))
  99                                         ino = inode->i_ino;
 100                                 else if (!strcmp(de->name,MSDOS_DOTDOT))
 101                                                 ino = msdos_parent_ino(inode,0);
 102                                 put_fs_long(ino,&dirent->d_ino);
 103                                 put_fs_byte(0,i+dirent->d_name);
 104                                 put_fs_word(i,&dirent->d_reclen);
 105                                 brelse(bh);
 106                                 return i;
 107                         }
 108                 }
 109         }
 110         if (bh) brelse(bh);
 111         return 0;
 112 }

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