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         NULL                    /* permission */
  53 };
  54 
  55 static int msdos_readdir(struct inode *inode,struct file *filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  56     struct dirent *dirent,int count)
  57 {
  58         int ino,i,i2,last;
  59         char c,*walk;
  60         struct buffer_head *bh;
  61         struct msdos_dir_entry *de;
  62 
  63         if (!inode || !S_ISDIR(inode->i_mode)) return -EBADF;
  64         if (inode->i_ino == MSDOS_ROOT_INO) {
  65 /* Fake . and .. for the root directory. */
  66                 if (filp->f_pos == 2) filp->f_pos = 0;
  67                 else if (filp->f_pos < 2) {
  68                                 walk = filp->f_pos++ ? ".." : ".";
  69                                 for (i = 0; *walk; walk++)
  70                                         put_fs_byte(*walk,dirent->d_name+i++);
  71                                 put_fs_long(MSDOS_ROOT_INO,&dirent->d_ino);
  72                                 put_fs_byte(0,dirent->d_name+i);
  73                                 put_fs_word(i,&dirent->d_reclen);
  74                                 return i;
  75                         }
  76         }
  77         if (filp->f_pos & (sizeof(struct msdos_dir_entry)-1)) return -ENOENT;
  78         bh = NULL;
  79         while ((ino = msdos_get_entry(inode,&filp->f_pos,&bh,&de)) > -1) {
  80                 if (de->name[0] && ((unsigned char *) (de->name))[0] !=
  81                     DELETED_FLAG && !(de->attr & ATTR_VOLUME)) {
  82                         for (i = last = 0; i < 8; i++) {
  83                                 if (!(c = de->name[i])) break;
  84                                 if (c >= 'A' && c <= 'Z') c += 32;
  85                                 if (c != ' ') last = i+1;
  86                                 put_fs_byte(c,i+dirent->d_name);
  87                         }
  88                         i = last;
  89                         put_fs_byte('.',i+dirent->d_name);
  90                         i++;
  91                         for (i2 = 0; i2 < 3; i2++) {
  92                                 if (!(c = de->ext[i2])) break;
  93                                 if (c >= 'A' && c <= 'Z') c += 32;
  94                                 if (c != ' ') last = i+1;
  95                                 put_fs_byte(c,i+dirent->d_name);
  96                                 i++;
  97                         }
  98                         if ((i = last) != 0) {
  99                                 if (!strcmp(de->name,MSDOS_DOT))
 100                                         ino = inode->i_ino;
 101                                 else if (!strcmp(de->name,MSDOS_DOTDOT))
 102                                                 ino = msdos_parent_ino(inode,0);
 103                                 put_fs_long(ino,&dirent->d_ino);
 104                                 put_fs_byte(0,i+dirent->d_name);
 105                                 put_fs_word(i,&dirent->d_reclen);
 106                                 brelse(bh);
 107                                 return i;
 108                         }
 109                 }
 110         }
 111         if (bh) brelse(bh);
 112         return 0;
 113 }

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