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
  14. init_module
  15. cleanup_module

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

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