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

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