Print this page
PSARC 2008/290 lofi mount
6384817 Need persistent lofi based mounts and direct mount(1m) support for lofi


   9 
  10 /*
  11  * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
  12  * All rights reserved.
  13  *
  14  * Redistribution and use in source and binary forms are permitted
  15  * provided that: (1) source distributions retain this entire copyright
  16  * notice and comment, and (2) distributions including binaries display
  17  * the following acknowledgement:  ``This product includes software
  18  * developed by the University of California, Berkeley and its contributors''
  19  * in the documentation or other materials provided with the distribution
  20  * and in all advertising materials mentioning features or use of this
  21  * software. Neither the name of the University nor the names of its
  22  * contributors may be used to endorse or promote products derived
  23  * from this software without specific prior written permission.
  24  * THIS SOFTWARE IS PROVIDED '`AS IS'' AND WITHOUT ANY EXPRESS OR
  25  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27  */
  28 
  29 #pragma ident   "@(#)main.c     1.54    08/02/06 SMI"
  30 
  31 /*
  32  * In-core structures:
  33  * blockmap[]
  34  *      A bitmap of block usage very similar to what's on disk, but
  35  *      for the entire filesystem rather than just a cylinder group.
  36  *      Zero indicates free, one indicates allocated.  Note that this
  37  *      is opposite the interpretation of a cylinder group's free block
  38  *      bitmap.
  39  *
  40  * statemap[]
  41  *      Tracks what is known about each inode in the filesystem.
  42  *      The fundamental state value is one of USTATE, FSTATE, DSTATE,
  43  *      or SSTATE (unallocated, file, directory, shadow/acl).
  44  *
  45  *      There are optional modifying attributes as well: INZLINK,
  46  *      INFOUND, INCLEAR, INORPHAN, and INDELAYD.  The IN prefix
  47  *      stands for inode.  INZLINK declares that no links (di_nlink ==
  48  *      0) to the inode have been found.  It is used instead of
  49  *      examining di_nlink because we've always got the statemap[] in


 679 /*
 680  * fsck -m: does the filesystem pass cursory examination
 681  *
 682  * XXX This is very redundant with setup().  The right thing would be
 683  *     for setup() to modify its behaviour when mflag is set (less
 684  *     chatty, exit instead of return, etc).
 685  */
 686 void
 687 check_sanity(char *filename)
 688 {
 689         struct stat64 stbd, stbr;
 690         char *devname;
 691         struct ustat usb;
 692         char vfsfilename[MAXPATHLEN];
 693         struct vfstab vfsbuf;
 694         FILE *vfstab;
 695         struct statvfs vfs_stat;
 696         int found_magic[MAGIC_LIMIT];
 697         int magic_cnt;
 698         int is_magic = 0;
 699         int is_block;

 700 
 701         (void) memset((void *)found_magic, 0, sizeof (found_magic));
 702 
 703         if (stat64(filename, &stbd) < 0) {
 704                 (void) fprintf(stderr,
 705                 "ufs fsck: sanity check failed : cannot stat %s\n", filename);
 706                 exit(EXNOSTAT);
 707         }
 708 
 709         if ((stbd.st_mode & S_IFMT) == S_IFBLK) {
 710                 is_block = 1;
 711         } else if ((stbd.st_mode & S_IFMT) == S_IFCHR) {
 712                 is_block = 0;
 713         } else {
 714                 /*
 715                  * In !mflag mode, we allow checking the contents
 716                  * of a file.  Since this is intended primarily for
 717                  * speeding up boot-time checks and allowing for a
 718                  * file complicates the ok-input tests, we'll disallow
 719                  * that option.
 720                  */
 721                 (void) fprintf(stderr,
 722                     "ufs fsck: sanity check failed: "
 723                     "%s not block or character device\n", filename);
 724                 exit(EXNOSTAT);
 725         }
 726 
 727         /*
 728          * Determine if this is the root file system via vfstab. Give up
 729          * silently on failures. The whole point of this is to be tolerant
 730          * of the magic file systems being already mounted.
 731          */
 732         if ((vfstab = fopen(VFSTAB, "r")) != 0) {
 733                 for (magic_cnt = 0; magic_cnt < MAGIC_LIMIT; magic_cnt++) {
 734                         if (magic_cnt == MAGIC_NONE)
 735                                 continue;
 736                         if (getvfsfile(vfstab, &vfsbuf,
 737                             magic_fs[magic_cnt]) == 0) {
 738                                 if (is_block)
 739                                         devname = vfsbuf.vfs_special;
 740                                 else
 741                                         devname = vfsbuf.vfs_fsckdev;
 742                                 if (stat64(devname, &stbr) == 0) {
 743                                         if (stbr.st_rdev == stbd.st_rdev) {
 744                                                 found_magic[magic_cnt] = 1;
 745                                                 is_magic = magic_cnt;
 746                                                 break;
 747                                         }
 748                                 }
 749                         }
 750                 }
 751         }
 752 




   9 
  10 /*
  11  * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
  12  * All rights reserved.
  13  *
  14  * Redistribution and use in source and binary forms are permitted
  15  * provided that: (1) source distributions retain this entire copyright
  16  * notice and comment, and (2) distributions including binaries display
  17  * the following acknowledgement:  ``This product includes software
  18  * developed by the University of California, Berkeley and its contributors''
  19  * in the documentation or other materials provided with the distribution
  20  * and in all advertising materials mentioning features or use of this
  21  * software. Neither the name of the University nor the names of its
  22  * contributors may be used to endorse or promote products derived
  23  * from this software without specific prior written permission.
  24  * THIS SOFTWARE IS PROVIDED '`AS IS'' AND WITHOUT ANY EXPRESS OR
  25  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27  */
  28 
  29 #pragma ident   "@(#)main.c     1.55    08/05/07 SMI"
  30 
  31 /*
  32  * In-core structures:
  33  * blockmap[]
  34  *      A bitmap of block usage very similar to what's on disk, but
  35  *      for the entire filesystem rather than just a cylinder group.
  36  *      Zero indicates free, one indicates allocated.  Note that this
  37  *      is opposite the interpretation of a cylinder group's free block
  38  *      bitmap.
  39  *
  40  * statemap[]
  41  *      Tracks what is known about each inode in the filesystem.
  42  *      The fundamental state value is one of USTATE, FSTATE, DSTATE,
  43  *      or SSTATE (unallocated, file, directory, shadow/acl).
  44  *
  45  *      There are optional modifying attributes as well: INZLINK,
  46  *      INFOUND, INCLEAR, INORPHAN, and INDELAYD.  The IN prefix
  47  *      stands for inode.  INZLINK declares that no links (di_nlink ==
  48  *      0) to the inode have been found.  It is used instead of
  49  *      examining di_nlink because we've always got the statemap[] in


 679 /*
 680  * fsck -m: does the filesystem pass cursory examination
 681  *
 682  * XXX This is very redundant with setup().  The right thing would be
 683  *     for setup() to modify its behaviour when mflag is set (less
 684  *     chatty, exit instead of return, etc).
 685  */
 686 void
 687 check_sanity(char *filename)
 688 {
 689         struct stat64 stbd, stbr;
 690         char *devname;
 691         struct ustat usb;
 692         char vfsfilename[MAXPATHLEN];
 693         struct vfstab vfsbuf;
 694         FILE *vfstab;
 695         struct statvfs vfs_stat;
 696         int found_magic[MAGIC_LIMIT];
 697         int magic_cnt;
 698         int is_magic = 0;
 699         int is_block = 0;
 700         int is_file = 0;
 701 
 702         (void) memset((void *)found_magic, 0, sizeof (found_magic));
 703 
 704         if (stat64(filename, &stbd) < 0) {
 705                 (void) fprintf(stderr,
 706                 "ufs fsck: sanity check failed : cannot stat %s\n", filename);
 707                 exit(EXNOSTAT);
 708         }
 709 
 710         if (S_ISBLK(stbd.st_mode)) {
 711                 is_block = 1;
 712         } else if (S_ISCHR(stbd.st_mode)) {
 713                 is_block = 0;
 714         } else if (S_ISREG(stbd.st_mode)) {
 715                 is_file = 1;










 716         }
 717 
 718         /*
 719          * Determine if this is the root file system via vfstab. Give up
 720          * silently on failures. The whole point of this is to be tolerant
 721          * of the magic file systems being already mounted.
 722          */
 723         if (!is_file && (vfstab = fopen(VFSTAB, "r")) != NULL) {
 724                 for (magic_cnt = 0; magic_cnt < MAGIC_LIMIT; magic_cnt++) {
 725                         if (magic_cnt == MAGIC_NONE)
 726                                 continue;
 727                         if (getvfsfile(vfstab, &vfsbuf,
 728                             magic_fs[magic_cnt]) == 0) {
 729                                 if (is_block)
 730                                         devname = vfsbuf.vfs_special;
 731                                 else
 732                                         devname = vfsbuf.vfs_fsckdev;
 733                                 if (stat64(devname, &stbr) == 0) {
 734                                         if (stbr.st_rdev == stbd.st_rdev) {
 735                                                 found_magic[magic_cnt] = 1;
 736                                                 is_magic = magic_cnt;
 737                                                 break;
 738                                         }
 739                                 }
 740                         }
 741                 }
 742         }
 743