root/fs/umsdos/inode.c

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

DEFINITIONS

This source file includes following definitions.
  1. UMSDOS_put_inode
  2. UMSDOS_put_super
  3. UMSDOS_statfs
  4. umsdos_real_lookup
  5. umsdos_setup_dir_inode
  6. umsdos_set_dirinfo
  7. umsdos_isinit
  8. umsdos_patch_inode
  9. umsdos_get_dirowner
  10. UMSDOS_read_inode
  11. UMSDOS_write_inode
  12. UMSDOS_notify_change
  13. UMSDOS_read_super

   1 /*
   2  *  linux/fs/umsdos/inode.c
   3  *
   4  *      Written 1993 by Jacques Gelinas 
   5  *      Inspired from linux/fs/msdos/... by Werner Almesberger
   6  *
   7  */
   8 
   9 #include <stdlib.h>
  10 #include <linux/fs.h>
  11 #include <linux/msdos_fs.h>
  12 #include <linux/kernel.h>
  13 #include <linux/sched.h>
  14 #include <linux/errno.h>
  15 #include <asm/segment.h>
  16 #include <linux/string.h>
  17 #include <linux/ctype.h>
  18 #include <linux/stat.h>
  19 #include <linux/umsdos_fs.h>
  20 
  21 struct inode *pseudo_root=NULL;         /* Useful to simulate the pseudo DOS */
  22                                                                         /* directory. See UMSDOS_readdir_x() */
  23 
  24 /* #Specification: convention / PRINTK Printk and printk
  25         Here is the convention for the use of printk inside fs/umsdos
  26 
  27         printk carry important message (error or status).
  28         Printk is for debugging (it is a macro defined at the beginning of
  29                    most source.
  30         PRINTK is a nulled Printk macro.
  31 
  32         This convention makes the source easier to read, and Printk easier
  33         to shut off.
  34 */
  35 #define PRINTK(x)
  36 #define Printk(x) printk x
  37 
  38 
  39 void UMSDOS_put_inode(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  40 {
  41         PRINTK (("put inode %x owner %x pos %d dir %x\n",inode
  42                 ,inode->u.umsdos_i.i_emd_owner,inode->u.umsdos_i.pos
  43                 ,inode->u.umsdos_i.i_emd_dir));
  44         msdos_put_inode(inode);
  45 }
  46 
  47 
  48 void UMSDOS_put_super(struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50         msdos_put_super(sb);
  51 }
  52 
  53 
  54 void UMSDOS_statfs(struct super_block *sb,struct statfs *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         msdos_statfs(sb,buf);
  57 }
  58 
  59 
  60 /*
  61         Call msdos_lookup, but set back the original msdos function table.
  62         Return 0 if ok, or a negative error code if not.
  63 */
  64 int umsdos_real_lookup (
     /* [previous][next][first][last][top][bottom][index][help] */
  65         struct inode *dir,
  66         const char *name,
  67         int len,
  68         struct inode **result)  /* Will hold inode of the file, if successful */
  69 {
  70         int ret;
  71         dir->i_count++;
  72         ret = msdos_lookup (dir,name,len,result);
  73         return ret;
  74 }
  75 /*
  76         Complete the setup of an directory inode.
  77         First, it completes the function pointers, then
  78         it locates the EMD file. If the EMD is there, then plug the
  79         umsdos function table. If not, use the msdos one.
  80 */
  81 void umsdos_setup_dir_inode (struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  82 {
  83         inode->u.umsdos_i.i_emd_dir = 0;
  84         {
  85                 struct inode *emd_dir = umsdos_emd_dir_lookup (inode,0);
  86                 extern struct inode_operations umsdos_rdir_inode_operations;
  87                 inode->i_op = emd_dir != NULL
  88                         ? &umsdos_dir_inode_operations
  89                         : &umsdos_rdir_inode_operations;
  90                 iput (emd_dir);
  91         }
  92 }
  93 /*
  94         Add some info into an inode so it can find its owner quickly
  95 */
  96 void umsdos_set_dirinfo(
     /* [previous][next][first][last][top][bottom][index][help] */
  97         struct inode *inode,
  98         struct inode *dir,
  99         off_t f_pos)
 100 {
 101         struct inode *emd_owner = umsdos_emd_dir_lookup(dir,1);
 102         inode->u.umsdos_i.i_dir_owner = dir->i_ino;
 103         inode->u.umsdos_i.i_emd_owner = emd_owner->i_ino;
 104         iput (emd_owner);
 105         inode->u.umsdos_i.pos = f_pos;
 106 }
 107 /*
 108         Tells if an Umsdos inode has been "patched" once.
 109         Return != 0 if so.
 110 */
 111 int umsdos_isinit (struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 112 {
 113 #if     1
 114         return inode->u.umsdos_i.i_emd_owner != 0;
 115 #elif 0
 116         return inode->i_atime != 0;
 117 #else
 118         return inode->i_count > 1;
 119 #endif
 120 }
 121 /*
 122         Connect the proper tables in the inode and add some info.
 123 */
 124 void umsdos_patch_inode (
     /* [previous][next][first][last][top][bottom][index][help] */
 125         struct inode *inode,
 126         struct inode *dir,              /* May be NULL */
 127         off_t f_pos)
 128 {
 129         /*
 130                 This function is called very early to setup the inode, somewhat
 131                 too early (called by UMSDOS_read_inode). At this point, we can't
 132                 do to much, such as lookup up EMD files and so on. This causes
 133                 confusion in the kernel. This is why some initialisation
 134                 will be done when dir != NULL only.
 135 
 136                 UMSDOS do run piggy back on top of msdos fs. It looks like something
 137                 is missing in the VFS to accommodate stacked fs. Still unclear what
 138                 (quite honestly).
 139 
 140                 Well, maybe one! A new entry "may_unmount" which would allow
 141                 the stacked fs to allocate some inode permanently and release
 142                 them at the end. Doing that now introduce a problem. unmount
 143                 always fail because some inodes are in use.
 144         */
 145         if (!umsdos_isinit(inode)){
 146                 inode->u.umsdos_i.i_emd_dir = 0;
 147                 if (S_ISREG(inode->i_mode)){
 148                         static char is_init = 0;
 149                         if (!is_init){
 150                                 /*
 151                                         I don't want to change the msdos file system code
 152                                         so I get the address of some subroutine dynamically
 153                                         once.
 154                                 */
 155                                 umsdos_file_inode_operations.bmap = inode->i_op->bmap;
 156                                 inode->i_op = &umsdos_file_inode_operations;
 157                                 is_init = 1;
 158                         }
 159                         inode->i_op = &umsdos_file_inode_operations;
 160                 }else if (S_ISDIR(inode->i_mode)){
 161                         if (dir != NULL){
 162                                 umsdos_setup_dir_inode(inode);
 163                         }
 164                 }else if (S_ISLNK(inode->i_mode)){
 165                         inode->i_op = &umsdos_symlink_inode_operations;
 166                 }else if (S_ISCHR(inode->i_mode)){
 167                         inode->i_op = &chrdev_inode_operations;
 168                 }else if (S_ISBLK(inode->i_mode)){
 169                         inode->i_op = &blkdev_inode_operations;
 170                 }else if (S_ISFIFO(inode->i_mode)){
 171                         init_fifo(inode);
 172                 }
 173                 if (dir != NULL){
 174                         /* #Specification: inode / umsdos info
 175                                 The first time an inode is seen (inode->i_count == 1),
 176                                 the inode number of the EMD file which control this inode
 177                                 is tagged to this inode. It allows operation such
 178                                 as notify_change to be handled.
 179                         */
 180                         /*
 181                                 This is done last because it also control the
 182                                 status of umsdos_isinit()
 183                         */
 184                         umsdos_set_dirinfo (inode,dir,f_pos);
 185                 }
 186         }else if (dir != NULL){
 187                 /*
 188                         Test to see if the info is maintained.
 189                         This should be removed when the file system will be proven.
 190                 */
 191                 struct inode *emd_owner = umsdos_emd_dir_lookup(dir,1);
 192                 iput (emd_owner);
 193                 if (emd_owner->i_ino != inode->u.umsdos_i.i_emd_owner){
 194                         printk ("UMSDOS: *** EMD_OWNER ??? *** ino = %ld %ld <> %ld "
 195                                 ,inode->i_ino,emd_owner->i_ino,inode->u.umsdos_i.i_emd_owner);
 196                 }
 197         }
 198 }
 199 /*
 200         Get the inode of the directory which owns this inode.
 201         Return 0 if ok, -EIO if error.
 202 */
 203 int umsdos_get_dirowner(
     /* [previous][next][first][last][top][bottom][index][help] */
 204         struct inode *inode,
 205         struct inode **result)  /* Hold NULL if any error */
 206                                                         /* else, the inode of the directory */
 207 {
 208         int ret = -EIO;
 209         unsigned long ino = inode->u.umsdos_i.i_dir_owner;
 210         *result = NULL;
 211         if (ino == 0){
 212                 printk ("UMSDOS: umsdos_get_dirowner ino == 0\n");
 213         }else{
 214                 struct inode *dir = *result = iget(inode->i_sb,ino);
 215                 if (dir != NULL){
 216                         umsdos_patch_inode (dir,NULL,0);
 217                         ret = 0;
 218                 }
 219         }
 220         return ret;
 221 }
 222 /*
 223         Load an inode from disk.
 224 */
 225 void UMSDOS_read_inode(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 226 {
 227         PRINTK (("read inode %x ino = %d ",inode,inode->i_ino));
 228         msdos_read_inode(inode);
 229         PRINTK (("ino = %d %d\n",inode->i_ino,inode->i_count));
 230         if (S_ISDIR(inode->i_mode)
 231                 && (inode->u.umsdos_i.u.dir_info.creating != 0
 232                         || inode->u.umsdos_i.u.dir_info.looking != 0
 233                         || inode->u.umsdos_i.u.dir_info.p != NULL)){
 234                 Printk (("read inode %d %d %p\n"
 235                         ,inode->u.umsdos_i.u.dir_info.creating
 236                         ,inode->u.umsdos_i.u.dir_info.looking
 237                         ,inode->u.umsdos_i.u.dir_info.p));
 238         }
 239         /* #Specification: Inode / post initialisation
 240                 To completely initialise an inode, we need access to the owner
 241                 directory, so we can locate more info in the EMD file. This is
 242                 not available the first time the inode is access, we use
 243                 a value in the inode to tell if it has been finally initialised.
 244 
 245                 At first, we have tried testing i_count but it was causing
 246                 problem. It is possible that two or more process use the
 247                 newly accessed inode. While the first one block during
 248                 the initialisation (probably while reading the EMD file), the
 249                 others believe all is well because i_count > 1. They go banana
 250                 with a broken inode. See umsdos_lookup_patch and umsdos_patch_inode.
 251         */
 252         umsdos_patch_inode(inode,NULL,0);
 253 }
 254 
 255 /*
 256         Update the disk with the inode content
 257 */
 258 void UMSDOS_write_inode(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 259 {
 260         PRINTK (("UMSDOS_write_inode emd %d\n",inode->u.umsdos_i.i_emd_owner));
 261         msdos_write_inode(inode);
 262         UMSDOS_notify_change (NOTIFY_TIME,inode);
 263 }
 264 int UMSDOS_notify_change (int flags, struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 265 {
 266         int ret = 0;
 267         if (inode->i_nlink > 0){
 268                 /* #Specification: notify_change / i_nlink > 0
 269                         notify change is only done for inode with nlink > 0. An inode
 270                         with nlink == 0 is no longer associated with any entry in
 271                         the EMD file, so there is nothing to update.
 272                 */
 273                 unsigned long i_emd_owner = inode->u.umsdos_i.i_emd_owner;
 274                 if (inode == inode->i_sb->s_mounted){
 275                         /* #Specification: root inode / attributes
 276                                 I don't know yet how this should work. Normally
 277                                 the attributes (permissions bits, owner, times) of
 278                                 a directory are stored in the EMD file of its parent.
 279 
 280                                 One thing we could do is store the attributes of the root
 281                                 inode in its own EMD file. A simple entry named "." could
 282                                 be used for this special case. It would be read once
 283                                 when the file system is mounted and update in
 284                                 UMSDOS_notify_change() (right here).
 285 
 286                                 I am not sure of the behavior of the root inode for
 287                                 a real UNIX file system. For now, this is a nop.
 288                         */
 289                 }else if (i_emd_owner != 0xffffffff && i_emd_owner != 0){
 290                         /* This inode is not a EMD file nor an inode used internally
 291                                 by MSDOS, so we can update its status.
 292                                 See emd.c
 293                         */
 294                         struct inode *emd_owner = iget (inode->i_sb,i_emd_owner);
 295                         PRINTK (("notify change %p ",inode));
 296                         if (emd_owner == NULL){
 297                                 printk ("UMSDOS: emd_owner = NULL ???");
 298                                 ret = -EPERM;
 299                         }else{
 300                                 struct file filp;
 301                                 struct umsdos_dirent entry;
 302                                 filp.f_pos = inode->u.umsdos_i.pos;
 303                                 PRINTK (("pos = %d ",filp.f_pos));
 304                                 /* Read only the start of the entry since we don't touch */
 305                                 /* the name */
 306                                 ret = umsdos_emd_dir_read (emd_owner,&filp,(char*)&entry
 307                                         ,UMSDOS_REC_SIZE);
 308                                 if (ret == 0){
 309                                         if (flags & NOTIFY_UIDGID){
 310                                                 entry.uid = inode->i_uid;
 311                                                 entry.gid = inode->i_gid;
 312                                                 /* Remove those flags msdos don't like */
 313                                                 flags &= ~NOTIFY_UIDGID;
 314                                         }
 315                                         if (flags & NOTIFY_MODE){
 316                                                 entry.mode = inode->i_mode;
 317                                                 flags &= ~NOTIFY_MODE;
 318                                         }
 319                                         if (flags & NOTIFY_TIME){
 320                                                 entry.atime = inode->i_atime;
 321                                                 entry.mtime = inode->i_mtime;
 322                                                 entry.ctime = inode->i_ctime;
 323                                         }
 324                                         entry.nlink = inode->i_nlink;
 325                                         filp.f_pos = inode->u.umsdos_i.pos;
 326                                         ret = umsdos_emd_dir_write (emd_owner,&filp,(char*)&entry
 327                                                 ,UMSDOS_REC_SIZE);
 328                                         PRINTK (("notify pos %d ret %d nlink %d "
 329                                                 ,inode->u.umsdos_i.pos
 330                                                 ,ret,entry.nlink));
 331                                         /* #Specification: notify_change / msdos fs
 332                                                 notify_change operation are done only on the
 333                                                 EMD file. The msdos fs is not even called.
 334                                         */
 335                                         #if 0
 336                                         if (ret == 0
 337                                                 && (S_ISDIR(inode->i_mode)
 338                                                         || S_ISREG(inode->i_mode))){
 339                                                 ret = msdos_notify_change(flags, inode);
 340                                                 printk ("msdos_notify %x %d",inode,ret);
 341                                         }
 342                                         #endif
 343                                 }
 344                                 iput (emd_owner);
 345                         }
 346                         PRINTK (("\n"));
 347                 }
 348         }
 349         return ret;
 350 }
 351 
 352 /* #Specification: function name / convention
 353         A simple convention for function name has been used in
 354         the UMSDOS file system. First all function use the prefix
 355         umsdos_ to avoid name clash with other part of the kernel.
 356 
 357         And standard VFS entry point use the prefix UMSDOS (upper case)
 358         so it's easier to tell them apart.
 359 */
 360 
 361 static struct super_operations umsdos_sops = { 
 362         UMSDOS_read_inode,
 363         UMSDOS_notify_change,
 364         UMSDOS_write_inode,
 365         UMSDOS_put_inode,
 366         UMSDOS_put_super,
 367         NULL, /* added in 0.96c */
 368         UMSDOS_statfs,
 369         NULL
 370 };
 371 
 372 /*
 373         Read the super block of an Extended MS-DOS FS.
 374 */
 375 struct super_block *UMSDOS_read_super(
     /* [previous][next][first][last][top][bottom][index][help] */
 376         struct super_block *s,
 377         void *data,
 378         int silent)
 379 {
 380         /* #Specification: mount / options
 381                 Umsdos run on top of msdos. Currently, it supports no
 382                 mount option, but happily pass all option received to
 383                 the msdos driver. I am not sure if all msdos mount option
 384                 make sense with Umsdos. Here are at least those who
 385                 are useful.
 386                         uid=
 387                         gid=
 388 
 389                 These options affect the operation of umsdos in directories
 390                 which do not have an EMD file. They behave like normal
 391                 msdos directory, with all limitation of msdos.
 392         */
 393         struct super_block *sb = msdos_read_super(s,data,silent);
 394         printk ("UMSDOS Alpha 0.4 (compatibility level %d.%d)\n"
 395                 ,UMSDOS_VERSION,UMSDOS_RELEASE);
 396         if (sb != NULL){
 397                 sb->s_op = &umsdos_sops;
 398                 PRINTK (("umsdos_read_super %p\n",sb->s_mounted));
 399                 umsdos_setup_dir_inode (sb->s_mounted);
 400                 PRINTK (("End umsdos_read_super\n"));
 401                 if (s == super_blocks){
 402                         /* #Specification: pseudo root / mount
 403                                 When a umsdos fs is mounted, a special handling is done
 404                                 if it is the root partition. We check for the presence
 405                                 of the file /linux/etc/init or /linux/etc/rc.
 406                                 If one is there, we do a chroot("/linux").
 407 
 408                                 We check both because (see init/main.c) the kernel
 409                                 try to exec init at different place and if it fails
 410                                 it tries /bin/sh /etc/rc. To be consistent with
 411                                 init/main.c, many more test would have to be done
 412                                 to locate init. Any complain ?
 413 
 414                                 The chroot is done manually in init/main.c but the
 415                                 info (the inode) is located at mount time and store
 416                                 in a global variable (pseudo_root) which is used at
 417                                 different place in the umsdos driver. There is no
 418                                 need to store this variable elsewhere because it
 419                                 will always be one, not one per mount.
 420 
 421                                 This feature allows the installation
 422                                 of a linux system within a DOS system in a subdirectory.
 423         
 424                                 A user may install its linux stuff in c:\linux
 425                                 avoiding any clash with existing DOS file and subdirectory.
 426                                 When linux boots, it hides this fact, showing a normal
 427                                 root directory with /etc /bin /tmp ...
 428 
 429                                 The word "linux" is hardcoded in /usr/include/linux/umsdos_fs.h
 430                                 in the macro UMSDOS_PSDROOT_NAME.
 431                         */
 432 
 433                         struct inode *pseudo;
 434                         Printk (("Mounting root\n"));
 435                         if (umsdos_real_lookup (sb->s_mounted,UMSDOS_PSDROOT_NAME
 436                                         ,UMSDOS_PSDROOT_LEN,&pseudo)==0
 437                                 && S_ISDIR(pseudo->i_mode)){
 438                                 struct inode *etc = NULL;
 439                                 struct inode *rc = NULL;
 440                                 Printk (("/%s is there\n",UMSDOS_PSDROOT_NAME));
 441                                 if (umsdos_real_lookup (pseudo,"etc",3,&etc)==0
 442                                         && S_ISDIR(etc->i_mode)){
 443                                         struct inode *init;
 444                                         Printk (("/%s/etc is there\n",UMSDOS_PSDROOT_NAME));
 445                                         if ((umsdos_real_lookup (etc,"init",4,&init)==0
 446                                                         && S_ISREG(init->i_mode))
 447                                                 || (umsdos_real_lookup (etc,"rc",2,&rc)==0
 448                                                         && S_ISREG(rc->i_mode))){
 449                                                 umsdos_setup_dir_inode (pseudo);
 450                                                 Printk (("Activating pseudo root /%s\n",UMSDOS_PSDROOT_NAME));
 451                                                 pseudo_root = pseudo;
 452                                                 pseudo->i_count++;
 453                                                 pseudo = NULL;
 454                                         }
 455                                         iput (init);
 456                                         iput (rc);
 457                                 }
 458                                 iput (etc);
 459                         }
 460                         iput (pseudo);
 461                 }
 462         }
 463         return sb;
 464 }
 465 
 466 

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