| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * symlink.c | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * PURPOSE | 
					
						
							|  |  |  |  *	Symlink handling routines for the OSTA-UDF(tm) filesystem. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * COPYRIGHT | 
					
						
							|  |  |  |  *	This file is distributed under the terms of the GNU General Public | 
					
						
							|  |  |  |  *	License (GPL). Copies of the GPL can be obtained from: | 
					
						
							|  |  |  |  *		ftp://prep.ai.mit.edu/pub/gnu/GPL
 | 
					
						
							|  |  |  |  *	Each contributing author retains all rights to their own work. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  (C) 1998-2001 Ben Fennema | 
					
						
							| 
									
										
										
										
											2007-07-21 04:37:18 -07:00
										 |  |  |  *  (C) 1999 Stelias Computing Inc | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * HISTORY | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  04/16/99 blf  Created. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "udfdecl.h"
 | 
					
						
							|  |  |  | #include <asm/uaccess.h>
 | 
					
						
							|  |  |  | #include <linux/errno.h>
 | 
					
						
							|  |  |  | #include <linux/fs.h>
 | 
					
						
							|  |  |  | #include <linux/time.h>
 | 
					
						
							|  |  |  | #include <linux/mm.h>
 | 
					
						
							|  |  |  | #include <linux/stat.h>
 | 
					
						
							|  |  |  | #include <linux/pagemap.h>
 | 
					
						
							|  |  |  | #include <linux/buffer_head.h>
 | 
					
						
							|  |  |  | #include "udf_i.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 21:28:48 -05:00
										 |  |  | static void udf_pc_to_char(struct super_block *sb, unsigned char *from, | 
					
						
							|  |  |  | 			   int fromlen, unsigned char *to) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct pathComponent *pc; | 
					
						
							|  |  |  | 	int elen = 0; | 
					
						
							| 
									
										
										
										
											2010-01-31 21:28:48 -05:00
										 |  |  | 	unsigned char *p = to; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 01:47:43 -07:00
										 |  |  | 	while (elen < fromlen) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		pc = (struct pathComponent *)(from + elen); | 
					
						
							| 
									
										
										
										
											2007-07-19 01:47:43 -07:00
										 |  |  | 		switch (pc->componentType) { | 
					
						
							|  |  |  | 		case 1: | 
					
						
							| 
									
										
										
										
											2011-12-12 15:13:50 +01:00
										 |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * Symlink points to some place which should be agreed | 
					
						
							|  |  |  |  			 * upon between originator and receiver of the media. Ignore. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (pc->lengthComponentIdent > 0) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			/* Fall through */ | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			p = to; | 
					
						
							|  |  |  | 			*p++ = '/'; | 
					
						
							| 
									
										
										
										
											2007-07-19 01:47:43 -07:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 3: | 
					
						
							|  |  |  | 			memcpy(p, "../", 3); | 
					
						
							|  |  |  | 			p += 3; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 4: | 
					
						
							|  |  |  | 			memcpy(p, "./", 2); | 
					
						
							|  |  |  | 			p += 2; | 
					
						
							|  |  |  | 			/* that would be . - just ignore */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 5: | 
					
						
							|  |  |  | 			p += udf_get_filename(sb, pc->componentIdent, p, | 
					
						
							|  |  |  | 					      pc->lengthComponentIdent); | 
					
						
							|  |  |  | 			*p++ = '/'; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		elen += sizeof(struct pathComponent) + pc->lengthComponentIdent; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-07-19 01:47:43 -07:00
										 |  |  | 	if (p > to + 1) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		p[-1] = '\0'; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		p[0] = '\0'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int udf_symlink_filler(struct file *file, struct page *page) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct inode *inode = page->mapping->host; | 
					
						
							|  |  |  | 	struct buffer_head *bh = NULL; | 
					
						
							| 
									
										
										
										
											2010-01-31 21:28:48 -05:00
										 |  |  | 	unsigned char *symlink; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	int err = -EIO; | 
					
						
							| 
									
										
										
										
											2010-01-31 21:28:48 -05:00
										 |  |  | 	unsigned char *p = kmap(page); | 
					
						
							| 
									
										
										
										
											2008-02-08 04:20:44 -08:00
										 |  |  | 	struct udf_inode_info *iinfo; | 
					
						
							| 
									
										
										
										
											2010-11-16 18:40:47 +01:00
										 |  |  | 	uint32_t pos; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-08 04:20:44 -08:00
										 |  |  | 	iinfo = UDF_I(inode); | 
					
						
							| 
									
										
										
										
											2010-11-16 18:40:47 +01:00
										 |  |  | 	pos = udf_block_map(inode, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	down_read(&iinfo->i_data_sem); | 
					
						
							| 
									
										
										
										
											2008-02-08 04:20:44 -08:00
										 |  |  | 	if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { | 
					
						
							|  |  |  | 		symlink = iinfo->i_ext.i_data + iinfo->i_lenEAttr; | 
					
						
							| 
									
										
										
										
											2007-07-21 04:37:18 -07:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2010-11-16 18:40:47 +01:00
										 |  |  | 		bh = sb_bread(inode->i_sb, pos); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!bh) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		symlink = bh->b_data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p); | 
					
						
							| 
									
										
										
										
											2007-05-08 00:35:16 -07:00
										 |  |  | 	brelse(bh); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-16 18:40:47 +01:00
										 |  |  | 	up_read(&iinfo->i_data_sem); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	SetPageUptodate(page); | 
					
						
							|  |  |  | 	kunmap(page); | 
					
						
							|  |  |  | 	unlock_page(page); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2007-07-21 04:37:18 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | out: | 
					
						
							| 
									
										
										
										
											2010-11-16 18:40:47 +01:00
										 |  |  | 	up_read(&iinfo->i_data_sem); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	SetPageError(page); | 
					
						
							|  |  |  | 	kunmap(page); | 
					
						
							|  |  |  | 	unlock_page(page); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * symlinks can't do much... | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-06-28 04:26:44 -07:00
										 |  |  | const struct address_space_operations udf_symlink_aops = { | 
					
						
							| 
									
										
										
										
											2007-07-21 04:37:18 -07:00
										 |  |  | 	.readpage		= udf_symlink_filler, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; |