Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/fs/squashfs/inode.c (Version 2.6.31.13) and /linux/fs/squashfs/inode.c (Version 2.6.25.8)


  1 /*                                                  1 
  2  * Squashfs - a compressed read only filesyste    
  3  *                                                
  4  * Copyright (c) 2002, 2003, 2004, 2005, 2006,    
  5  * Phillip Lougher <phillip@lougher.demon.co.u    
  6  *                                                
  7  * This program is free software; you can redi    
  8  * modify it under the terms of the GNU Genera    
  9  * as published by the Free Software Foundatio    
 10  * or (at your option) any later version.         
 11  *                                                
 12  * This program is distributed in the hope tha    
 13  * but WITHOUT ANY WARRANTY; without even the     
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR    
 15  * GNU General Public License for more details    
 16  *                                                
 17  * You should have received a copy of the GNU     
 18  * along with this program; if not, write to t    
 19  * Foundation, 51 Franklin Street, Fifth Floor    
 20  *                                                
 21  * inode.c                                        
 22  */                                               
 23                                                   
 24 /*                                                
 25  * This file implements code to create and rea    
 26  *                                                
 27  * Inodes in Squashfs are identified by a 48-b    
 28  * location of the compressed metadata block c    
 29  * offset into that block where the inode is p    
 30  *                                                
 31  * To maximise compression there are different    
 32  * (regular file, directory, device, etc.), th    
 33  * varying with the type.                         
 34  *                                                
 35  * To further maximise compression, two types     
 36  * directory inode are defined: inodes optimis    
 37  * regular files and directories, and extended    
 38  * information has to be stored.                  
 39  */                                               
 40                                                   
 41 #include <linux/fs.h>                             
 42 #include <linux/vfs.h>                            
 43 #include <linux/zlib.h>                           
 44                                                   
 45 #include "squashfs_fs.h"                          
 46 #include "squashfs_fs_sb.h"                       
 47 #include "squashfs_fs_i.h"                        
 48 #include "squashfs.h"                             
 49                                                   
 50 /*                                                
 51  * Initialise VFS inode with the base inode in    
 52  * Squashfs inode types.  Sqsh_ino contains th    
 53  * off disk.                                      
 54  */                                               
 55 static int squashfs_new_inode(struct super_blo    
 56                                 struct squashf    
 57 {                                                 
 58         int err;                                  
 59                                                   
 60         err = squashfs_get_id(sb, le16_to_cpu(    
 61         if (err)                                  
 62                 return err;                       
 63                                                   
 64         err = squashfs_get_id(sb, le16_to_cpu(    
 65         if (err)                                  
 66                 return err;                       
 67                                                   
 68         inode->i_ino = le32_to_cpu(sqsh_ino->i    
 69         inode->i_mtime.tv_sec = le32_to_cpu(sq    
 70         inode->i_atime.tv_sec = inode->i_mtime    
 71         inode->i_ctime.tv_sec = inode->i_mtime    
 72         inode->i_mode = le16_to_cpu(sqsh_ino->    
 73         inode->i_size = 0;                        
 74                                                   
 75         return err;                               
 76 }                                                 
 77                                                   
 78                                                   
 79 struct inode *squashfs_iget(struct super_block    
 80                                 unsigned int i    
 81 {                                                 
 82         struct inode *inode = iget_locked(sb,     
 83         int err;                                  
 84                                                   
 85         TRACE("Entered squashfs_iget\n");         
 86                                                   
 87         if (!inode)                               
 88                 return ERR_PTR(-ENOMEM);          
 89         if (!(inode->i_state & I_NEW))            
 90                 return inode;                     
 91                                                   
 92         err = squashfs_read_inode(inode, ino);    
 93         if (err) {                                
 94                 iget_failed(inode);               
 95                 return ERR_PTR(err);              
 96         }                                         
 97                                                   
 98         unlock_new_inode(inode);                  
 99         return inode;                             
100 }                                                 
101                                                   
102                                                   
103 /*                                                
104  * Initialise VFS inode by reading inode from     
105  * metadata).  The format and amount of data r    
106  */                                               
107 int squashfs_read_inode(struct inode *inode, l    
108 {                                                 
109         struct super_block *sb = inode->i_sb;     
110         struct squashfs_sb_info *msblk = sb->s    
111         u64 block = SQUASHFS_INODE_BLK(ino) +     
112         int err, type, offset = SQUASHFS_INODE    
113         union squashfs_inode squashfs_ino;        
114         struct squashfs_base_inode *sqshb_ino     
115                                                   
116         TRACE("Entered squashfs_read_inode\n")    
117                                                   
118         /*                                        
119          * Read inode base common to all inode    
120          */                                       
121         err = squashfs_read_metadata(sb, sqshb    
122                                 &offset, sizeo    
123         if (err < 0)                              
124                 goto failed_read;                 
125                                                   
126         err = squashfs_new_inode(sb, inode, sq    
127         if (err)                                  
128                 goto failed_read;                 
129                                                   
130         block = SQUASHFS_INODE_BLK(ino) + msbl    
131         offset = SQUASHFS_INODE_OFFSET(ino);      
132                                                   
133         type = le16_to_cpu(sqshb_ino->inode_ty    
134         switch (type) {                           
135         case SQUASHFS_REG_TYPE: {                 
136                 unsigned int frag_offset, frag    
137                 int frag_size;                    
138                 u64 frag_blk;                     
139                 struct squashfs_reg_inode *sqs    
140                                                   
141                 err = squashfs_read_metadata(s    
142                                                   
143                 if (err < 0)                      
144                         goto failed_read;         
145                                                   
146                 frag = le32_to_cpu(sqsh_ino->f    
147                 if (frag != SQUASHFS_INVALID_F    
148                         frag_offset = le32_to_    
149                         frag_size = squashfs_f    
150                         if (frag_size < 0) {      
151                                 err = frag_siz    
152                                 goto failed_re    
153                         }                         
154                 } else {                          
155                         frag_blk = SQUASHFS_IN    
156                         frag_size = 0;            
157                         frag_offset = 0;          
158                 }                                 
159                                                   
160                 inode->i_nlink = 1;               
161                 inode->i_size = le32_to_cpu(sq    
162                 inode->i_fop = &generic_ro_fop    
163                 inode->i_mode |= S_IFREG;         
164                 inode->i_blocks = ((inode->i_s    
165                 squashfs_i(inode)->fragment_bl    
166                 squashfs_i(inode)->fragment_si    
167                 squashfs_i(inode)->fragment_of    
168                 squashfs_i(inode)->start = le3    
169                 squashfs_i(inode)->block_list_    
170                 squashfs_i(inode)->offset = of    
171                 inode->i_data.a_ops = &squashf    
172                                                   
173                 TRACE("File inode %x:%x, start    
174                         "%llx, offset %x\n", S    
175                         offset, squashfs_i(ino    
176                 break;                            
177         }                                         
178         case SQUASHFS_LREG_TYPE: {                
179                 unsigned int frag_offset, frag    
180                 int frag_size;                    
181                 u64 frag_blk;                     
182                 struct squashfs_lreg_inode *sq    
183                                                   
184                 err = squashfs_read_metadata(s    
185                                                   
186                 if (err < 0)                      
187                         goto failed_read;         
188                                                   
189                 frag = le32_to_cpu(sqsh_ino->f    
190                 if (frag != SQUASHFS_INVALID_F    
191                         frag_offset = le32_to_    
192                         frag_size = squashfs_f    
193                         if (frag_size < 0) {      
194                                 err = frag_siz    
195                                 goto failed_re    
196                         }                         
197                 } else {                          
198                         frag_blk = SQUASHFS_IN    
199                         frag_size = 0;            
200                         frag_offset = 0;          
201                 }                                 
202                                                   
203                 inode->i_nlink = le32_to_cpu(s    
204                 inode->i_size = le64_to_cpu(sq    
205                 inode->i_fop = &generic_ro_fop    
206                 inode->i_mode |= S_IFREG;         
207                 inode->i_blocks = ((inode->i_s    
208                                 le64_to_cpu(sq    
209                                                   
210                 squashfs_i(inode)->fragment_bl    
211                 squashfs_i(inode)->fragment_si    
212                 squashfs_i(inode)->fragment_of    
213                 squashfs_i(inode)->start = le6    
214                 squashfs_i(inode)->block_list_    
215                 squashfs_i(inode)->offset = of    
216                 inode->i_data.a_ops = &squashf    
217                                                   
218                 TRACE("File inode %x:%x, start    
219                         "%llx, offset %x\n", S    
220                         offset, squashfs_i(ino    
221                 break;                            
222         }                                         
223         case SQUASHFS_DIR_TYPE: {                 
224                 struct squashfs_dir_inode *sqs    
225                                                   
226                 err = squashfs_read_metadata(s    
227                                 sizeof(*sqsh_i    
228                 if (err < 0)                      
229                         goto failed_read;         
230                                                   
231                 inode->i_nlink = le32_to_cpu(s    
232                 inode->i_size = le16_to_cpu(sq    
233                 inode->i_op = &squashfs_dir_in    
234                 inode->i_fop = &squashfs_dir_o    
235                 inode->i_mode |= S_IFDIR;         
236                 squashfs_i(inode)->start = le3    
237                 squashfs_i(inode)->offset = le    
238                 squashfs_i(inode)->dir_idx_cnt    
239                 squashfs_i(inode)->parent = le    
240                                                   
241                 TRACE("Directory inode %x:%x,     
242                                 SQUASHFS_INODE    
243                                 squashfs_i(ino    
244                                 le16_to_cpu(sq    
245                 break;                            
246         }                                         
247         case SQUASHFS_LDIR_TYPE: {                
248                 struct squashfs_ldir_inode *sq    
249                                                   
250                 err = squashfs_read_metadata(s    
251                                 sizeof(*sqsh_i    
252                 if (err < 0)                      
253                         goto failed_read;         
254                                                   
255                 inode->i_nlink = le32_to_cpu(s    
256                 inode->i_size = le32_to_cpu(sq    
257                 inode->i_op = &squashfs_dir_in    
258                 inode->i_fop = &squashfs_dir_o    
259                 inode->i_mode |= S_IFDIR;         
260                 squashfs_i(inode)->start = le3    
261                 squashfs_i(inode)->offset = le    
262                 squashfs_i(inode)->dir_idx_sta    
263                 squashfs_i(inode)->dir_idx_off    
264                 squashfs_i(inode)->dir_idx_cnt    
265                 squashfs_i(inode)->parent = le    
266                                                   
267                 TRACE("Long directory inode %x    
268                                 "%x\n", SQUASH    
269                                 squashfs_i(ino    
270                                 le16_to_cpu(sq    
271                 break;                            
272         }                                         
273         case SQUASHFS_SYMLINK_TYPE:               
274         case SQUASHFS_LSYMLINK_TYPE: {            
275                 struct squashfs_symlink_inode     
276                                                   
277                 err = squashfs_read_metadata(s    
278                                 sizeof(*sqsh_i    
279                 if (err < 0)                      
280                         goto failed_read;         
281                                                   
282                 inode->i_nlink = le32_to_cpu(s    
283                 inode->i_size = le32_to_cpu(sq    
284                 inode->i_op = &page_symlink_in    
285                 inode->i_data.a_ops = &squashf    
286                 inode->i_mode |= S_IFLNK;         
287                 squashfs_i(inode)->start = blo    
288                 squashfs_i(inode)->offset = of    
289                                                   
290                 TRACE("Symbolic link inode %x:    
291                                 "%x\n", SQUASH    
292                                 block, offset)    
293                 break;                            
294         }                                         
295         case SQUASHFS_BLKDEV_TYPE:                
296         case SQUASHFS_CHRDEV_TYPE:                
297         case SQUASHFS_LBLKDEV_TYPE:               
298         case SQUASHFS_LCHRDEV_TYPE: {             
299                 struct squashfs_dev_inode *sqs    
300                 unsigned int rdev;                
301                                                   
302                 err = squashfs_read_metadata(s    
303                                 sizeof(*sqsh_i    
304                 if (err < 0)                      
305                         goto failed_read;         
306                                                   
307                 if (type == SQUASHFS_CHRDEV_TY    
308                         inode->i_mode |= S_IFC    
309                 else                              
310                         inode->i_mode |= S_IFB    
311                 inode->i_nlink = le32_to_cpu(s    
312                 rdev = le32_to_cpu(sqsh_ino->r    
313                 init_special_inode(inode, inod    
314                                                   
315                 TRACE("Device inode %x:%x, rde    
316                                 SQUASHFS_INODE    
317                 break;                            
318         }                                         
319         case SQUASHFS_FIFO_TYPE:                  
320         case SQUASHFS_SOCKET_TYPE:                
321         case SQUASHFS_LFIFO_TYPE:                 
322         case SQUASHFS_LSOCKET_TYPE: {             
323                 struct squashfs_ipc_inode *sqs    
324                                                   
325                 err = squashfs_read_metadata(s    
326                                 sizeof(*sqsh_i    
327                 if (err < 0)                      
328                         goto failed_read;         
329                                                   
330                 if (type == SQUASHFS_FIFO_TYPE    
331                         inode->i_mode |= S_IFI    
332                 else                              
333                         inode->i_mode |= S_IFS    
334                 inode->i_nlink = le32_to_cpu(s    
335                 init_special_inode(inode, inod    
336                 break;                            
337         }                                         
338         default:                                  
339                 ERROR("Unknown inode type %d i    
340                 return -EINVAL;                   
341         }                                         
342                                                   
343         return 0;                                 
344                                                   
345 failed_read:                                      
346         ERROR("Unable to read inode 0x%llx\n",    
347         return err;                               
348 }                                                 
349                                                   
  This page was automatically generated by the LXR engine.