Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | /* * linux/fs/umsdos/inode.c * * Written 1993 by Jacques Gelinas * Inspired from linux/fs/msdos/... by Werner Almesberger */ #include <linux/module.h> #include <linux/init.h> #include <linux/fs.h> #include <linux/msdos_fs.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/errno.h> #include <asm/uaccess.h> #include <linux/string.h> #include <linux/stat.h> #include <linux/umsdos_fs.h> #include <linux/list.h> extern struct dentry_operations umsdos_dentry_operations; extern struct inode_operations umsdos_rdir_inode_operations; struct dentry *saved_root = NULL; /* Original root if changed */ struct inode *pseudo_root = NULL; /* Useful to simulate the pseudo DOS */ /* directory. See UMSDOS_readdir_x() */ static struct dentry *check_pseudo_root(struct super_block *); /* * Initialize a private filp */ void fill_new_filp (struct file *filp, struct dentry *dentry) { if (!dentry) printk(KERN_ERR "fill_new_filp: NULL dentry!\n"); memset (filp, 0, sizeof (struct file)); filp->f_reada = 1; filp->f_flags = O_RDWR; filp->f_dentry = dentry; filp->f_op = &umsdos_file_operations; } void UMSDOS_put_inode (struct inode *inode) { PRINTK ((KERN_DEBUG "put inode %p (%lu) owner %lu pos %lu dir %lu count=%d\n" ,inode, inode->i_ino ,inode->u.umsdos_i.i_emd_owner, inode->u.umsdos_i.pos ,inode->u.umsdos_i.i_emd_dir, inode->i_count)); if (inode == pseudo_root) { printk (KERN_ERR "Umsdos: Oops releasing pseudo_root." " Notify jacques@solucorp.qc.ca\n"); } inode->u.umsdos_i.i_patched = 0; fat_put_inode (inode); } void UMSDOS_put_super (struct super_block *sb) { Printk ((KERN_DEBUG "UMSDOS_put_super: entering\n")); if (saved_root) { shrink_dcache_parent(saved_root); printk("UMSDOS_put_super: freeing saved root, d_count=%d\n", saved_root->d_count); dput(saved_root); saved_root = NULL; pseudo_root = NULL; } msdos_put_super (sb); MOD_DEC_USE_COUNT; } /* * Complete the setup of a directory dentry based on its * EMD/non-EMD status. If it has an EMD, then plug the * umsdos function table. If not, use the msdos one. */ void umsdos_setup_dir(struct dentry *dir) { struct inode *inode = dir->d_inode; if (!S_ISDIR(inode->i_mode)) printk(KERN_ERR "umsdos_setup_dir: %s/%s not a dir!\n", dir->d_parent->d_name.name, dir->d_name.name); inode->u.umsdos_i.i_emd_dir = 0; inode->i_op = &umsdos_rdir_inode_operations; if (umsdos_have_emd(dir)) { Printk((KERN_DEBUG "umsdos_setup_dir: %s/%s using EMD\n", dir->d_parent->d_name.name, dir->d_name.name)); inode->i_op = &umsdos_dir_inode_operations; } } /* * Add some info into an inode so it can find its owner quickly */ void umsdos_set_dirinfo_new (struct dentry *dentry, off_t f_pos) { struct inode *inode = dentry->d_inode; struct dentry *demd; inode->u.umsdos_i.i_emd_owner = 0; inode->u.umsdos_i.pos = f_pos; /* now check the EMD file */ demd = umsdos_get_emd_dentry(dentry->d_parent); if (!IS_ERR(demd)) { if (demd->d_inode) inode->u.umsdos_i.i_emd_owner = demd->d_inode->i_ino; dput(demd); } return; } /* * Connect the proper tables in the inode and add some info. */ /* #Specification: inode / umsdos info * The first time an inode is seen (inode->i_count == 1), * the inode number of the EMD file which controls this inode * is tagged to this inode. It allows operations such as * notify_change to be handled. */ void umsdos_patch_dentry_inode(struct dentry *dentry, off_t f_pos) { struct inode *inode = dentry->d_inode; PRINTK (("umsdos_patch_dentry_inode: inode=%lu\n", inode->i_ino)); /* * Classify the inode based on EMD/non-EMD status. */ PRINTK (("umsdos_patch_inode: call umsdos_set_dirinfo_new(%p,%lu)\n", dentry, f_pos)); umsdos_set_dirinfo_new(dentry, f_pos); inode->u.umsdos_i.i_emd_dir = 0; if (S_ISREG (inode->i_mode)) { if (MSDOS_SB (inode->i_sb)->cvf_format) { if (MSDOS_SB (inode->i_sb)->cvf_format->flags & CVF_USE_READPAGE) { inode->i_op = &umsdos_file_inode_operations_readpage; } else { inode->i_op = &umsdos_file_inode_operations_no_bmap; } } else { if (inode->i_op->bmap != NULL) { inode->i_op = &umsdos_file_inode_operations; } else { inode->i_op = &umsdos_file_inode_operations_no_bmap; } } } else if (S_ISDIR (inode->i_mode)) { umsdos_setup_dir(dentry); } else if (S_ISLNK (inode->i_mode)) { inode->i_op = &umsdos_symlink_inode_operations; } else if (S_ISCHR (inode->i_mode)) { inode->i_op = &chrdev_inode_operations; } else if (S_ISBLK (inode->i_mode)) { inode->i_op = &blkdev_inode_operations; } else if (S_ISFIFO (inode->i_mode)) { init_fifo (inode); } } /* * Load an inode from disk. */ /* #Specification: Inode / post initialisation * To completely initialise an inode, we need access to the owner * directory, so we can locate more info in the EMD file. This is * not available the first time the inode is accessed, so we use * a value in the inode to tell if it has been finally initialised. * * New inodes are obtained by the lookup and create routines, and * each of these must ensure that the inode gets patched. */ void UMSDOS_read_inode (struct inode *inode) { Printk ((KERN_DEBUG "UMSDOS_read_inode %p ino = %lu ", inode, inode->i_ino)); msdos_read_inode (inode); /* inode needs patching */ inode->u.umsdos_i.i_patched = 0; } int umsdos_notify_change_locked(struct dentry *, struct iattr *); /* * lock the parent dir before starting ... */ int UMSDOS_notify_change (struct dentry *dentry, struct iattr *attr) { struct inode *dir = dentry->d_parent->d_inode; int ret; down(&dir->i_sem); ret = umsdos_notify_change_locked(dentry, attr); up(&dir->i_sem); return ret; } /* * Must be called with the parent lock held. */ int umsdos_notify_change_locked(struct dentry *dentry, struct iattr *attr) { struct inode *inode = dentry->d_inode; struct dentry *demd; int ret; struct file filp; struct umsdos_dirent entry; Printk(("UMSDOS_notify_change: entering for %s/%s (%d)\n", dentry->d_parent->d_name.name, dentry->d_name.name, inode->u.umsdos_i.i_patched)); ret = inode_change_ok (inode, attr); if (ret) { printk("UMSDOS_notify_change: %s/%s change not OK, ret=%d\n", dentry->d_parent->d_name.name, dentry->d_name.name, ret); goto out; } if (inode->i_nlink == 0) goto out; if (inode->i_ino == UMSDOS_ROOT_INO) goto out; /* get the EMD file dentry */ demd = umsdos_get_emd_dentry(dentry->d_parent); ret = PTR_ERR(demd); if (IS_ERR(demd)) goto out; ret = -EPERM; if (!demd->d_inode) { printk(KERN_WARNING "UMSDOS_notify_change: no EMD file %s/%s\n", demd->d_parent->d_name.name, demd->d_name.name); goto out_dput; } ret = 0; /* don't do anything if this is the EMD itself */ if (inode == demd->d_inode) goto out_dput; /* This inode is not a EMD file nor an inode used internally * by MSDOS, so we can update its status. * See emd.c */ fill_new_filp (&filp, demd); filp.f_pos = inode->u.umsdos_i.pos; Printk(("UMSDOS_notify_change: %s/%s reading at %d\n", dentry->d_parent->d_name.name, dentry->d_name.name, (int) filp.f_pos)); /* Read only the start of the entry since we don't touch the name */ ret = umsdos_emd_dir_read (&filp, (char *) &entry, UMSDOS_REC_SIZE); if (ret) { printk(KERN_WARNING "umsdos_notify_change: %s/%s EMD read error, ret=%d\n", dentry->d_parent->d_name.name, dentry->d_name.name,ret); goto out_dput; } if (attr->ia_valid & ATTR_UID) entry.uid = attr->ia_uid; if (attr->ia_valid & ATTR_GID) entry.gid = attr->ia_gid; if (attr->ia_valid & ATTR_MODE) entry.mode = attr->ia_mode; if (attr->ia_valid & ATTR_ATIME) entry.atime = attr->ia_atime; if (attr->ia_valid & ATTR_MTIME) entry.mtime = attr->ia_mtime; if (attr->ia_valid & ATTR_CTIME) entry.ctime = attr->ia_ctime; entry.nlink = inode->i_nlink; filp.f_pos = inode->u.umsdos_i.pos; ret = umsdos_emd_dir_write (&filp, (char *) &entry, UMSDOS_REC_SIZE); if (ret) printk(KERN_WARNING "umsdos_notify_change: %s/%s EMD write error, ret=%d\n", dentry->d_parent->d_name.name, dentry->d_name.name,ret); Printk (("notify pos %lu ret %d nlink %d ", inode->u.umsdos_i.pos, ret, entry.nlink)); /* #Specification: notify_change / msdos fs * notify_change operation are done only on the * EMD file. The msdos fs is not even called. */ #ifdef UMSDOS_DEBUG_VERBOSE if (entry.flags & UMSDOS_HIDDEN) printk("umsdos_notify_change: %s/%s hidden, nlink=%d, ret=%d\n", dentry->d_parent->d_name.name, dentry->d_name.name, entry.nlink, ret); #endif out_dput: dput(demd); out: if (ret == 0) inode_setattr (inode, attr); return ret; } /* * Update the disk with the inode content */ void UMSDOS_write_inode (struct inode *inode) { struct iattr newattrs; PRINTK (("UMSDOS_write_inode emd %d (FIXME: missing notify_change)\n", inode->u.umsdos_i.i_emd_owner)); fat_write_inode (inode); newattrs.ia_mtime = inode->i_mtime; newattrs.ia_atime = inode->i_atime; newattrs.ia_ctime = inode->i_ctime; newattrs.ia_valid = ATTR_MTIME | ATTR_ATIME | ATTR_CTIME; /* * UMSDOS_notify_change is convenient to call here * to update the EMD entry associated with this inode. * But it has the side effect to re"dirt" the inode. */ /* * UMSDOS_notify_change (inode, &newattrs); * inode->i_state &= ~I_DIRTY; / * FIXME: this doesn't work. We need to remove ourselves from list on dirty inodes. /mn/ */ } static struct super_operations umsdos_sops = { UMSDOS_read_inode, /* read_inode */ UMSDOS_write_inode, /* write_inode */ UMSDOS_put_inode, /* put_inode */ fat_delete_inode, /* delete_inode */ UMSDOS_notify_change, /* notify_change */ UMSDOS_put_super, /* put_super */ NULL, /* write_super */ fat_statfs, /* statfs */ NULL /* remount_fs */ }; /* * Read the super block of an Extended MS-DOS FS. */ struct super_block *UMSDOS_read_super (struct super_block *sb, void *data, int silent) { struct super_block *res; struct dentry *new_root; MOD_INC_USE_COUNT; MSDOS_SB(sb)->options.isvfat = 0; /* * Call msdos-fs to mount the disk. * Note: this returns res == sb or NULL */ res = msdos_read_super (sb, data, silent); if (!res) goto out_fail; printk (KERN_INFO "UMSDOS dentry-pre 0.84 " "(compatibility level %d.%d, fast msdos)\n", UMSDOS_VERSION, UMSDOS_RELEASE); sb->s_op = &umsdos_sops; MSDOS_SB(sb)->options.dotsOK = 0; /* disable hidden==dotfile */ /* install our dentry operations ... */ sb->s_root->d_op = &umsdos_dentry_operations; umsdos_patch_dentry_inode(sb->s_root, 0); /* Check whether to change to the /linux root */ new_root = check_pseudo_root(sb); if (new_root) { /* sanity check */ if (new_root->d_op != &umsdos_dentry_operations) printk("umsdos_read_super: pseudo-root wrong ops!\n"); pseudo_root = new_root->d_inode; saved_root = sb->s_root; sb->s_root = new_root; printk(KERN_INFO "UMSDOS: changed to alternate root\n"); } /* if d_count is not 1, mount will fail with -EBUSY! */ if (sb->s_root->d_count > 1) { shrink_dcache_sb(sb); if (sb->s_root->d_count > 1) { printk(KERN_ERR "UMSDOS: root count %d > 1 !", sb->s_root->d_count); } } return sb; out_fail: printk(KERN_INFO "UMSDOS: msdos_read_super failed, mount aborted.\n"); sb->s_dev = 0; MOD_DEC_USE_COUNT; return NULL; } /* * Check for an alternate root if we're the root device. */ static struct dentry *check_pseudo_root(struct super_block *sb) { struct dentry *root, *init; /* * Check whether we're mounted as the root device. * If so, this should be the only superblock. */ if (sb->s_list.next->next != &sb->s_list) goto out_noroot; printk("check_pseudo_root: mounted as root\n"); root = lookup_dentry(UMSDOS_PSDROOT_NAME, dget(sb->s_root), 0); if (IS_ERR(root)) goto out_noroot; if (!root->d_inode) goto out_dput; printk("check_pseudo_root: found %s/%s\n", root->d_parent->d_name.name, root->d_name.name); /* look for /sbin/init */ init = lookup_dentry("sbin/init", dget(root), 0); if (!IS_ERR(init)) { if (init->d_inode) goto root_ok; dput(init); } /* check for other files? */ goto out_dput; root_ok: printk("check_pseudo_root: found %s/%s, enabling pseudo-root\n", init->d_parent->d_name.name, init->d_name.name); dput(init); return root; /* Alternate root not found ... */ out_dput: dput(root); out_noroot: return NULL; } static struct file_system_type umsdos_fs_type = { "umsdos", FS_REQUIRES_DEV, UMSDOS_read_super, NULL }; __initfunc (int init_umsdos_fs (void)) { return register_filesystem (&umsdos_fs_type); } #ifdef MODULE EXPORT_NO_SYMBOLS; int init_module (void) { return init_umsdos_fs (); } void cleanup_module (void) { unregister_filesystem (&umsdos_fs_type); } #endif |