ia64/xen-unstable

changeset 14055:fe3e024e38f8

Add iso9660 support to libfsimage.

Signed-off-by: John Levon <john.levon@sun.com>
author john.levon@sun.com
date Tue Feb 20 14:54:04 2007 -0800 (2007-02-20)
parents bca284f67702
children 47db75f8cc76
files tools/libfsimage/Makefile tools/libfsimage/common/fsimage_grub.c tools/libfsimage/common/fsimage_grub.h tools/libfsimage/common/mapfile-GNU tools/libfsimage/common/mapfile-SunOS tools/libfsimage/ext2fs/fsys_ext2fs.c tools/libfsimage/iso9660/Makefile tools/libfsimage/iso9660/fsys_iso9660.c tools/libfsimage/iso9660/iso9660.h tools/libfsimage/reiserfs/fsys_reiserfs.c
line diff
     1.1 --- a/tools/libfsimage/Makefile	Wed Feb 21 10:13:40 2007 +0000
     1.2 +++ b/tools/libfsimage/Makefile	Tue Feb 20 14:54:04 2007 -0800
     1.3 @@ -1,7 +1,7 @@
     1.4  XEN_ROOT = ../..
     1.5  include $(XEN_ROOT)/tools/Rules.mk
     1.6  
     1.7 -SUBDIRS-y = common ufs reiserfs
     1.8 +SUBDIRS-y = common ufs reiserfs iso9660
     1.9  SUBDIRS-y += $(shell ./check-libext2fs)
    1.10  
    1.11  .PHONY: all
     2.1 --- a/tools/libfsimage/common/fsimage_grub.c	Wed Feb 21 10:13:40 2007 +0000
     2.2 +++ b/tools/libfsimage/common/fsimage_grub.c	Tue Feb 20 14:54:04 2007 -0800
     2.3 @@ -122,6 +122,84 @@ fsig_disk_read_junk(void)
     2.4  	return (&disk_read_junk);
     2.5  }
     2.6  
     2.7 +#if defined(__i386__) || defined(__x86_64__)
     2.8 +
     2.9 +#ifdef __amd64
    2.10 +#define BSF "bsfq"
    2.11 +#else
    2.12 +#define BSF "bsfl"
    2.13 +#endif
    2.14 +unsigned long
    2.15 +fsig_log2 (unsigned long word)
    2.16 +{
    2.17 +  __asm__ (BSF " %1,%0"
    2.18 +	   : "=r" (word)
    2.19 +	   : "r" (word));
    2.20 +  return word;
    2.21 +}
    2.22 +
    2.23 +#elif defined(__ia64__)
    2.24 +
    2.25 +#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
    2.26 +# define ia64_popcnt(x) __builtin_popcountl(x)
    2.27 +#else
    2.28 +# define ia64_popcnt(x)                                     \
    2.29 +  ({                                                        \
    2.30 +    __u64 ia64_intri_res;                                   \
    2.31 +    asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x)); \
    2.32 +    ia64_intri_res;                                         \
    2.33 +  })
    2.34 +#endif
    2.35 +
    2.36 +unsigned long
    2.37 +fsig_log2 (unsigned long word)
    2.38 +{
    2.39 +  unsigned long result;
    2.40 +
    2.41 +  result = ia64_popcnt((word - 1) & ~word);
    2.42 +  return result;
    2.43 +}
    2.44 +
    2.45 +#elif defined(__powerpc__)
    2.46 +
    2.47 +#ifdef __powerpc64__
    2.48 +#define PPC_CNTLZL "cntlzd"
    2.49 +#else
    2.50 +#define PPC_CNTLZL "cntlzw"
    2.51 +#endif
    2.52 +#define BITS_PER_LONG (sizeof(long) * 8)
    2.53 +
    2.54 +static int
    2.55 +__ilog2(unsigned long x)
    2.56 +{
    2.57 +  int lz;
    2.58 +
    2.59 +  asm (PPC_CNTLZL " %0,%1" : "=r" (lz) : "r" (x));
    2.60 +  return BITS_PER_LONG - 1 - lz;
    2.61 +}
    2.62 +
    2.63 +unsigned long
    2.64 +fsig_log2 (unsigned long word)
    2.65 +{
    2.66 +  return __ilog2(word & -word);
    2.67 +}
    2.68 +
    2.69 +#else /* Unoptimized */
    2.70 +
    2.71 +unsigned long
    2.72 +fsig_log2 (unsigned long word)
    2.73 +{
    2.74 +  unsigned long result = 0;
    2.75 +
    2.76 +  while (!(word & 1UL))
    2.77 +    {
    2.78 +      result++;
    2.79 +      word >>= 1;
    2.80 +    }
    2.81 +  return result;
    2.82 +}
    2.83 +#endif
    2.84 +
    2.85  int
    2.86  fsig_devread(fsi_file_t *ffi, unsigned int sector, unsigned int offset,
    2.87      unsigned int bufsize, char *buf)
     3.1 --- a/tools/libfsimage/common/fsimage_grub.h	Wed Feb 21 10:13:40 2007 +0000
     3.2 +++ b/tools/libfsimage/common/fsimage_grub.h	Tue Feb 20 14:54:04 2007 -0800
     3.3 @@ -57,17 +57,20 @@ typedef struct fsig_plugin_ops {
     3.4  #define	disk_read_func (*fsig_disk_read_junk())
     3.5  #define	disk_read_hook (*fsig_disk_read_junk())
     3.6  #define	print_possibilities 0
     3.7 +#define	noisy_printf
     3.8  
     3.9  #define	grub_memset memset
    3.10  #define	grub_memmove memmove
    3.11 +#define grub_log2 fsig_log2
    3.12  
    3.13  extern char **fsig_disk_read_junk(void);
    3.14 +unsigned long fsig_log2(unsigned long);
    3.15  
    3.16  #define	ERR_FSYS_CORRUPT 1
    3.17 +#define	ERR_OUTSIDE_PART 1
    3.18  #define	ERR_SYMLINK_LOOP 1
    3.19  #define	ERR_FILELENGTH 1
    3.20  #define	ERR_BAD_FILETYPE 1
    3.21 -#define	ERR_BAD_FILETYPE 1
    3.22  #define	ERR_FILE_NOT_FOUND 1
    3.23  
    3.24  fsi_plugin_ops_t *fsig_init(fsi_plugin_t *, fsig_plugin_ops_t *);
     4.1 --- a/tools/libfsimage/common/mapfile-GNU	Wed Feb 21 10:13:40 2007 +0000
     4.2 +++ b/tools/libfsimage/common/mapfile-GNU	Tue Feb 20 14:54:04 2007 -0800
     4.3 @@ -20,6 +20,7 @@ VERSION {
     4.4  			fsig_init;
     4.5  			fsig_devread;
     4.6  			fsig_substring;
     4.7 +			fsig_log2;
     4.8  			fsig_fs_buf;
     4.9  			fsig_file_alloc;
    4.10  			fsig_file_buf;
     5.1 --- a/tools/libfsimage/common/mapfile-SunOS	Wed Feb 21 10:13:40 2007 +0000
     5.2 +++ b/tools/libfsimage/common/mapfile-SunOS	Tue Feb 20 14:54:04 2007 -0800
     5.3 @@ -19,6 +19,7 @@ libfsimage.so.1.0 {
     5.4  		fsig_init;
     5.5  		fsig_devread;
     5.6  		fsig_substring;
     5.7 +		fsig_log2;
     5.8  		fsig_fs_buf;
     5.9  		fsig_file_alloc;
    5.10  		fsig_file_buf;
     6.1 --- a/tools/libfsimage/ext2fs/fsys_ext2fs.c	Wed Feb 21 10:13:40 2007 +0000
     6.2 +++ b/tools/libfsimage/ext2fs/fsys_ext2fs.c	Tue Feb 20 14:54:04 2007 -0800
     6.3 @@ -191,7 +191,7 @@ struct ext2_dir_entry
     6.4  
     6.5  
     6.6  /* ext2/super.c */
     6.7 -#define log2(n) ffz(~(n))
     6.8 +#define log2(n) grub_log2(n)
     6.9  
    6.10  #define EXT2_SUPER_MAGIC      0xEF53	/* include/linux/ext2_fs.h */
    6.11  #define EXT2_ROOT_INO              2	/* include/linux/ext2_fs.h */
    6.12 @@ -232,93 +232,6 @@ struct ext2_dir_entry
    6.13  #define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
    6.14  #define S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)
    6.15  
    6.16 -#if defined(__i386__) || defined(__x86_64__)
    6.17 -/* include/asm-i386/bitops.h */
    6.18 -/*
    6.19 - * ffz = Find First Zero in word. Undefined if no zero exists,
    6.20 - * so code should check against ~0UL first..
    6.21 - */
    6.22 -#ifdef __amd64
    6.23 -#define BSF "bsfq"
    6.24 -#else
    6.25 -#define BSF "bsfl"
    6.26 -#endif
    6.27 -static __inline__ unsigned long
    6.28 -ffz (unsigned long word)
    6.29 -{
    6.30 -  __asm__ (BSF " %1,%0"
    6.31 -:	   "=r" (word)
    6.32 -:	   "r" (~word));
    6.33 -  return word;
    6.34 -}
    6.35 -
    6.36 -#elif defined(__ia64__)
    6.37 -
    6.38 -typedef unsigned long __u64;
    6.39 -
    6.40 -#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
    6.41 -# define ia64_popcnt(x) __builtin_popcountl(x)
    6.42 -#else
    6.43 -# define ia64_popcnt(x)                                     \
    6.44 -  ({                                                        \
    6.45 -    __u64 ia64_intri_res;                                   \
    6.46 -    asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x)); \
    6.47 -    ia64_intri_res;                                         \
    6.48 -  })
    6.49 -#endif
    6.50 -
    6.51 -static __inline__ unsigned long
    6.52 -ffz (unsigned long word)
    6.53 -{
    6.54 -  unsigned long result;
    6.55 -
    6.56 -  result = ia64_popcnt(word & (~word - 1));
    6.57 -  return result;
    6.58 -}
    6.59 -
    6.60 -#elif defined(__powerpc__)
    6.61 -
    6.62 -#ifdef __powerpc64__
    6.63 -#define PPC_CNTLZL "cntlzd"
    6.64 -#else
    6.65 -#define PPC_CNTLZL "cntlzw"
    6.66 -#endif
    6.67 -#define BITS_PER_LONG (sizeof(long) * 8)
    6.68 -
    6.69 -static __inline__ int
    6.70 -__ilog2(unsigned long x)
    6.71 -{
    6.72 -  int lz;
    6.73 -
    6.74 -  asm (PPC_CNTLZL " %0,%1" : "=r" (lz) : "r" (x));
    6.75 -  return BITS_PER_LONG - 1 - lz;
    6.76 -}
    6.77 -
    6.78 -static __inline__ unsigned long
    6.79 -ffz (unsigned long word)
    6.80 -{
    6.81 -  if ((word = ~word) == 0)
    6.82 -    return BITS_PER_LONG;
    6.83 -  return __ilog2(word & -word);
    6.84 -}
    6.85 -
    6.86 -#else /* Unoptimized */
    6.87 -
    6.88 -static __inline__ unsigned long
    6.89 -ffz (unsigned long word)
    6.90 -{
    6.91 -  unsigned long result;
    6.92 -
    6.93 -  result = 0;
    6.94 -  while(word & 1)
    6.95 -    {
    6.96 -      result++;
    6.97 -      word >>= 1;
    6.98 -    }
    6.99 -  return result;
   6.100 -}
   6.101 -#endif
   6.102 -
   6.103  /* check filesystem types and read superblock into memory buffer */
   6.104  int
   6.105  ext2fs_mount (fsi_file_t *ffi, const char *options)
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/libfsimage/iso9660/Makefile	Tue Feb 20 14:54:04 2007 -0800
     7.3 @@ -0,0 +1,15 @@
     7.4 +XEN_ROOT = ../../..
     7.5 +
     7.6 +LIB_SRCS-y = fsys_iso9660.c
     7.7 +
     7.8 +FS = iso9660
     7.9 +
    7.10 +.PHONY: all
    7.11 +all: fs-all
    7.12 +
    7.13 +.PHONY: install
    7.14 +install: fs-install
    7.15 +
    7.16 +fsys_iso9660.c: iso9660.h
    7.17 +
    7.18 +include $(XEN_ROOT)/tools/libfsimage/Rules.mk
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/libfsimage/iso9660/fsys_iso9660.c	Tue Feb 20 14:54:04 2007 -0800
     8.3 @@ -0,0 +1,463 @@
     8.4 +/*
     8.5 + *  ISO 9660 filesystem backend for GRUB (GRand Unified Bootloader)
     8.6 + *  including Rock Ridge Extensions support
     8.7 + *
     8.8 + *  Copyright (C) 1998, 1999  Kousuke Takai  <tak@kmc.kyoto-u.ac.jp>
     8.9 + *
    8.10 + *  This program is free software; you can redistribute it and/or modify
    8.11 + *  it under the terms of the GNU General Public License as published by
    8.12 + *  the Free Software Foundation; either version 2 of the License, or
    8.13 + *  (at your option) any later version.
    8.14 + *
    8.15 + *  This program is distributed in the hope that it will be useful,
    8.16 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.17 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.18 + *  GNU General Public License for more details.
    8.19 + *
    8.20 + *  You should have received a copy of the GNU General Public License
    8.21 + *  along with this program; if not, write to the Free Software
    8.22 + *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    8.23 + */
    8.24 +/*
    8.25 + *  References:
    8.26 + *	linux/fs/isofs/rock.[ch]
    8.27 + *	mkisofs-1.11.1/diag/isoinfo.c
    8.28 + *	mkisofs-1.11.1/iso9660.h
    8.29 + *		(all are written by Eric Youngdale)
    8.30 + *
    8.31 + *  Modifications by:
    8.32 + *	Leonid Lisovskiy   <lly@pisem.net>	2003
    8.33 + */
    8.34 +
    8.35 +#include <fsimage_grub.h>
    8.36 +#include <limits.h>
    8.37 +
    8.38 +#include "iso9660.h"
    8.39 +
    8.40 +#define	MAXINT INT_MAX
    8.41 +
    8.42 +/* iso9660 super-block data in memory */
    8.43 +struct iso_sb_info {
    8.44 +  unsigned long vol_sector;
    8.45 +
    8.46 +};
    8.47 +
    8.48 +/* iso fs inode data in memory */
    8.49 +struct iso_inode_info {
    8.50 +  unsigned long file_start;
    8.51 +};
    8.52 +
    8.53 +#define ISO_SUPER	\
    8.54 +    ((struct iso_sb_info *)(FSYS_BUF))
    8.55 +#define INODE		\
    8.56 +    ((struct iso_inode_info *)(FSYS_BUF+sizeof(struct iso_sb_info)))
    8.57 +#define PRIMDESC        ((struct iso_primary_descriptor *)(FSYS_BUF + 2048))
    8.58 +#define DIRREC          ((struct iso_directory_record *)(FSYS_BUF + 4096))
    8.59 +#define RRCONT_BUF      ((unsigned char *)(FSYS_BUF + 6144))
    8.60 +#define NAME_BUF        ((unsigned char *)(FSYS_BUF + 8192))
    8.61 +
    8.62 +
    8.63 +#define log2 grub_log2
    8.64 +
    8.65 +static int
    8.66 +iso9660_devread (fsi_file_t *ffi, int sector, int byte_offset, int byte_len, char *buf)
    8.67 +{
    8.68 +  static int read_count = 0, threshold = 2;
    8.69 +  unsigned short sector_size_lg2 = log2(512 /*buf_geom.sector_size*/);
    8.70 +
    8.71 +  /*
    8.72 +   * We have to use own devread() function since BIOS return wrong geometry
    8.73 +   */
    8.74 +  if (sector < 0)
    8.75 +    {
    8.76 +      errnum = ERR_OUTSIDE_PART;
    8.77 +      return 0;
    8.78 +    }
    8.79 +  if (byte_len <= 0)
    8.80 +    return 1;
    8.81 +
    8.82 +#if 0
    8.83 +  sector += (byte_offset >> sector_size_lg2);
    8.84 +  byte_offset &= (buf_geom.sector_size - 1);
    8.85 +  asm volatile ("shl%L0 %1,%0"
    8.86 +		: "=r"(sector)
    8.87 +		: "Ic"((int8_t)(ISO_SECTOR_BITS - sector_size_lg2)),
    8.88 +		"0"(sector));
    8.89 +#else
    8.90 +  sector = (sector * 4) + (byte_offset >> sector_size_lg2);
    8.91 +  byte_offset &= 511;
    8.92 +#endif
    8.93 +
    8.94 +#if !defined(STAGE1_5)
    8.95 +  if (disk_read_hook && debug)
    8.96 +    printf ("<%d, %d, %d>", sector, byte_offset, byte_len);
    8.97 +#endif /* !STAGE1_5 */
    8.98 +
    8.99 +  read_count += (byte_len >> 9);
   8.100 +  if ((read_count >> 11) > threshold) {
   8.101 +	noisy_printf(".");
   8.102 +	threshold += 2;	/* one dot every 2 MB */
   8.103 +  }
   8.104 +  return devread(ffi, sector, byte_offset, byte_len, buf);
   8.105 +}
   8.106 +
   8.107 +int
   8.108 +iso9660_mount (fsi_file_t *ffi, const char *options)
   8.109 +{
   8.110 +  unsigned int sector;
   8.111 +
   8.112 +  /*
   8.113 +   *  Because there is no defined slice type ID for ISO-9660 filesystem,
   8.114 +   *  this test will pass only either (1) if entire disk is used, or
   8.115 +   *  (2) if current partition is BSD style sub-partition whose ID is
   8.116 +   *  ISO-9660.
   8.117 +   */
   8.118 +#if 0
   8.119 +  if ((current_partition != 0xFFFFFF)
   8.120 +      && !IS_PC_SLICE_TYPE_BSD_WITH_FS(current_slice, FS_ISO9660))
   8.121 +    return 0;
   8.122 +#endif
   8.123 +
   8.124 +  /*
   8.125 +   *  Currently, only FIRST session of MultiSession disks are supported !!!
   8.126 +   */
   8.127 +  for (sector = 16 ; sector < 32 ; sector++)
   8.128 +    {
   8.129 +      if (!iso9660_devread(ffi, sector, 0, sizeof(*PRIMDESC), (char *)PRIMDESC)) 
   8.130 +	break;
   8.131 +      /* check ISO_VD_PRIMARY and ISO_STANDARD_ID */
   8.132 +      if (PRIMDESC->type.l == ISO_VD_PRIMARY
   8.133 +	  && !memcmp(PRIMDESC->id, ISO_STANDARD_ID, sizeof(PRIMDESC->id)))
   8.134 +	{
   8.135 +	  ISO_SUPER->vol_sector = sector;
   8.136 +	  INODE->file_start = 0;
   8.137 +#if 0
   8.138 +	  fsmax = PRIMDESC->volume_space_size.l;
   8.139 +#endif
   8.140 +	  return 1;
   8.141 +	}
   8.142 +    }
   8.143 +
   8.144 +  return 0;
   8.145 +}
   8.146 +
   8.147 +int
   8.148 +iso9660_dir (fsi_file_t *ffi, char *dirname)
   8.149 +{
   8.150 +  struct iso_directory_record *idr;
   8.151 +  RR_ptr_t rr_ptr;
   8.152 +  struct rock_ridge *ce_ptr;
   8.153 +  unsigned int pathlen;
   8.154 +  int size;
   8.155 +  unsigned int extent;
   8.156 +  unsigned char file_type;
   8.157 +  unsigned int rr_len;
   8.158 +  unsigned char rr_flag;
   8.159 +
   8.160 +  idr = &PRIMDESC->root_directory_record;
   8.161 +  INODE->file_start = 0;
   8.162 +
   8.163 +  do
   8.164 +    {
   8.165 +      while (*dirname == '/')	/* skip leading slashes */
   8.166 +	dirname++;
   8.167 +      /* pathlen = strcspn(dirname, "/\n\t "); */
   8.168 +      for (pathlen = 0 ;
   8.169 +	   dirname[pathlen]
   8.170 +	     && !isspace(dirname[pathlen]) && dirname[pathlen] != '/' ;
   8.171 +	   pathlen++)
   8.172 +	;
   8.173 +
   8.174 +      size = idr->size.l;
   8.175 +      extent = idr->extent.l;
   8.176 +
   8.177 +      while (size > 0)
   8.178 +	{
   8.179 +	  if (!iso9660_devread(ffi, extent, 0, ISO_SECTOR_SIZE, (char *)DIRREC))
   8.180 +	    {
   8.181 +	      errnum = ERR_FSYS_CORRUPT;
   8.182 +	      return 0;
   8.183 +	    }
   8.184 +	  extent++;
   8.185 +
   8.186 +	  idr = (struct iso_directory_record *)DIRREC;
   8.187 +	  for (; idr->length.l > 0;
   8.188 +	       idr = (struct iso_directory_record *)((char *)idr + idr->length.l) )
   8.189 +	    {
   8.190 +	      const char *name = idr->name;
   8.191 +	      unsigned int name_len = idr->name_len.l;
   8.192 +
   8.193 +	      file_type = (idr->flags.l & 2) ? ISO_DIRECTORY : ISO_REGULAR;
   8.194 +	      if (name_len == 1)
   8.195 +		{
   8.196 +		  if ((name[0] == 0) ||	/* self */
   8.197 +		      (name[0] == 1)) 	/* parent */
   8.198 +		    continue;
   8.199 +		}
   8.200 +	      if (name_len > 2 && CHECK2(name + name_len - 2, ';', '1'))
   8.201 +		{
   8.202 +		  name_len -= 2;	/* truncate trailing file version */
   8.203 +		  if (name_len > 1 && name[name_len - 1] == '.')
   8.204 +		    name_len--;		/* truncate trailing dot */
   8.205 +		}
   8.206 +
   8.207 +	      /*
   8.208 +	       *  Parse Rock-Ridge extension
   8.209 +	       */
   8.210 +	      rr_len = (idr->length.l - idr->name_len.l
   8.211 +			- sizeof(struct iso_directory_record)
   8.212 +			+ sizeof(idr->name));
   8.213 +	      rr_ptr.ptr = ((unsigned char *)idr + idr->name_len.l
   8.214 +			    + sizeof(struct iso_directory_record)
   8.215 +			    - sizeof(idr->name));
   8.216 +	      if (rr_ptr.i & 1)
   8.217 +		rr_ptr.i++, rr_len--;
   8.218 +	      ce_ptr = NULL;
   8.219 +	      rr_flag = RR_FLAG_NM | RR_FLAG_PX /*| RR_FLAG_SL*/;
   8.220 +
   8.221 +	      while (rr_len >= 4)
   8.222 +		{
   8.223 +		  if (rr_ptr.rr->version != 1)
   8.224 +		    {
   8.225 +#ifndef STAGE1_5
   8.226 +		      if (debug)
   8.227 +			printf(
   8.228 +			       "Non-supported version (%d) RockRidge chunk "
   8.229 +			       "`%c%c'\n", rr_ptr.rr->version,
   8.230 +			       rr_ptr.rr->signature & 0xFF,
   8.231 +			       rr_ptr.rr->signature >> 8);
   8.232 +#endif
   8.233 +		    }
   8.234 +		  else
   8.235 +		    {
   8.236 +		      switch (rr_ptr.rr->signature)
   8.237 +			{
   8.238 +			case RRMAGIC('R', 'R'):
   8.239 +			  if ( rr_ptr.rr->len >= (4+sizeof(struct RR)))
   8.240 +			    rr_flag &= rr_ptr.rr->u.rr.flags.l;
   8.241 +			  break;
   8.242 +			case RRMAGIC('N', 'M'):
   8.243 +			  name = rr_ptr.rr->u.nm.name;
   8.244 +			  name_len = rr_ptr.rr->len - (4+sizeof(struct NM));
   8.245 +			  rr_flag &= ~RR_FLAG_NM;
   8.246 +			  break;
   8.247 +			case RRMAGIC('P', 'X'):
   8.248 +			  if (rr_ptr.rr->len >= (4+sizeof(struct PX)))
   8.249 +			    {
   8.250 +			      file_type = ((rr_ptr.rr->u.px.mode.l & POSIX_S_IFMT)
   8.251 +					   == POSIX_S_IFREG
   8.252 +					   ? ISO_REGULAR
   8.253 +					   : ((rr_ptr.rr->u.px.mode.l & POSIX_S_IFMT)
   8.254 +					      == POSIX_S_IFDIR
   8.255 +					      ? ISO_DIRECTORY : ISO_OTHER));
   8.256 +			      rr_flag &= ~RR_FLAG_PX;
   8.257 +			    }
   8.258 +			  break;
   8.259 +			case RRMAGIC('C', 'E'):
   8.260 +			  if (rr_ptr.rr->len >= (4+sizeof(struct CE)))
   8.261 +			    ce_ptr = rr_ptr.rr;
   8.262 +			  break;
   8.263 +#if 0		// RockRidge symlinks are not supported yet
   8.264 +			case RRMAGIC('S', 'L'):
   8.265 +			  {
   8.266 +			    int slen;
   8.267 +			    unsigned char rootflag, prevflag;
   8.268 +			    char *rpnt = NAME_BUF+1024;
   8.269 +			    struct SL_component *slp;
   8.270 +
   8.271 +			    slen = rr_ptr.rr->len - (4+1);
   8.272 +			    slp = &rr_ptr.rr->u.sl.link;
   8.273 +			    while (slen > 1)
   8.274 +			      {
   8.275 +				rootflag = 0;
   8.276 +				switch (slp->flags.l)
   8.277 +				  {
   8.278 +				  case 0:
   8.279 +				    memcpy(rpnt, slp->text, slp->len);
   8.280 +				    rpnt += slp->len;
   8.281 +				    break;
   8.282 +				  case 4:
   8.283 +				    *rpnt++ = '.';
   8.284 +				    /* fallthru */
   8.285 +				  case 2:
   8.286 +				    *rpnt++ = '.';
   8.287 +				    break;
   8.288 +				  case 8:
   8.289 +				    rootflag = 1;
   8.290 +				    *rpnt++ = '/';
   8.291 +				    break;
   8.292 +				  default:
   8.293 +				    printf("Symlink component flag not implemented (%d)\n",
   8.294 +					   slp->flags.l);
   8.295 +				    slen = 0;
   8.296 +				    break;
   8.297 +				  }
   8.298 +				slen -= slp->len + 2;
   8.299 +				prevflag = slp->flags.l;
   8.300 +				slp = (struct SL_component *) ((char *) slp + slp->len + 2);
   8.301 +
   8.302 +				if (slen < 2)
   8.303 +				  {
   8.304 +				    /*
   8.305 +				     * If there is another SL record, and this component
   8.306 +				     * record isn't continued, then add a slash.
   8.307 +				     */
   8.308 +				    if ((!rootflag) && (rr_ptr.rr->u.sl.flags.l & 1) && !(prevflag & 1))
   8.309 +				      *rpnt++='/';
   8.310 +				    break;
   8.311 +				  }
   8.312 +
   8.313 +				/*
   8.314 +				 * If this component record isn't continued, then append a '/'.
   8.315 +				 */
   8.316 +				if (!rootflag && !(prevflag & 1))
   8.317 +				  *rpnt++ = '/';
   8.318 +			      }
   8.319 +			    *rpnt++ = '\0';
   8.320 +			    grub_putstr(NAME_BUF+1024);// debug print!
   8.321 +			  }
   8.322 +			  rr_flag &= ~RR_FLAG_SL;
   8.323 +			  break;
   8.324 +#endif
   8.325 +			default:
   8.326 +			  break;
   8.327 +			}
   8.328 +		    }
   8.329 +		  if (!rr_flag)
   8.330 +		    /*
   8.331 +		     * There is no more extension we expects...
   8.332 +		     */
   8.333 +		    break;
   8.334 +
   8.335 +		  rr_len -= rr_ptr.rr->len;
   8.336 +		  rr_ptr.ptr += rr_ptr.rr->len;
   8.337 +		  if (rr_len < 4 && ce_ptr != NULL)
   8.338 +		    {
   8.339 +		      /* preserve name before loading new extent. */
   8.340 +		      if( RRCONT_BUF <= (unsigned char *)name
   8.341 +			  && (unsigned char *)name < RRCONT_BUF + ISO_SECTOR_SIZE )
   8.342 +			{
   8.343 +			  memcpy(NAME_BUF, name, name_len);
   8.344 +			  name = NAME_BUF;
   8.345 +			}
   8.346 +		      rr_ptr.ptr = RRCONT_BUF + ce_ptr->u.ce.offset.l;
   8.347 +		      rr_len = ce_ptr->u.ce.size.l;
   8.348 +		      if (!iso9660_devread(ffi, ce_ptr->u.ce.extent.l, 0, ISO_SECTOR_SIZE, RRCONT_BUF))
   8.349 +			{
   8.350 +			  errnum = 0;	/* this is not fatal. */
   8.351 +			  break;
   8.352 +			}
   8.353 +		      ce_ptr = NULL;
   8.354 +		    }
   8.355 +		} /* rr_len >= 4 */
   8.356 +
   8.357 +	      filemax = MAXINT;
   8.358 +	      if (name_len >= pathlen
   8.359 +		  && !memcmp(name, dirname, pathlen))
   8.360 +		{
   8.361 +		  if (dirname[pathlen] == '/' || !print_possibilities)
   8.362 +		    {
   8.363 +		      /*
   8.364 +		       *  DIRNAME is directory component of pathname,
   8.365 +		       *  or we are to open a file.
   8.366 +		       */
   8.367 +		      if (pathlen == name_len)
   8.368 +			{
   8.369 +			  if (dirname[pathlen] == '/')
   8.370 +			    {
   8.371 +			      if (file_type != ISO_DIRECTORY)
   8.372 +				{
   8.373 +				  errnum = ERR_BAD_FILETYPE;
   8.374 +				  return 0;
   8.375 +				}
   8.376 +			      goto next_dir_level;
   8.377 +			    }
   8.378 +			  if (file_type != ISO_REGULAR)
   8.379 +			    {
   8.380 +			      errnum = ERR_BAD_FILETYPE;
   8.381 +			      return 0;
   8.382 +			    }
   8.383 +			  INODE->file_start = idr->extent.l;
   8.384 +			  filepos = 0;
   8.385 +			  filemax = idr->size.l;
   8.386 +			  return 1;
   8.387 +			}
   8.388 +		    }
   8.389 +		  else	/* Completion */
   8.390 +		    {
   8.391 +#ifndef STAGE1_5
   8.392 +		      if (print_possibilities > 0)
   8.393 +			print_possibilities = -print_possibilities;
   8.394 +		      memcpy(NAME_BUF, name, name_len);
   8.395 +		      NAME_BUF[name_len] = '\0';
   8.396 +		      print_a_completion (NAME_BUF);
   8.397 +#endif
   8.398 +		    }
   8.399 +		}
   8.400 +	    } /* for */
   8.401 +
   8.402 +	  size -= ISO_SECTOR_SIZE;
   8.403 +	} /* size>0 */
   8.404 +
   8.405 +      if (dirname[pathlen] == '/' || print_possibilities >= 0)
   8.406 +	{
   8.407 +	  errnum = ERR_FILE_NOT_FOUND;
   8.408 +	  return 0;
   8.409 +	}
   8.410 +
   8.411 +    next_dir_level:
   8.412 +      dirname += pathlen;
   8.413 +
   8.414 +    } while (*dirname == '/');
   8.415 +
   8.416 +  return 1;
   8.417 +}
   8.418 +
   8.419 +int
   8.420 +iso9660_read (fsi_file_t *ffi, char *buf, int len)
   8.421 +{
   8.422 +  int sector, blkoffset, size, ret;
   8.423 +
   8.424 +  if (INODE->file_start == 0)
   8.425 +    return 0;
   8.426 +
   8.427 +  ret = 0;
   8.428 +  blkoffset = filepos & (ISO_SECTOR_SIZE - 1);
   8.429 +  sector = filepos >> ISO_SECTOR_BITS;
   8.430 +  while (len > 0)
   8.431 +    {
   8.432 +      size = ISO_SECTOR_SIZE - blkoffset;
   8.433 +      if (size > len)
   8.434 +        size = len;
   8.435 +
   8.436 +      disk_read_func = disk_read_hook;
   8.437 +
   8.438 +      if (!iso9660_devread(ffi, INODE->file_start + sector, blkoffset, size, buf))
   8.439 +	return 0;
   8.440 +
   8.441 +      disk_read_func = NULL;
   8.442 +
   8.443 +      len -= size;
   8.444 +      buf += size;
   8.445 +      ret += size;
   8.446 +      filepos += size;
   8.447 +      sector++;
   8.448 +      blkoffset = 0;
   8.449 +    }
   8.450 +
   8.451 +  return ret;
   8.452 +}
   8.453 +
   8.454 +fsi_plugin_ops_t *
   8.455 +fsi_init_plugin(int version, fsi_plugin_t *fp, const char **name)
   8.456 +{
   8.457 +	static fsig_plugin_ops_t ops = {
   8.458 +		FSIMAGE_PLUGIN_VERSION,
   8.459 +		.fpo_mount = iso9660_mount,
   8.460 +		.fpo_dir = iso9660_dir,
   8.461 +		.fpo_read = iso9660_read
   8.462 +	};
   8.463 +
   8.464 +	*name = "iso9660";
   8.465 +	return (fsig_init(fp, &ops));
   8.466 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/libfsimage/iso9660/iso9660.h	Tue Feb 20 14:54:04 2007 -0800
     9.3 @@ -0,0 +1,219 @@
     9.4 +/*
     9.5 + *  ISO 9660 filesystem backend for GRUB (GRand Unified Bootloader)
     9.6 + *  including Rock Ridge Extensions support
     9.7 + *
     9.8 + *  Copyright (C) 1998, 1999  Kousuke Takai  <tak@kmc.kyoto-u.ac.jp>
     9.9 + *
    9.10 + *  This program is free software; you can redistribute it and/or modify
    9.11 + *  it under the terms of the GNU General Public License as published by
    9.12 + *  the Free Software Foundation; either version 2 of the License, or
    9.13 + *  (at your option) any later version.
    9.14 + *
    9.15 + *  This program is distributed in the hope that it will be useful,
    9.16 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.17 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.18 + *  GNU General Public License for more details.
    9.19 + *
    9.20 + *  You should have received a copy of the GNU General Public License
    9.21 + *  along with this program; if not, write to the Free Software
    9.22 + *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    9.23 + */
    9.24 +/*
    9.25 + *  References:
    9.26 + *	linux/fs/isofs/rock.[ch]
    9.27 + *	mkisofs-1.11.1/diag/isoinfo.c
    9.28 + *	mkisofs-1.11.1/iso9660.h
    9.29 + *		(all are written by Eric Youngdale)
    9.30 + */
    9.31 +
    9.32 +#ifndef _ISO9660_H_
    9.33 +#define _ISO9660_H_
    9.34 +
    9.35 +#define ISO_SECTOR_BITS              (11)
    9.36 +#define ISO_SECTOR_SIZE              (1<<ISO_SECTOR_BITS)
    9.37 +
    9.38 +#define	ISO_REGULAR	1	/* regular file	*/
    9.39 +#define	ISO_DIRECTORY	2	/* directory	*/
    9.40 +#define	ISO_OTHER	0	/* other file (with Rock Ridge) */
    9.41 +
    9.42 +#define	RR_FLAG_PX	0x01	/* have POSIX file attributes */
    9.43 +#define RR_FLAG_PN	0x02	/* POSIX devices */
    9.44 +#define RR_FLAG_SL	0x04	/* Symbolic link */
    9.45 +#define	RR_FLAG_NM	0x08	/* have alternate file name   */
    9.46 +#define RR_FLAG_CL	0x10	/* Child link */
    9.47 +#define RR_FLAG_PL	0x20	/* Parent link */
    9.48 +#define RR_FLAG_RE	0x40	/* Relocation directory */
    9.49 +#define RR_FLAG_TF	0x80	/* Timestamps */
    9.50 +
    9.51 +/* POSIX file attributes for Rock Ridge extensions */
    9.52 +#define	POSIX_S_IFMT	0xF000
    9.53 +#define	POSIX_S_IFREG	0x8000
    9.54 +#define	POSIX_S_IFDIR	0x4000
    9.55 +
    9.56 +/* volume descriptor types */
    9.57 +#define ISO_VD_PRIMARY 1
    9.58 +#define ISO_VD_END 255
    9.59 +
    9.60 +#define ISO_STANDARD_ID "CD001"
    9.61 +
    9.62 +#ifndef ASM_FILE
    9.63 +
    9.64 +#ifndef __sun
    9.65 +#ifndef	__BIT_TYPES_DEFINED__
    9.66 +typedef		 int	 int8_t	__attribute__((mode(QI)));
    9.67 +typedef unsigned int   u_int8_t	__attribute__((mode(QI)));
    9.68 +typedef		 int	int16_t	__attribute__((mode(HI)));
    9.69 +typedef unsigned int  u_int16_t	__attribute__((mode(HI)));
    9.70 +typedef		 int	int32_t	__attribute__((mode(SI)));
    9.71 +typedef unsigned int  u_int32_t	__attribute__((mode(SI)));
    9.72 +#endif
    9.73 +#else
    9.74 +#ifndef GRUB_UTIL
    9.75 +typedef		 char  int8_t;
    9.76 +typedef		 short int16_t;
    9.77 +typedef		 int   int32_t;
    9.78 +#endif /* ! GRUB_UTIL */
    9.79 +typedef unsigned char  u_int8_t;
    9.80 +typedef unsigned short u_int16_t;
    9.81 +typedef unsigned int   u_int32_t;
    9.82 +#endif /* __sun */
    9.83 +
    9.84 +typedef	union {
    9.85 +  u_int8_t l,b;
    9.86 +}	iso_8bit_t;
    9.87 +
    9.88 +struct __iso_16bit {
    9.89 +  u_int16_t l, b;
    9.90 +} __attribute__ ((packed));
    9.91 +typedef	struct __iso_16bit iso_16bit_t;
    9.92 +
    9.93 +struct __iso_32bit {
    9.94 +  u_int32_t l, b;
    9.95 +} __attribute__ ((packed));
    9.96 +typedef	struct __iso_32bit iso_32bit_t;
    9.97 +
    9.98 +typedef u_int8_t		iso_date_t[7];
    9.99 +
   9.100 +struct iso_directory_record {
   9.101 +  iso_8bit_t	length;
   9.102 +  iso_8bit_t	ext_attr_length;
   9.103 +  iso_32bit_t	extent;
   9.104 +  iso_32bit_t	size;
   9.105 +  iso_date_t	date;
   9.106 +  iso_8bit_t	flags;
   9.107 +  iso_8bit_t	file_unit_size;
   9.108 +  iso_8bit_t	interleave;
   9.109 +  iso_16bit_t	volume_seq_number;
   9.110 +  iso_8bit_t	name_len;
   9.111 +  u_int8_t	name[1];
   9.112 +} __attribute__ ((packed));
   9.113 +
   9.114 +struct iso_primary_descriptor {
   9.115 +  iso_8bit_t	type;
   9.116 +  u_int8_t	id[5];
   9.117 +  iso_8bit_t	version;
   9.118 +  u_int8_t	_unused1[1];
   9.119 +  u_int8_t	system_id[32];
   9.120 +  u_int8_t	volume_id[32];
   9.121 +  u_int8_t	_unused2[8];
   9.122 +  iso_32bit_t	volume_space_size;
   9.123 +  u_int8_t	_unused3[32];
   9.124 +  iso_16bit_t	volume_set_size;
   9.125 +  iso_16bit_t	volume_seq_number;
   9.126 +  iso_16bit_t	logical_block_size;
   9.127 +  iso_32bit_t	path_table_size;
   9.128 +  u_int8_t	type_l_path_table[4];
   9.129 +  u_int8_t	opt_type_l_path_table[4];
   9.130 +  u_int8_t	type_m_path_table[4];
   9.131 +  u_int8_t	opt_type_m_path_table[4];
   9.132 +  struct iso_directory_record root_directory_record;
   9.133 +  u_int8_t	volume_set_id[128];
   9.134 +  u_int8_t	publisher_id[128];
   9.135 +  u_int8_t	preparer_id[128];
   9.136 +  u_int8_t	application_id[128];
   9.137 +  u_int8_t	copyright_file_id[37];
   9.138 +  u_int8_t	abstract_file_id[37];
   9.139 +  u_int8_t	bibliographic_file_id[37];
   9.140 +  u_int8_t	creation_date[17];
   9.141 +  u_int8_t	modification_date[17];
   9.142 +  u_int8_t	expiration_date[17];
   9.143 +  u_int8_t	effective_date[17];
   9.144 +  iso_8bit_t	file_structure_version;
   9.145 +  u_int8_t	_unused4[1];
   9.146 +  u_int8_t	application_data[512];
   9.147 +  u_int8_t	_unused5[653];
   9.148 +} __attribute__ ((packed));
   9.149 +
   9.150 +struct rock_ridge {
   9.151 +  u_int16_t	signature;
   9.152 +  u_int8_t	len;
   9.153 +  u_int8_t	version;
   9.154 +  union {
   9.155 +    struct SP {
   9.156 +      u_int16_t	magic;
   9.157 +      u_int8_t	skip;
   9.158 +    } sp;
   9.159 +    struct CE {
   9.160 +      iso_32bit_t	extent;
   9.161 +      iso_32bit_t	offset;
   9.162 +      iso_32bit_t	size;
   9.163 +    } ce;
   9.164 +    struct ER {
   9.165 +      u_int8_t	len_id;
   9.166 +      u_int8_t	len_des;
   9.167 +      u_int8_t	len_src;
   9.168 +      u_int8_t	ext_ver;
   9.169 +      u_int8_t	data[0];
   9.170 +    } er;
   9.171 +    struct RR {
   9.172 +      iso_8bit_t	flags;
   9.173 +    } rr;
   9.174 +    struct PX {
   9.175 +      iso_32bit_t	mode;
   9.176 +      iso_32bit_t	nlink;
   9.177 +      iso_32bit_t	uid;
   9.178 +      iso_32bit_t	gid;
   9.179 +    } px;
   9.180 +    struct PN {
   9.181 +      iso_32bit_t	dev_high;
   9.182 +      iso_32bit_t	dev_low;
   9.183 +    } pn;
   9.184 +    struct SL {
   9.185 +      iso_8bit_t flags;
   9.186 +      struct SL_component {
   9.187 +	iso_8bit_t	flags;
   9.188 +	u_int8_t		len;
   9.189 +	u_int8_t		text[0];
   9.190 +      } link;
   9.191 +    } sl;
   9.192 +    struct NM {
   9.193 +      iso_8bit_t	flags;
   9.194 +      u_int8_t	name[0];
   9.195 +    } nm;
   9.196 +    struct CL {
   9.197 +      iso_32bit_t	location;
   9.198 +    } cl;
   9.199 +    struct PL {
   9.200 +      iso_32bit_t	location;
   9.201 +    } pl;
   9.202 +    struct TF {
   9.203 +      iso_8bit_t	flags;
   9.204 +      iso_date_t	times[0];
   9.205 +    } tf;
   9.206 +  } u;
   9.207 +} __attribute__ ((packed));
   9.208 +
   9.209 +typedef	union RR_ptr {
   9.210 +  struct rock_ridge *rr;
   9.211 +  char		  *ptr;
   9.212 +  int		   i;
   9.213 +} RR_ptr_t;
   9.214 +
   9.215 +#define	RRMAGIC(c1, c2)	((c1)|(c2) << 8)
   9.216 +
   9.217 +#define	CHECK2(ptr, c1, c2) \
   9.218 +	(*(unsigned short *)(ptr) == (((c1) | (c2) << 8) & 0xFFFF))
   9.219 +
   9.220 +#endif /* !ASM_FILE */
   9.221 +
   9.222 +#endif /* _ISO9660_H_ */
    10.1 --- a/tools/libfsimage/reiserfs/fsys_reiserfs.c	Wed Feb 21 10:13:40 2007 +0000
    10.2 +++ b/tools/libfsimage/reiserfs/fsys_reiserfs.c	Tue Feb 20 14:54:04 2007 -0800
    10.3 @@ -363,83 +363,6 @@ struct fsys_reiser_info
    10.4  #define JOURNAL_START    ((__u32 *) (INFO + 1))
    10.5  #define JOURNAL_END      ((__u32 *) (FSYS_BUF + FSYS_BUFLEN))
    10.6  
    10.7 -#if defined(__i386__) || defined(__x86_64__)
    10.8 -
    10.9 -#ifdef __amd64
   10.10 -#define BSF "bsfq"
   10.11 -#else
   10.12 -#define BSF "bsfl"
   10.13 -#endif
   10.14 -static __inline__ unsigned long
   10.15 -grub_log2 (unsigned long word)
   10.16 -{
   10.17 -  __asm__ (BSF " %1,%0"
   10.18 -	   : "=r" (word)
   10.19 -	   : "r" (word));
   10.20 -  return word;
   10.21 -}
   10.22 -
   10.23 -#elif defined(__ia64__)
   10.24 -
   10.25 -#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
   10.26 -# define ia64_popcnt(x) __builtin_popcountl(x)
   10.27 -#else
   10.28 -# define ia64_popcnt(x)                                     \
   10.29 -  ({                                                        \
   10.30 -    __u64 ia64_intri_res;                                   \
   10.31 -    asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x)); \
   10.32 -    ia64_intri_res;                                         \
   10.33 -  })
   10.34 -#endif
   10.35 -
   10.36 -static __inline__ unsigned long
   10.37 -grub_log2 (unsigned long word)
   10.38 -{
   10.39 -  unsigned long result;
   10.40 -
   10.41 -  result = ia64_popcnt((word - 1) & ~word);
   10.42 -  return result;
   10.43 -}
   10.44 -
   10.45 -#elif defined(__powerpc__)
   10.46 -
   10.47 -#ifdef __powerpc64__
   10.48 -#define PPC_CNTLZL "cntlzd"
   10.49 -#else
   10.50 -#define PPC_CNTLZL "cntlzw"
   10.51 -#endif
   10.52 -#define BITS_PER_LONG (sizeof(long) * 8)
   10.53 -
   10.54 -static __inline__ int
   10.55 -__ilog2(unsigned long x)
   10.56 -{
   10.57 -  int lz;
   10.58 -
   10.59 -  asm (PPC_CNTLZL " %0,%1" : "=r" (lz) : "r" (x));
   10.60 -  return BITS_PER_LONG - 1 - lz;
   10.61 -}
   10.62 -
   10.63 -static __inline__ unsigned long
   10.64 -grub_log2 (unsigned long word)
   10.65 -{
   10.66 -  return __ilog2(word & -word);
   10.67 -}
   10.68 -
   10.69 -#else /* Unoptimized */
   10.70 -
   10.71 -static __inline__ unsigned long
   10.72 -grub_log2 (unsigned long word)
   10.73 -{
   10.74 -  unsigned long result = 0;
   10.75 -
   10.76 -  while (!(word & 1UL))
   10.77 -    {
   10.78 -      result++;
   10.79 -      word >>= 1;
   10.80 -    }
   10.81 -  return result;
   10.82 -}
   10.83 -#endif
   10.84  #define log2 grub_log2
   10.85  
   10.86  static __inline__ int