Skip to Content

手动修改2.6.30内核源码 让其同时支持squashfs和lzma

无线电子 的头像
fs/squashfs/Kconfig
2 2         tristate "SquashFS 4.0 - Squashed file system support"  
3 3         depends on BLOCK  
4 4         select CRYPTO  
5           select CRYPTO_ZLIB  
6 5         help  
7 6           Saying Y here includes support for SquashFS 4.0 (a Compressed  
8 7           Read-Only File System).  Squashfs is a highly compressed read-only  
鈥?/a> 鈥?/a>   
37 36   
38 37           If unsure, say N.  
39 38   
  39 config SQUASHFS_SUPPORT_ZLIB  
  40         bool  
  41         prompt "Support ZLIB compression" if SQUASHFS_SUPPORT_LZMA  
  42         depends on SQUASHFS  
  43         select CRYPTO_ZLIB  
  44         default y  
  45         help  
  46           ZLIB is the default compression used in squashfs. If you are  
  47           using LZMA compression instead, you can remove support for ZLIB  
  48           entirely.  
  49   
  50 config SQUASHFS_SUPPORT_LZMA  
  51         bool "Support LZMA compression"  
  52         depends on SQUASHFS  
  53         select CRYPTO_LZMA  
  54         help  
  55           By default SquashFS uses ZLIB compression, however (if your tools  
  56           support it, you can use LZMA instead, which saves space.  
  57   
  58   
40 59 config SQUASHFS_FRAGMENT_CACHE_SIZE  
41 60         int "Number of fragments cached" if SQUASHFS_EMBEDDED  
42 61         depends on SQUASHFS  
TabularUnified fs/squashfs/squashfs_fs.h
212 212  * definitions for structures on disk  
213 213  */  
214 214 #define ZLIB_COMPRESSION         1  
  215 #define LZMA_COMPRESSION         2  
215 216   
216 217 struct squashfs_super_block {  
217 218         __le32                  s_magic; 
TabularUnified fs/squashfs/super.c
47 47 #include "squashfs.h"  
48 48   
49 49   
50   #define SQUASHFS_CRYPTO_ALG     "zlib"  
  50 static int squashfs_setup_zlib(struct squashfs_sb_info *msblk)  
  51 {  
  52         int err = -EOPNOTSUPP;  
  53   
  54 #ifdef CONFIG_SQUASHFS_SUPPORT_ZLIB  
  55         struct {  
  56                 struct nlattr nla;  
  57                 int val;  
  58         } params = {  
  59                 .nla = {  
  60                         .nla_len        = nla_attr_size(sizeof(int)),  
  61                         .nla_type       = ZLIB_DECOMP_WINDOWBITS,  
  62                 },  
  63                 .val                    = DEF_WBITS,  
  64         };  
  65   
  66         msblk->tfm = crypto_alloc_pcomp("zlib", 0,  
  67                                         CRYPTO_ALG_ASYNC);  
  68         if (IS_ERR(msblk->tfm)) {  
  69                 ERROR("Failed to load zlib crypto module\n");  
  70                 return PTR_ERR(msblk->tfm);  
  71         }  
  72   
  73         err = crypto_decompress_setup(msblk->tfm, &params, sizeof(params));  
  74         if (err) {  
  75                 ERROR("Failed to set up decompression parameters\n");  
  76                 crypto_free_pcomp(msblk->tfm);  
  77         }  
  78 #endif  
51 79   
  80         return err;  
  81 }  
  82   
  83 static int squashfs_setup_lzma(struct squashfs_sb_info *msblk)  
  84 {  
  85         int err = -EOPNOTSUPP;  
  86   
  87 #ifdef CONFIG_SQUASHFS_SUPPORT_LZMA  
  88         msblk->tfm = crypto_alloc_pcomp("lzma", 0,  
  89                                         CRYPTO_ALG_ASYNC);  
  90         if (IS_ERR(msblk->tfm)) {  
  91                 ERROR("Failed to load lzma crypto module\n");  
  92                 return PTR_ERR(msblk->tfm);  
  93         }  
  94   
  95         err = crypto_decompress_setup(msblk->tfm, NULL, 0);  
  96         if (err) {  
  97                 ERROR("Failed to set up decompression parameters\n");  
  98                 crypto_free_pcomp(msblk->tfm);  
  99         }  
  100 #endif  
  101   
  102         return err;  
  103 }  
52 104   
53 105 static struct file_system_type squashfs_fs_type;  
54 106 static struct super_operations squashfs_super_ops;  
55 107   
56   static int supported_squashfs_filesystem(short major, short minor, short comp)  
  108 static int supported_squashfs_filesystem(short major, short minor)  
57 109 {  
58 110         if (major < SQUASHFS_MAJOR) {  
59 111                 ERROR("Major/Minor mismatch, older Squashfs %d.%d "  
鈥?/a> 鈥?/a>   
66 118                 return -EINVAL;  
67 119         }  
68 120   
69           if (comp != ZLIB_COMPRESSION)  
70                   return -EINVAL;  
71     
72 121         return 0;  
73 122 }  
74 123   
鈥?/a> 鈥?/a>   
83 132         unsigned short flags;  
84 133         unsigned int fragments;  
85 134         u64 lookup_table_start;  
86           struct {  
87                   struct nlattr nla;  
88                   int val;  
89           } params = {  
90                   .nla = {  
91                           .nla_len        = nla_attr_size(sizeof(int)),  
92                           .nla_type       = ZLIB_DECOMP_WINDOWBITS,  
93                   },  
94                   .val                    = DEF_WBITS,  
95           };  
96 135         int err;  
97 136   
98 137         TRACE("Entered squashfs_fill_superblock\n");  
鈥?/a> 鈥?/a>   
104 143         }  
105 144         msblk = sb->s_fs_info;  
106 145   
107           msblk->tfm = crypto_alloc_pcomp(SQUASHFS_CRYPTO_ALG, 0,  
108                                           CRYPTO_ALG_ASYNC);  
109           if (IS_ERR(msblk->tfm)) {  
110                   ERROR("Failed to load %s crypto module\n",  
111                         SQUASHFS_CRYPTO_ALG);  
112                   err = PTR_ERR(msblk->tfm);  
113                   goto failed_pcomp;  
114           }  
115     
116           err = crypto_decompress_setup(msblk->tfm, &params, sizeof(params));  
117           if (err) {  
118                   ERROR("Failed to set up decompression parameters\n");  
119                   goto failure;  
120           }  
121     
122 146         sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);  
123 147         if (sblk == NULL) {  
124 148                 ERROR("Failed to allocate squashfs_super_block\n");  
鈥?/a> 鈥?/a>   
158 182   
159 183         /* Check the MAJOR & MINOR versions and compression type */  
160 184         err = supported_squashfs_filesystem(le16_to_cpu(sblk->s_major),  
161                           le16_to_cpu(sblk->s_minor),  
162                           le16_to_cpu(sblk->compression));  
  185                         le16_to_cpu(sblk->s_minor));  
  186         if (err < 0)  
  187                 goto failed_mount;  
  188   
  189         switch(le16_to_cpu(sblk->compression)) {  
  190         case ZLIB_COMPRESSION:  
  191                 err = squashfs_setup_zlib(msblk);  
  192                 break;  
  193         case LZMA_COMPRESSION:  
  194                 err = squashfs_setup_lzma(msblk);  
  195                 break;  
  196         default:  
  197                 err = -EINVAL;  
  198                 break;  
  199         }  
163 200         if (err < 0)  
164 201                 goto failed_mount;  
165 202   
鈥?/a> 鈥?/a>   
305 342         return 0;  
306 343   
307 344 failed_mount:  
  345         if (msblk->tfm)  
  346                 crypto_free_pcomp(msblk->tfm);  
308 347         squashfs_cache_delete(msblk->block_cache);  
309 348         squashfs_cache_delete(msblk->fragment_cache);  
310 349         squashfs_cache_delete(msblk->read_page);  
311 350         kfree(msblk->inode_lookup_table);  
312 351         kfree(msblk->fragment_index);  
313 352         kfree(msblk->id_table);  
314           crypto_free_pcomp(msblk->tfm);  
315           kfree(sb->s_fs_info);  
316           sb->s_fs_info = NULL;  
317 353         kfree(sblk);  
318           return err;  
319     
320 354 failure:  
321           crypto_free_pcomp(msblk->tfm);  
322   failed_pcomp:  
323 355         kfree(sb->s_fs_info);  
324 356         sb->s_fs_info = NULL;  
325 357         return err;  
#6580
sasaqqdan 的头像
辛苦了。
#16156
好多没定义,编译不过啊

发表新评论

  • 你可以在文本中使用BBCode标记语言。 URL会自动被转为链接。

更多关於格式化选项的信息

CAPTCHA
请验证您是否是机器人。
Image CAPTCHA
Enter the characters shown in the image.