src/findlib/fstype.c
bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
{
   char *fname = ff_pkt->fname;
   struct statfs st;
   const char *fstype;

   if (statfs(fname, &st) == 0) {
      mtab_item *item, search_item;
      if (*ff_pkt->last_fstypename && ff_pkt->last_fstype == (uint64_t)st.f_type) {
         bstrncpy(fs, ff_pkt->last_fstypename, fslen);
         return true; 
      }
      if (!ff_pkt->mtab_list) {
         ff_pkt->mtab_list = New(rblist());
         read_mtab(add_mtab_item, ff_pkt->mtab_list);
      }
      search_item.dev = st.f_type;
      item = (mtab_item *)ff_pkt->mtab_list->search((void *)&search_item, compare_mtab_items);
      if (item) {
         ff_pkt->last_fstype = st.f_type;
         bstrncpy(ff_pkt->last_fstypename, item->fstype, sizeof(ff_pkt->last_fstypename));
         bstrncpy(fs, ff_pkt->last_fstypename, fslen);
         return true;
      }
      /*
       * Values obtained from statfs(2), testing and
       *
       *    $ grep -r SUPER_MAGIC /usr/include/linux
       */
      switch (st.f_type) {
      /* Known good values */
      /* ext2, ext3, and ext4 have the same code */
      case 0xef53:         fstype = "ext2"; break;          /* EXT2_SUPER_MAGIC */
      case 0x3153464a:     fstype = "jfs"; break;           /* JFS_SUPER_MAGIC */
      case 0x5346544e:     fstype = "ntfs"; break;          /* NTFS_SB_MAGIC */
      case 0x9fa0:         fstype = "proc"; break;          /* PROC_SUPER_MAGIC */
      case 0x52654973:     fstype = "reiserfs"; break;      /* REISERFS_SUPER_MAGIC */
      case 0x58465342:     fstype = "xfs"; break;           /* XFS_SB_MAGIC */
      case 0x9fa2:         fstype = "usbdevfs"; break;      /* USBDEVICE_SUPER_MAGIC */
      case 0x62656572:     fstype = "sysfs"; break;         /* SYSFS_MAGIC */
      case 0x517B:         fstype = "smbfs"; break;         /* SMB_SUPER_MAGIC */
      case 0x9660:         fstype = "iso9660"; break;       /* ISOFS_SUPER_MAGIC */
      case 0xadf5:         fstype = "adfs"; break;          /* ADFS_SUPER_MAGIC */
      case 0xadff:         fstype = "affs"; break;          /* AFFS_SUPER_MAGIC */
      case 0x42465331:     fstype = "befs"; break;          /* BEFS_SUPER_MAGIC */
      case 0xFF534D42:     fstype = "cifs"; break;          /* CIFS_MAGIC_NUMBER */
      case 0x73757245:     fstype = "coda"; break;          /* CODA_SUPER_MAGIC */
      case 0x012ff7b7:     fstype = "coherent"; break;      /* COH_SUPER_MAGIC */
      case 0x28cd3d45:     fstype = "cramfs"; break;        /* CRAMFS_MAGIC */
      case 0x1373:         fstype = "devfs"; break;         /* DEVFS_SUPER_MAGIC */
      case 0x414A53:       fstype = "efs"; break;           /* EFS_SUPER_MAGIC */
      case 0x137d:         fstype = "ext"; break;           /* EXT_SUPER_MAGIC */
      case 0xef51:         fstype = "oldext2"; break;          /* EXT2_OLD_SUPER_MAGIC */
      case 0x4244:         fstype = "hfs"; break;          /* EXT2_OLD_SUPER_MAGIC */
      case 0xf995e849:     fstype = "hpfs"; break;          /* HPFS_SUPER_MAGIC */
      case 0x958458f6:     fstype = "hugetlbfs"; break;     /* HUGETLBFS_MAGIC */
      case 0x72b6:         fstype = "jffs2"; break;         /* JFFS2_SUPER_MAGIC */
      case 0x2468:         fstype = "minix"; break;         /* MINIX2_SUPER_MAGIC */
      case 0x2478:         fstype = "minix"; break;         /* MINIX2_SUPER_MAGIC2 */
      case 0x137f:         fstype = "minix"; break;         /* MINIX_SUPER_MAGIC */
      case 0x138f:         fstype = "minix"; break;         /* MINIX_SUPER_MAGIC2 */
      case 0x4d44:         fstype = "msdos"; break;         /* MSDOS_SUPER_MAGIC */
      case 0x564c:         fstype = "ncpfs"; break;         /* NCP_SUPER_MAGIC */
      case 0x6969:         fstype = "nfs"; break;           /* NFS_SUPER_MAGIC */
      case 0x9fa1:         fstype = "openpromfs"; break;    /* OPENPROM_SUPER_MAGIC */
      case 0x002f:         fstype = "qnx4"; break;          /* QNX4_SUPER_MAGIC */
      case 0x7275:         fstype = "romfs"; break;          /* QNX4_SUPER_MAGIC */
      case 0x012ff7b6:     fstype = "sysv2"; break;
      case 0x012ff7b5:     fstype = "sysv4"; break;
      case 0x01021994:     fstype = "tmpfs"; break;
      case 0x15013346:     fstype = "udf"; break;
      case 0x00011954:     fstype = "ufs"; break;
      case 0xa501FCF5:     fstype = "vxfs"; break;
      case 0x012FF7B4:     fstype = "xenix"; break;
      case 0x012FD16D:     fstype = "xiafs"; break;
      case 0x9123683e:     fstype = "btrfs"; break;
      case 0x7461636f:     fstype = "ocfs2"; break;         /* OCFS2_SUPER_MAGIC */

#if 0       /* These need confirmation */
      case 0x6B414653:     fstype = "afs"; break;           /* AFS_FS_MAGIC */
      case 0x0187:         fstype = "autofs"; break;        /* AUTOFS_SUPER_MAGIC */
      case 0x62646576:     fstype = "bdev"; break;          /* ??? */
      case 0x1BADFACE:     fstype = "bfs"; break;           /* BFS_MAGIC */
      case 0x42494e4d:     fstype = "binfmt_misc"; break;   /* ??? */
      case (('C'<<8)|'N'): fstype = "capifs"; break;        /* CAPIFS_SUPER_MAGIC */
      case 0x1cd1:         fstype = "devpts"; break;        /* ??? */
      case 0x03111965:     fstype = "eventpollfs"; break;   /* EVENTPOLLFS_MAGIC */
      case 0xBAD1DEA:      fstype = "futexfs"; break;       /* ??? */
      case 0xaee71ee7:     fstype = "gadgetfs"; break;      /* GADGETFS_MAGIC */
      case 0x00c0ffee:     fstype = "hostfs"; break;        /* HOSTFS_SUPER_MAGIC */
      case 0xb00000ee:     fstype = "hppfs"; break;         /* HPPFS_SUPER_MAGIC */
      case 0x12061983:     fstype = "hwgfs"; break;         /* HWGFS_MAGIC */
      case 0x66726f67:     fstype = "ibmasmfs"; break;      /* IBMASMFS_MAGIC */
      case 0x19800202:     fstype = "mqueue"; break;        /* MQUEUE_MAGIC */
      case 0x6f70726f:     fstype = "oprofilefs"; break;    /* OPROFILEFS_MAGIC */
      case 0xa0b4d889:     fstype = "pfmfs"; break;         /* PFMFS_MAGIC */
      case 0x50495045:     fstype = "pipfs"; break;         /* PIPEFS_MAGIC */
      case 0x858458f6:     fstype = "ramfs"; break;         /* RAMFS_MAGIC */
      case 0x7275:         fstype = "romfs"; break;         /* ROMFS_MAGIC */
      case 0x858458f6:     fstype = "rootfs"; break;        /* RAMFS_MAGIC */
      case 0x67596969:     fstype = "rpc_pipefs"; break;    /* RPCAUTH_GSSMAGIC */
      case 0x534F434B:     fstype = "sockfs"; break;        /* SOCKFS_MAGIC */
      case 0x858458f6:     fstype = "tmpfs"; break;         /* RAMFS_MAGIC */
      case 0x01021994:     fstype = "tmpfs"; break;         /* TMPFS_MAGIC */
#endif

      default:
         Dmsg2(10, "Unknown file system type \"0x%x\" for \"%s\".\n", st.f_type,
               fname);
         return false;
      }
      ff_pkt->last_fstype = st.f_type;
      bstrncpy(ff_pkt->last_fstypename, fstype, sizeof(ff_pkt->last_fstypename));
      bstrncpy(fs, fstype, fslen);
      return true;
   }
   Dmsg1(50, "statfs() failed for \"%s\"\n", fname);
   return false;
}
/*
 * Linux statfs() does not return the filesystem name type.  It
 *  only returns a binary fstype, so we must look up the type name
 *  in mtab.
 */
Linux statfs() does not return the filesystem name type.  It
only returns a binary fstype, so we must look up the type name
in mtab.
Linux statfs () does not return the filesystem name type . It only returns a binary fstype so we must look up the type name in mtab .
bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
{
   char *fname = ff_pkt->fname;
   struct statfs st;
   const char *fstype;
   if (statfs(fname, &st) == 0) {
      mtab_item *item, search_item;
      if (*ff_pkt->last_fstypename && ff_pkt->last_fstype == (uint64_t)st.f_type) {
         bstrncpy(fs, ff_pkt->last_fstypename, fslen);
         return true; 
      }
      if (!ff_pkt->mtab_list) {
         ff_pkt->mtab_list = New(rblist());
         read_mtab(add_mtab_item, ff_pkt->mtab_list);
      }
      search_item.dev = st.f_type;
      item = (mtab_item *)ff_pkt->mtab_list->search((void *)&search_item, compare_mtab_items);
      if (item) {
         ff_pkt->last_fstype = st.f_type;
         bstrncpy(ff_pkt->last_fstypename, item->fstype, sizeof(ff_pkt->last_fstypename));
         bstrncpy(fs, ff_pkt->last_fstypename, fslen);
         return true;
      }
      switch (st.f_type) {
      case 0xef53:         fstype = "ext2"; break;          
      case 0x3153464a:     fstype = "jfs"; break;           
      case 0x5346544e:     fstype = "ntfs"; break;          
      case 0x9fa0:         fstype = "proc"; break;          
      case 0x52654973:     fstype = "reiserfs"; break;      
      case 0x58465342:     fstype = "xfs"; break;           
      case 0x9fa2:         fstype = "usbdevfs"; break;      
      case 0x62656572:     fstype = "sysfs"; break;         
      case 0x517B:         fstype = "smbfs"; break;         
      case 0x9660:         fstype = "iso9660"; break;       
      case 0xadf5:         fstype = "adfs"; break;          
      case 0xadff:         fstype = "affs"; break;          
      case 0x42465331:     fstype = "befs"; break;          
      case 0xFF534D42:     fstype = "cifs"; break;          
      case 0x73757245:     fstype = "coda"; break;          
      case 0x012ff7b7:     fstype = "coherent"; break;      
      case 0x28cd3d45:     fstype = "cramfs"; break;        
      case 0x1373:         fstype = "devfs"; break;         
      case 0x414A53:       fstype = "efs"; break;           
      case 0x137d:         fstype = "ext"; break;           
      case 0xef51:         fstype = "oldext2"; break;          
      case 0x4244:         fstype = "hfs"; break;          
      case 0xf995e849:     fstype = "hpfs"; break;          
      case 0x958458f6:     fstype = "hugetlbfs"; break;     
      case 0x72b6:         fstype = "jffs2"; break;         
      case 0x2468:         fstype = "minix"; break;         
      case 0x2478:         fstype = "minix"; break;         
      case 0x137f:         fstype = "minix"; break;         
      case 0x138f:         fstype = "minix"; break;         
      case 0x4d44:         fstype = "msdos"; break;         
      case 0x564c:         fstype = "ncpfs"; break;         
      case 0x6969:         fstype = "nfs"; break;           
      case 0x9fa1:         fstype = "openpromfs"; break;    
      case 0x002f:         fstype = "qnx4"; break;          
      case 0x7275:         fstype = "romfs"; break;          
      case 0x012ff7b6:     fstype = "sysv2"; break;
      case 0x012ff7b5:     fstype = "sysv4"; break;
      case 0x01021994:     fstype = "tmpfs"; break;
      case 0x15013346:     fstype = "udf"; break;
      case 0x00011954:     fstype = "ufs"; break;
      case 0xa501FCF5:     fstype = "vxfs"; break;
      case 0x012FF7B4:     fstype = "xenix"; break;
      case 0x012FD16D:     fstype = "xiafs"; break;
      case 0x9123683e:     fstype = "btrfs"; break;
      case 0x7461636f:     fstype = "ocfs2"; break;         
#if 0       
      case 0x6B414653:     fstype = "afs"; break;           
      case 0x0187:         fstype = "autofs"; break;        
      case 0x62646576:     fstype = "bdev"; break;          
      case 0x1BADFACE:     fstype = "bfs"; break;           
      case 0x42494e4d:     fstype = "binfmt_misc"; break;   
      case (('C'<<8)|'N'): fstype = "capifs"; break;        
      case 0x1cd1:         fstype = "devpts"; break;        
      case 0x03111965:     fstype = "eventpollfs"; break;   
      case 0xBAD1DEA:      fstype = "futexfs"; break;       
      case 0xaee71ee7:     fstype = "gadgetfs"; break;      
      case 0x00c0ffee:     fstype = "hostfs"; break;        
      case 0xb00000ee:     fstype = "hppfs"; break;         
      case 0x12061983:     fstype = "hwgfs"; break;         
      case 0x66726f67:     fstype = "ibmasmfs"; break;      
      case 0x19800202:     fstype = "mqueue"; break;        
      case 0x6f70726f:     fstype = "oprofilefs"; break;    
      case 0xa0b4d889:     fstype = "pfmfs"; break;         
      case 0x50495045:     fstype = "pipfs"; break;         
      case 0x858458f6:     fstype = "ramfs"; break;         
      case 0x7275:         fstype = "romfs"; break;         
      case 0x858458f6:     fstype = "rootfs"; break;        
      case 0x67596969:     fstype = "rpc_pipefs"; break;    
      case 0x534F434B:     fstype = "sockfs"; break;        
      case 0x858458f6:     fstype = "tmpfs"; break;         
      case 0x01021994:     fstype = "tmpfs"; break;         
#endif
      default:
         Dmsg2(10, "Unknown file system type \"0x%x\" for \"%s\".\n", st.f_type,
               fname);
         return false;
      }
      ff_pkt->last_fstype = st.f_type;
      bstrncpy(ff_pkt->last_fstypename, fstype, sizeof(ff_pkt->last_fstypename));
      bstrncpy(fs, fstype, fslen);
      return true;
   }
   Dmsg1(50, "statfs() failed for \"%s\"\n", fname);
   return false;
}
bool fstype ( FF_PKT * ff_pkt , char * fs , int fslen ) { char * fname = ff_pkt -> fname ; struct statfs st ; const char * fstype ; if ( statfs ( fname , & st ) == 0 ) { mtab_item * item , search_item ; if ( * ff_pkt -> last_fstypename && ff_pkt -> last_fstype == ( uint64_t ) st . f_type ) { bstrncpy ( fs , ff_pkt -> last_fstypename , fslen ) ; return true ; } if ( ! ff_pkt -> mtab_list ) { ff_pkt -> mtab_list = New ( rblist ( ) ) ; read_mtab ( add_mtab_item , ff_pkt -> mtab_list ) ; } search_item . dev = st . f_type ; item = ( mtab_item * ) ff_pkt -> mtab_list -> search ( ( void * ) & search_item , compare_mtab_items ) ; if ( item ) { ff_pkt -> last_fstype = st . f_type ; bstrncpy ( ff_pkt -> last_fstypename , item -> fstype , sizeof ( ff_pkt -> last_fstypename ) ) ; bstrncpy ( fs , ff_pkt -> last_fstypename , fslen ) ; return true ; } switch ( st . f_type ) { case 0xef53 : fstype = " " ; break ; case 0x3153464a : fstype = " " ; break ; case 0x5346544e : fstype = " " ; break ; case 0x9fa0 : fstype = " " ; break ; case 0x52654973 : fstype = " " ; break ; case 0x58465342 : fstype = " " ; break ; case 0x9fa2 : fstype = " " ; break ; case 0x62656572 : fstype = " " ; break ; case 0x517B : fstype = " " ; break ; case 0x9660 : fstype = " " ; break ; case 0xadf5 : fstype = " " ; break ; case 0xadff : fstype = " " ; break ; case 0x42465331 : fstype = " " ; break ; case 0xFF534D42 : fstype = " " ; break ; case 0x73757245 : fstype = " " ; break ; case 0x012ff7b7 : fstype = " " ; break ; case 0x28cd3d45 : fstype = " " ; break ; case 0x1373 : fstype = " " ; break ; case 0x414A53 : fstype = " " ; break ; case 0x137d : fstype = " " ; break ; case 0xef51 : fstype = " " ; break ; case 0x4244 : fstype = " " ; break ; case 0xf995e849 : fstype = " " ; break ; case 0x958458f6 : fstype = " " ; break ; case 0x72b6 : fstype = " " ; break ; case 0x2468 : fstype = " " ; break ; case 0x2478 : fstype = " " ; break ; case 0x137f : fstype = " " ; break ; case 0x138f : fstype = " " ; break ; case 0x4d44 : fstype = " " ; break ; case 0x564c : fstype = " " ; break ; case 0x6969 : fstype = " " ; break ; case 0x9fa1 : fstype = " " ; break ; case 0x002f : fstype = " " ; break ; case 0x7275 : fstype = " " ; break ; case 0x012ff7b6 : fstype = " " ; break ; case 0x012ff7b5 : fstype = " " ; break ; case 0x01021994 : fstype = " " ; break ; case 0x15013346 : fstype = " " ; break ; case 0x00011954 : fstype = " " ; break ; case 0xa501FCF5 : fstype = " " ; break ; case 0x012FF7B4 : fstype = " " ; break ; case 0x012FD16D : fstype = " " ; break ; case 0x9123683e : fstype = " " ; break ; case 0x7461636f : fstype = " " ; break ; #if 0 case 0x6B414653 : fstype = " " ; break ; case 0x0187 : fstype = " " ; break ; case 0x62646576 : fstype = " " ; break ; case 0x1BADFACE : fstype = " " ; break ; case 0x42494e4d : fstype = " " ; break ; case ( ( ' ' << 8 ) | ' ' ) : fstype = " " ; break ; case 0x1cd1 : fstype = " " ; break ; case 0x03111965 : fstype = " " ; break ; case 0xBAD1DEA : fstype = " " ; break ; case 0xaee71ee7 : fstype = " " ; break ; case 0x00c0ffee : fstype = " " ; break ; case 0xb00000ee : fstype = " " ; break ; case 0x12061983 : fstype = " " ; break ; case 0x66726f67 : fstype = " " ; break ; case 0x19800202 : fstype = " " ; break ; case 0x6f70726f : fstype = " " ; break ; case 0xa0b4d889 : fstype = " " ; break ; case 0x50495045 : fstype = " " ; break ; case 0x858458f6 : fstype = " " ; break ; case 0x7275 : fstype = " " ; break ; case 0x858458f6 : fstype = " " ; break ; case 0x67596969 : fstype = " " ; break ; case 0x534F434B : fstype = " " ; break ; case 0x858458f6 : fstype = " " ; break ; case 0x01021994 : fstype = " " ; break ; #endif default : Dmsg2 ( 10 , " \" \" \" \" \n " , st . f_type , fname ) ; return false ; } ff_pkt -> last_fstype = st . f_type ; bstrncpy ( ff_pkt -> last_fstypename , fstype , sizeof ( ff_pkt -> last_fstypename ) ) ; bstrncpy ( fs , fstype , fslen ) ; return true ; } Dmsg1 ( 50 , " \" \" \n " , fname ) ; return false ; }
Linux statfs() does not return the filesystem name type.
Linux statfs () does not return the filesystem name type .
/*
       * Values obtained from statfs(2), testing and
       *
       *    $ grep -r SUPER_MAGIC /usr/include/linux
       */ /* Known good values */ /* ext2, ext3, and ext4 have the same code */ /* EXT2_SUPER_MAGIC */ /* JFS_SUPER_MAGIC */ /* NTFS_SB_MAGIC */ /* PROC_SUPER_MAGIC */ /* REISERFS_SUPER_MAGIC */ /* XFS_SB_MAGIC */ /* USBDEVICE_SUPER_MAGIC */ /* SYSFS_MAGIC */ /* SMB_SUPER_MAGIC */ /* ISOFS_SUPER_MAGIC */ /* ADFS_SUPER_MAGIC */ /* AFFS_SUPER_MAGIC */ /* BEFS_SUPER_MAGIC */ /* CIFS_MAGIC_NUMBER */ /* CODA_SUPER_MAGIC */ /* COH_SUPER_MAGIC */ /* CRAMFS_MAGIC */ /* DEVFS_SUPER_MAGIC */ /* EFS_SUPER_MAGIC */ /* EXT_SUPER_MAGIC */ /* EXT2_OLD_SUPER_MAGIC */ /* EXT2_OLD_SUPER_MAGIC */ /* HPFS_SUPER_MAGIC */ /* HUGETLBFS_MAGIC */ /* JFFS2_SUPER_MAGIC */ /* MINIX2_SUPER_MAGIC */ /* MINIX2_SUPER_MAGIC2 */ /* MINIX_SUPER_MAGIC */ /* MINIX_SUPER_MAGIC2 */ /* MSDOS_SUPER_MAGIC */ /* NCP_SUPER_MAGIC */ /* NFS_SUPER_MAGIC */ /* OPENPROM_SUPER_MAGIC */ /* QNX4_SUPER_MAGIC */ /* QNX4_SUPER_MAGIC */ /* OCFS2_SUPER_MAGIC */ /* These need confirmation */ /* AFS_FS_MAGIC */ /* AUTOFS_SUPER_MAGIC */ /* ??? */ /* BFS_MAGIC */ /* ??? */ /* CAPIFS_SUPER_MAGIC */ /* ??? */ /* EVENTPOLLFS_MAGIC */ /* ??? */ /* GADGETFS_MAGIC */ /* HOSTFS_SUPER_MAGIC */ /* HPPFS_SUPER_MAGIC */ /* HWGFS_MAGIC */ /* IBMASMFS_MAGIC */ /* MQUEUE_MAGIC */ /* OPROFILEFS_MAGIC */ /* PFMFS_MAGIC */ /* PIPEFS_MAGIC */ /* RAMFS_MAGIC */ /* ROMFS_MAGIC */ /* RAMFS_MAGIC */ /* RPCAUTH_GSSMAGIC */ /* SOCKFS_MAGIC */ /* RAMFS_MAGIC */ /* TMPFS_MAGIC */