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

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