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 #define PRINTK(X)
  22 
  23 static int msdos_dir_read(struct inode * inode,struct file * filp, char * buf,int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25         return -EISDIR;
  26 }
  27 
  28 static struct file_operations msdos_dir_operations = {
  29         NULL,                   /* lseek - default */
  30         msdos_dir_read,         /* read */
  31         NULL,                   /* write - bad */
  32         msdos_readdir,          /* readdir */
  33         NULL,                   /* select - default */
  34         NULL,                   /* ioctl - default */
  35         NULL,                   /* mmap */
  36         NULL,                   /* no special open code */
  37         NULL,                   /* no special release code */
  38         file_fsync              /* fsync */
  39 };
  40 
  41 struct inode_operations msdos_dir_inode_operations = {
  42         &msdos_dir_operations,  /* default directory file-ops */
  43         msdos_create,           /* create */
  44         msdos_lookup,           /* lookup */
  45         NULL,                   /* link */
  46         msdos_unlink,           /* unlink */
  47         NULL,                   /* symlink */
  48         msdos_mkdir,            /* mkdir */
  49         msdos_rmdir,            /* rmdir */
  50         NULL,                   /* mknod */
  51         msdos_rename,           /* rename */
  52         NULL,                   /* readlink */
  53         NULL,                   /* follow_link */
  54         msdos_bmap,             /* bmap */
  55         NULL,                   /* truncate */
  56         NULL                    /* permission */
  57 };
  58 
  59 int msdos_readdir(
     /* [previous][next][first][last][top][bottom][index][help] */
  60         struct inode *inode,
  61         struct file *filp,
  62         struct dirent *dirent,  /* dirent in user space */
  63         int count)
  64 {
  65         int ino,i,i2,last;
  66         char c,*walk;
  67         struct buffer_head *bh;
  68         struct msdos_dir_entry *de;
  69 
  70         if (!inode || !S_ISDIR(inode->i_mode)) return -EBADF;
  71         if (inode->i_ino == MSDOS_ROOT_INO) {
  72 /* Fake . and .. for the root directory. */
  73                 if (filp->f_pos == 2) filp->f_pos = 0;
  74                 else if (filp->f_pos < 2) {
  75                         walk = filp->f_pos++ ? ".." : ".";
  76                         for (i = 0; *walk; walk++)
  77                                 put_fs_byte(*walk,dirent->d_name+i++);
  78                         put_fs_long(MSDOS_ROOT_INO,&dirent->d_ino);
  79                         put_fs_byte(0,dirent->d_name+i);
  80                         put_fs_word(i,&dirent->d_reclen);
  81                         return ROUND_UP(NAME_OFFSET(dirent) + i + 1);
  82                 }
  83         }
  84         if (filp->f_pos & (sizeof(struct msdos_dir_entry)-1)) return -ENOENT;
  85         bh = NULL;
  86         while ((ino = msdos_get_entry(inode,&filp->f_pos,&bh,&de)) > -1) {
  87                 if (!IS_FREE(de->name) && !(de->attr & ATTR_VOLUME)) {
  88                         char bufname[13];
  89                         char *ptname = bufname;
  90                         for (i = last = 0; i < 8; i++) {
  91                                 if (!(c = de->name[i])) break;
  92                                 if (c >= 'A' && c <= 'Z') c += 32;
  93                                 if (c != ' ')
  94                                         last = i+1;
  95                                 ptname[i] = c;
  96                         }
  97                         i = last;
  98                         ptname[i] = '.';
  99                         i++;
 100                         for (i2 = 0; i2 < 3; i2++) {
 101                                 if (!(c = de->ext[i2])) break;
 102                                 if (c >= 'A' && c <= 'Z') c += 32;
 103                                 if (c != ' ')
 104                                         last = i+1;
 105                                 ptname[i] = c;
 106                                i++;
 107                         }
 108                         if ((i = last) != 0) {
 109                                 if (!strcmp(de->name,MSDOS_DOT))
 110                                         ino = inode->i_ino;
 111                                 else if (!strcmp(de->name,MSDOS_DOTDOT))
 112                                                 ino = msdos_parent_ino(inode,0);
 113                                 bufname[i] = '\0';
 114                                 put_fs_long(ino,&dirent->d_ino);
 115                                 memcpy_tofs(dirent->d_name,bufname,i+1);
 116                                 put_fs_word(i,&dirent->d_reclen);
 117                                 PRINTK (("readdir avant brelse\n"));
 118                                 brelse(bh);
 119                                 PRINTK (("readdir retourne %d\n",i));
 120                                 return ROUND_UP(NAME_OFFSET(dirent) + i + 1);
 121                         }
 122                 }
 123         }
 124         if (bh) brelse(bh);
 125         return 0;
 126 }

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