Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * namei.c |
| 3 | * |
| 4 | * PURPOSE |
| 5 | * Inode name handling routines for the OSTA-UDF(tm) filesystem. |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * COPYRIGHT |
| 8 | * This file is distributed under the terms of the GNU General Public |
| 9 | * License (GPL). Copies of the GPL can be obtained from: |
| 10 | * ftp://prep.ai.mit.edu/pub/gnu/GPL |
| 11 | * Each contributing author retains all rights to their own work. |
| 12 | * |
| 13 | * (C) 1998-2004 Ben Fennema |
| 14 | * (C) 1999-2000 Stelias Computing Inc |
| 15 | * |
| 16 | * HISTORY |
| 17 | * |
| 18 | * 12/12/98 blf Created. Split out the lookup code from dir.c |
| 19 | * 04/19/99 blf link, mknod, symlink support |
| 20 | */ |
| 21 | |
| 22 | #include "udfdecl.h" |
| 23 | |
| 24 | #include "udf_i.h" |
| 25 | #include "udf_sb.h" |
| 26 | #include <linux/string.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/quotaops.h> |
| 31 | #include <linux/smp_lock.h> |
| 32 | #include <linux/buffer_head.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 33 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 35 | static inline int udf_match(int len1, const char *name1, int len2, |
| 36 | const char *name2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
| 38 | if (len1 != len2) |
| 39 | return 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | return !memcmp(name1, name2, len1); |
| 42 | } |
| 43 | |
| 44 | int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 45 | struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 46 | uint8_t *impuse, uint8_t *fileident) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag); |
| 49 | uint16_t crc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | int offset; |
| 51 | uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); |
| 52 | uint8_t lfi = cfi->lengthFileIdent; |
| 53 | int padlen = fibh->eoffset - fibh->soffset - liu - lfi - |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 54 | sizeof(struct fileIdentDesc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | int adinicb = 0; |
| 56 | |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 57 | if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | adinicb = 1; |
| 59 | |
| 60 | offset = fibh->soffset + sizeof(struct fileIdentDesc); |
| 61 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 62 | if (impuse) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 63 | if (adinicb || (offset + liu < 0)) { |
| 64 | memcpy((uint8_t *)sfi->impUse, impuse, liu); |
| 65 | } else if (offset >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | memcpy(fibh->ebh->b_data + offset, impuse, liu); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 67 | } else { |
| 68 | memcpy((uint8_t *)sfi->impUse, impuse, -offset); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 69 | memcpy(fibh->ebh->b_data, impuse - offset, |
| 70 | liu + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | offset += liu; |
| 75 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 76 | if (fileident) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 77 | if (adinicb || (offset + lfi < 0)) { |
| 78 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi); |
| 79 | } else if (offset >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | memcpy(fibh->ebh->b_data + offset, fileident, lfi); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 81 | } else { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 82 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, |
| 83 | -offset); |
| 84 | memcpy(fibh->ebh->b_data, fileident - offset, |
| 85 | lfi + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | offset += lfi; |
| 90 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 91 | if (adinicb || (offset + padlen < 0)) { |
| 92 | memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen); |
| 93 | } else if (offset >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | memset(fibh->ebh->b_data + offset, 0x00, padlen); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 95 | } else { |
| 96 | memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | memset(fibh->ebh->b_data, 0x00, padlen + offset); |
| 98 | } |
| 99 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 100 | crc = udf_crc((uint8_t *)cfi + sizeof(tag), |
| 101 | sizeof(struct fileIdentDesc) - sizeof(tag), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 103 | if (fibh->sbh == fibh->ebh) { |
| 104 | crc = udf_crc((uint8_t *)sfi->impUse, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 105 | crclen + sizeof(tag) - |
| 106 | sizeof(struct fileIdentDesc), crc); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 107 | } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 108 | crc = udf_crc(fibh->ebh->b_data + |
| 109 | sizeof(struct fileIdentDesc) + |
| 110 | fibh->soffset, |
| 111 | crclen + sizeof(tag) - |
| 112 | sizeof(struct fileIdentDesc), |
| 113 | crc); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 114 | } else { |
| 115 | crc = udf_crc((uint8_t *)sfi->impUse, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 116 | -fibh->soffset - sizeof(struct fileIdentDesc), |
| 117 | crc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); |
| 119 | } |
| 120 | |
| 121 | cfi->descTag.descCRC = cpu_to_le16(crc); |
| 122 | cfi->descTag.descCRCLength = cpu_to_le16(crclen); |
Marcin Slusarz | 3f2587b | 2008-02-08 04:20:39 -0800 | [diff] [blame] | 123 | cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 125 | if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 126 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, |
| 127 | sizeof(struct fileIdentDesc)); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 128 | } else { |
| 129 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); |
| 130 | memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 131 | sizeof(struct fileIdentDesc) + fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 134 | if (adinicb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | mark_inode_dirty(inode); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 136 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | if (fibh->sbh != fibh->ebh) |
| 138 | mark_buffer_dirty_inode(fibh->ebh, inode); |
| 139 | mark_buffer_dirty_inode(fibh->sbh, inode); |
| 140 | } |
| 141 | return 0; |
| 142 | } |
| 143 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 144 | static struct fileIdentDesc *udf_find_entry(struct inode *dir, |
| 145 | struct dentry *dentry, |
| 146 | struct udf_fileident_bh *fibh, |
| 147 | struct fileIdentDesc *cfi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 149 | struct fileIdentDesc *fi = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | loff_t f_pos; |
| 151 | int block, flen; |
| 152 | char fname[UDF_NAME_LEN]; |
| 153 | char *nameptr; |
| 154 | uint8_t lfi; |
| 155 | uint16_t liu; |
KAMBAROV, ZAUR | ec471dc | 2005-06-28 20:45:10 -0700 | [diff] [blame] | 156 | loff_t size; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 157 | kernel_lb_addr eloc; |
| 158 | uint32_t elen; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 159 | sector_t offset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 160 | struct extent_position epos = {}; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 161 | struct udf_inode_info *dinfo = UDF_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
KAMBAROV, ZAUR | ec471dc | 2005-06-28 20:45:10 -0700 | [diff] [blame] | 163 | size = (udf_ext0_offset(dir) + dir->i_size) >> 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | f_pos = (udf_ext0_offset(dir) >> 2); |
| 165 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 166 | fibh->soffset = fibh->eoffset = |
| 167 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 168 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | fibh->sbh = fibh->ebh = NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 170 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
| 171 | &epos, &eloc, &elen, &offset) == |
| 172 | (EXT_RECORDED_ALLOCATED >> 30)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 174 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 175 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 176 | epos.offset -= sizeof(short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 177 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 178 | epos.offset -= sizeof(long_ad); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 179 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | offset = 0; |
| 181 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 182 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 183 | if (!fibh->sbh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 184 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | return NULL; |
| 186 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 187 | } else { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 188 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return NULL; |
| 190 | } |
| 191 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 192 | while ((f_pos < size)) { |
| 193 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, |
| 194 | &elen, &offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 195 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 197 | brelse(fibh->ebh); |
| 198 | brelse(fibh->sbh); |
| 199 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return NULL; |
| 201 | } |
| 202 | |
| 203 | liu = le16_to_cpu(cfi->lengthOfImpUse); |
| 204 | lfi = cfi->lengthFileIdent; |
| 205 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 206 | if (fibh->sbh == fibh->ebh) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | nameptr = fi->fileIdent + liu; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 208 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | int poffset; /* Unpaded ending offset */ |
| 210 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 211 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + |
| 212 | liu + lfi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 214 | if (poffset >= lfi) |
| 215 | nameptr = (uint8_t *)(fibh->ebh->b_data + |
| 216 | poffset - lfi); |
| 217 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | nameptr = fname; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 219 | memcpy(nameptr, fi->fileIdent + liu, |
| 220 | lfi - poffset); |
| 221 | memcpy(nameptr + lfi - poffset, |
| 222 | fibh->ebh->b_data, poffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 226 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { |
| 227 | if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | continue; |
| 229 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 230 | |
| 231 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) { |
| 232 | if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | continue; |
| 234 | } |
| 235 | |
| 236 | if (!lfi) |
| 237 | continue; |
| 238 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 239 | flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); |
| 240 | if (flen && udf_match(flen, fname, dentry->d_name.len, |
| 241 | dentry->d_name.name)) { |
| 242 | brelse(epos.bh); |
| 243 | return fi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 248 | brelse(fibh->ebh); |
| 249 | brelse(fibh->sbh); |
| 250 | brelse(epos.bh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return NULL; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * udf_lookup |
| 257 | * |
| 258 | * PURPOSE |
| 259 | * Look-up the inode for a given name. |
| 260 | * |
| 261 | * DESCRIPTION |
| 262 | * Required - lookup_dentry() will return -ENOTDIR if this routine is not |
| 263 | * available for a directory. The filesystem is useless if this routine is |
| 264 | * not available for at least the filesystem's root directory. |
| 265 | * |
| 266 | * This routine is passed an incomplete dentry - it must be completed by |
| 267 | * calling d_add(dentry, inode). If the name does not exist, then the |
| 268 | * specified inode must be set to null. An error should only be returned |
| 269 | * when the lookup fails for a reason other than the name not existing. |
| 270 | * Note that the directory inode semaphore is held during the call. |
| 271 | * |
| 272 | * Refer to lookup_dentry() in fs/namei.c |
| 273 | * lookup_dentry() -> lookup() -> real_lookup() -> . |
| 274 | * |
| 275 | * PRE-CONDITIONS |
| 276 | * dir Pointer to inode of parent directory. |
| 277 | * dentry Pointer to dentry to complete. |
| 278 | * nd Pointer to lookup nameidata |
| 279 | * |
| 280 | * POST-CONDITIONS |
| 281 | * <return> Zero on success. |
| 282 | * |
| 283 | * HISTORY |
| 284 | * July 1, 1997 - Andrew E. Mileski |
| 285 | * Written, tested, and released. |
| 286 | */ |
| 287 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 288 | static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, |
| 289 | struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
| 291 | struct inode *inode = NULL; |
Jayachandran C | db9a369 | 2006-02-03 03:04:50 -0800 | [diff] [blame] | 292 | struct fileIdentDesc cfi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | struct udf_fileident_bh fibh; |
| 294 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 295 | if (dentry->d_name.len > UDF_NAME_LEN - 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | return ERR_PTR(-ENAMETOOLONG); |
| 297 | |
| 298 | lock_kernel(); |
| 299 | #ifdef UDF_RECOVERY |
| 300 | /* temporary shorthand for specifying files by inode number */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 301 | if (!strncmp(dentry->d_name.name, ".B=", 3)) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 302 | kernel_lb_addr lb = { |
| 303 | .logicalBlockNum = 0, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 304 | .partitionReferenceNum = |
| 305 | simple_strtoul(dentry->d_name.name + 3, |
| 306 | NULL, 0), |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 307 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | inode = udf_iget(dir->i_sb, lb); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 309 | if (!inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | unlock_kernel(); |
| 311 | return ERR_PTR(-EACCES); |
| 312 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 313 | } else |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 314 | #endif /* UDF_RECOVERY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 316 | if (udf_find_entry(dir, dentry, &fibh, &cfi)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 318 | brelse(fibh.ebh); |
| 319 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | inode = udf_iget(dir->i_sb, lelb_to_cpu(cfi.icb.extLocation)); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 322 | if (!inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | unlock_kernel(); |
| 324 | return ERR_PTR(-EACCES); |
| 325 | } |
| 326 | } |
| 327 | unlock_kernel(); |
| 328 | d_add(dentry, inode); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return NULL; |
| 331 | } |
| 332 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 333 | static struct fileIdentDesc *udf_add_entry(struct inode *dir, |
| 334 | struct dentry *dentry, |
| 335 | struct udf_fileident_bh *fibh, |
| 336 | struct fileIdentDesc *cfi, int *err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 338 | struct super_block *sb = dir->i_sb; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 339 | struct fileIdentDesc *fi = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | char name[UDF_NAME_LEN], fname[UDF_NAME_LEN]; |
| 341 | int namelen; |
| 342 | loff_t f_pos; |
| 343 | int flen; |
| 344 | char *nameptr; |
| 345 | loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; |
| 346 | int nfidlen; |
| 347 | uint8_t lfi; |
| 348 | uint16_t liu; |
| 349 | int block; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 350 | kernel_lb_addr eloc; |
| 351 | uint32_t elen; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 352 | sector_t offset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 353 | struct extent_position epos = {}; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 354 | struct udf_inode_info *dinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 356 | if (dentry) { |
| 357 | if (!dentry->d_name.len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | *err = -EINVAL; |
| 359 | return NULL; |
| 360 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 361 | namelen = udf_put_filename(sb, dentry->d_name.name, name, |
| 362 | dentry->d_name.len); |
| 363 | if (!namelen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | *err = -ENAMETOOLONG; |
| 365 | return NULL; |
| 366 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 367 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | namelen = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
| 371 | nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; |
| 372 | |
| 373 | f_pos = (udf_ext0_offset(dir) >> 2); |
| 374 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 375 | fibh->soffset = fibh->eoffset = |
| 376 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 377 | dinfo = UDF_I(dir); |
| 378 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | fibh->sbh = fibh->ebh = NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 380 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
| 381 | &epos, &eloc, &elen, &offset) == |
| 382 | (EXT_RECORDED_ALLOCATED >> 30)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 384 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 385 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 386 | epos.offset -= sizeof(short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 387 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 388 | epos.offset -= sizeof(long_ad); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 389 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | offset = 0; |
| 391 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 392 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 393 | if (!fibh->sbh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 394 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | *err = -EIO; |
| 396 | return NULL; |
| 397 | } |
| 398 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 399 | block = dinfo->i_location.logicalBlockNum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 401 | } else { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 402 | block = udf_get_lb_pblock(dir->i_sb, dinfo->i_location, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | fibh->sbh = fibh->ebh = NULL; |
| 404 | fibh->soffset = fibh->eoffset = sb->s_blocksize; |
| 405 | goto add; |
| 406 | } |
| 407 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 408 | while ((f_pos < size)) { |
| 409 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, |
| 410 | &elen, &offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 412 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 414 | brelse(fibh->ebh); |
| 415 | brelse(fibh->sbh); |
| 416 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | *err = -EIO; |
| 418 | return NULL; |
| 419 | } |
| 420 | |
| 421 | liu = le16_to_cpu(cfi->lengthOfImpUse); |
| 422 | lfi = cfi->lengthFileIdent; |
| 423 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 424 | if (fibh->sbh == fibh->ebh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | nameptr = fi->fileIdent + liu; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 426 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | int poffset; /* Unpaded ending offset */ |
| 428 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 429 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + |
| 430 | liu + lfi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 432 | if (poffset >= lfi) |
| 433 | nameptr = (char *)(fibh->ebh->b_data + |
| 434 | poffset - lfi); |
| 435 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | nameptr = fname; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 437 | memcpy(nameptr, fi->fileIdent + liu, |
| 438 | lfi - poffset); |
| 439 | memcpy(nameptr + lfi - poffset, |
| 440 | fibh->ebh->b_data, poffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 444 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 445 | if (((sizeof(struct fileIdentDesc) + |
| 446 | liu + lfi + 3) & ~3) == nfidlen) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 447 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | cfi->descTag.tagSerialNum = cpu_to_le16(1); |
| 449 | cfi->fileVersionNum = cpu_to_le16(1); |
| 450 | cfi->fileCharacteristics = 0; |
| 451 | cfi->lengthFileIdent = namelen; |
| 452 | cfi->lengthOfImpUse = cpu_to_le16(0); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 453 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, |
| 454 | name)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | return fi; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 456 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | *err = -EIO; |
| 458 | return NULL; |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | if (!lfi || !dentry) |
| 464 | continue; |
| 465 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 466 | flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); |
| 467 | if (flen && udf_match(flen, fname, dentry->d_name.len, |
| 468 | dentry->d_name.name)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 470 | brelse(fibh->ebh); |
| 471 | brelse(fibh->sbh); |
| 472 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | *err = -EEXIST; |
| 474 | return NULL; |
| 475 | } |
| 476 | } |
| 477 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 478 | add: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | f_pos += nfidlen; |
| 480 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 481 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 482 | sb->s_blocksize - fibh->eoffset < nfidlen) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 483 | brelse(epos.bh); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 484 | epos.bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | fibh->soffset -= udf_ext0_offset(dir); |
| 486 | fibh->eoffset -= udf_ext0_offset(dir); |
| 487 | f_pos -= (udf_ext0_offset(dir) >> 2); |
| 488 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 489 | brelse(fibh->ebh); |
| 490 | brelse(fibh->sbh); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 491 | fibh->sbh = fibh->ebh = |
| 492 | udf_expand_dir_adinicb(dir, &block, err); |
| 493 | if (!fibh->sbh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | return NULL; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 495 | epos.block = dinfo->i_location; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | eloc.logicalBlockNum = block; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 497 | eloc.partitionReferenceNum = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 498 | dinfo->i_location.partitionReferenceNum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | elen = dir->i_sb->s_blocksize; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 500 | epos.offset = udf_file_entry_alloc_offset(dir); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 501 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 502 | epos.offset += sizeof(short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 503 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 504 | epos.offset += sizeof(long_ad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 507 | if (sb->s_blocksize - fibh->eoffset >= nfidlen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | fibh->soffset = fibh->eoffset; |
| 509 | fibh->eoffset += nfidlen; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 510 | if (fibh->sbh != fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 511 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | fibh->sbh = fibh->ebh; |
| 513 | } |
| 514 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 515 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 516 | block = dinfo->i_location.logicalBlockNum; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 517 | fi = (struct fileIdentDesc *) |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 518 | (dinfo->i_ext.i_data + |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 519 | fibh->soffset - |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 520 | udf_ext0_offset(dir) + |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 521 | dinfo->i_lenEAttr); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 522 | } else { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 523 | block = eloc.logicalBlockNum + |
| 524 | ((elen - 1) >> |
| 525 | dir->i_sb->s_blocksize_bits); |
| 526 | fi = (struct fileIdentDesc *) |
| 527 | (fibh->sbh->b_data + fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 529 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | fibh->soffset = fibh->eoffset - sb->s_blocksize; |
| 531 | fibh->eoffset += nfidlen - sb->s_blocksize; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 532 | if (fibh->sbh != fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 533 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | fibh->sbh = fibh->ebh; |
| 535 | } |
| 536 | |
| 537 | block = eloc.logicalBlockNum + ((elen - 1) >> |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 538 | dir->i_sb->s_blocksize_bits); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 539 | fibh->ebh = udf_bread(dir, |
| 540 | f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
| 541 | 1, err); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 542 | if (!fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 543 | brelse(epos.bh); |
| 544 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | return NULL; |
| 546 | } |
| 547 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 548 | if (!fibh->soffset) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 549 | if (udf_next_aext(dir, &epos, &eloc, &elen, 1) == |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 550 | (EXT_RECORDED_ALLOCATED >> 30)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | block = eloc.logicalBlockNum + ((elen - 1) >> |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 552 | dir->i_sb->s_blocksize_bits); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 553 | } else |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 554 | block++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 556 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | fibh->sbh = fibh->ebh; |
| 558 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 559 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | fi = (struct fileIdentDesc *) |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 561 | (fibh->sbh->b_data + sb->s_blocksize + |
| 562 | fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
| 566 | memset(cfi, 0, sizeof(struct fileIdentDesc)); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 567 | if (UDF_SB(sb)->s_udfrev >= 0x0200) |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 568 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, |
| 569 | sizeof(tag)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | else |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 571 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, |
| 572 | sizeof(tag)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | cfi->fileVersionNum = cpu_to_le16(1); |
| 574 | cfi->lengthFileIdent = namelen; |
| 575 | cfi->lengthOfImpUse = cpu_to_le16(0); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 576 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 577 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | dir->i_size += nfidlen; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 579 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 580 | dinfo->i_lenAlloc += nfidlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | mark_inode_dirty(dir); |
| 582 | return fi; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 583 | } else { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 584 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 586 | brelse(fibh->ebh); |
| 587 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | *err = -EIO; |
| 589 | return NULL; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 594 | struct udf_fileident_bh *fibh, |
| 595 | struct fileIdentDesc *cfi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
| 597 | cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) |
| 600 | memset(&(cfi->icb), 0x00, sizeof(long_ad)); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); |
| 603 | } |
| 604 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 605 | static int udf_create(struct inode *dir, struct dentry *dentry, int mode, |
| 606 | struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { |
| 608 | struct udf_fileident_bh fibh; |
| 609 | struct inode *inode; |
| 610 | struct fileIdentDesc cfi, *fi; |
| 611 | int err; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 612 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | lock_kernel(); |
| 615 | inode = udf_new_inode(dir, mode, &err); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 616 | if (!inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | unlock_kernel(); |
| 618 | return err; |
| 619 | } |
| 620 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 621 | iinfo = UDF_I(inode); |
| 622 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | inode->i_data.a_ops = &udf_adinicb_aops; |
| 624 | else |
| 625 | inode->i_data.a_ops = &udf_aops; |
| 626 | inode->i_op = &udf_file_inode_operations; |
| 627 | inode->i_fop = &udf_file_operations; |
| 628 | inode->i_mode = mode; |
| 629 | mark_inode_dirty(inode); |
| 630 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 631 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 632 | if (!fi) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 633 | inode->i_nlink--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | mark_inode_dirty(inode); |
| 635 | iput(inode); |
| 636 | unlock_kernel(); |
| 637 | return err; |
| 638 | } |
| 639 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 640 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 641 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 642 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 644 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | mark_inode_dirty(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 647 | brelse(fibh.ebh); |
| 648 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | unlock_kernel(); |
| 650 | d_instantiate(dentry, inode); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 655 | static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, |
| 656 | dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 658 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | struct udf_fileident_bh fibh; |
| 660 | struct fileIdentDesc cfi, *fi; |
| 661 | int err; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 662 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
| 664 | if (!old_valid_dev(rdev)) |
| 665 | return -EINVAL; |
| 666 | |
| 667 | lock_kernel(); |
| 668 | err = -EIO; |
| 669 | inode = udf_new_inode(dir, mode, &err); |
| 670 | if (!inode) |
| 671 | goto out; |
| 672 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 673 | iinfo = UDF_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | inode->i_uid = current->fsuid; |
| 675 | init_special_inode(inode, mode, rdev); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 676 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 677 | if (!fi) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 678 | inode->i_nlink--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | mark_inode_dirty(inode); |
| 680 | iput(inode); |
| 681 | unlock_kernel(); |
| 682 | return err; |
| 683 | } |
| 684 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 685 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 686 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 687 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 689 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | mark_inode_dirty(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | mark_inode_dirty(inode); |
| 692 | |
| 693 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 694 | brelse(fibh.ebh); |
| 695 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | d_instantiate(dentry, inode); |
| 697 | err = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 698 | |
| 699 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | unlock_kernel(); |
| 701 | return err; |
| 702 | } |
| 703 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 704 | static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 706 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | struct udf_fileident_bh fibh; |
| 708 | struct fileIdentDesc cfi, *fi; |
| 709 | int err; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 710 | struct udf_inode_info *dinfo = UDF_I(dir); |
| 711 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
| 713 | lock_kernel(); |
| 714 | err = -EMLINK; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 715 | if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | goto out; |
| 717 | |
| 718 | err = -EIO; |
| 719 | inode = udf_new_inode(dir, S_IFDIR, &err); |
| 720 | if (!inode) |
| 721 | goto out; |
| 722 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 723 | iinfo = UDF_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | inode->i_op = &udf_dir_inode_operations; |
| 725 | inode->i_fop = &udf_dir_operations; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 726 | fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err); |
| 727 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | inode->i_nlink--; |
| 729 | mark_inode_dirty(inode); |
| 730 | iput(inode); |
| 731 | goto out; |
| 732 | } |
| 733 | inode->i_nlink = 2; |
| 734 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 735 | cfi.icb.extLocation = cpu_to_lelb(dinfo->i_location); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 736 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 737 | cpu_to_le32(dinfo->i_unique & 0x00000000FFFFFFFFUL); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 738 | cfi.fileCharacteristics = |
| 739 | FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 741 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | inode->i_mode = S_IFDIR | mode; |
| 743 | if (dir->i_mode & S_ISGID) |
| 744 | inode->i_mode |= S_ISGID; |
| 745 | mark_inode_dirty(inode); |
| 746 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 747 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 748 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | inode->i_nlink = 0; |
| 750 | mark_inode_dirty(inode); |
| 751 | iput(inode); |
| 752 | goto out; |
| 753 | } |
| 754 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 755 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 756 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 757 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; |
| 759 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 760 | inc_nlink(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | mark_inode_dirty(dir); |
| 762 | d_instantiate(dentry, inode); |
| 763 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 764 | brelse(fibh.ebh); |
| 765 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | err = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 767 | |
| 768 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | unlock_kernel(); |
| 770 | return err; |
| 771 | } |
| 772 | |
| 773 | static int empty_dir(struct inode *dir) |
| 774 | { |
| 775 | struct fileIdentDesc *fi, cfi; |
| 776 | struct udf_fileident_bh fibh; |
| 777 | loff_t f_pos; |
| 778 | loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; |
| 779 | int block; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 780 | kernel_lb_addr eloc; |
| 781 | uint32_t elen; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 782 | sector_t offset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 783 | struct extent_position epos = {}; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 784 | struct udf_inode_info *dinfo = UDF_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | f_pos = (udf_ext0_offset(dir) >> 2); |
| 787 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 788 | fibh.soffset = fibh.eoffset = |
| 789 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 791 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | fibh.sbh = fibh.ebh = NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 793 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
| 794 | &epos, &eloc, &elen, &offset) == |
| 795 | (EXT_RECORDED_ALLOCATED >> 30)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 797 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 798 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 799 | epos.offset -= sizeof(short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 800 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 801 | epos.offset -= sizeof(long_ad); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 802 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | offset = 0; |
| 804 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 805 | fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block); |
| 806 | if (!fibh.sbh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 807 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | return 0; |
| 809 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 810 | } else { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 811 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | return 0; |
| 813 | } |
| 814 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 815 | while ((f_pos < size)) { |
| 816 | fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, |
| 817 | &elen, &offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 818 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 820 | brelse(fibh.ebh); |
| 821 | brelse(fibh.sbh); |
| 822 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | return 0; |
| 824 | } |
| 825 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 826 | if (cfi.lengthFileIdent && |
| 827 | (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 829 | brelse(fibh.ebh); |
| 830 | brelse(fibh.sbh); |
| 831 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | return 0; |
| 833 | } |
| 834 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 837 | brelse(fibh.ebh); |
| 838 | brelse(fibh.sbh); |
| 839 | brelse(epos.bh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | return 1; |
| 842 | } |
| 843 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 844 | static int udf_rmdir(struct inode *dir, struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | { |
| 846 | int retval; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 847 | struct inode *inode = dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | struct udf_fileident_bh fibh; |
| 849 | struct fileIdentDesc *fi, cfi; |
| 850 | kernel_lb_addr tloc; |
| 851 | |
| 852 | retval = -ENOENT; |
| 853 | lock_kernel(); |
| 854 | fi = udf_find_entry(dir, dentry, &fibh, &cfi); |
| 855 | if (!fi) |
| 856 | goto out; |
| 857 | |
| 858 | retval = -EIO; |
| 859 | tloc = lelb_to_cpu(cfi.icb.extLocation); |
| 860 | if (udf_get_lb_pblock(dir->i_sb, tloc, 0) != inode->i_ino) |
| 861 | goto end_rmdir; |
| 862 | retval = -ENOTEMPTY; |
| 863 | if (!empty_dir(inode)) |
| 864 | goto end_rmdir; |
| 865 | retval = udf_delete_entry(dir, fi, &fibh, &cfi); |
| 866 | if (retval) |
| 867 | goto end_rmdir; |
| 868 | if (inode->i_nlink != 2) |
| 869 | udf_warning(inode->i_sb, "udf_rmdir", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 870 | "empty directory has nlink != 2 (%d)", |
| 871 | inode->i_nlink); |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 872 | clear_nlink(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | inode->i_size = 0; |
Stephen Mollett | c007c06 | 2007-05-08 00:31:31 -0700 | [diff] [blame] | 874 | inode_dec_link_count(dir); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 875 | inode->i_ctime = dir->i_ctime = dir->i_mtime = |
| 876 | current_fs_time(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | mark_inode_dirty(dir); |
| 878 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 879 | end_rmdir: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 881 | brelse(fibh.ebh); |
| 882 | brelse(fibh.sbh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 883 | |
| 884 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | unlock_kernel(); |
| 886 | return retval; |
| 887 | } |
| 888 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 889 | static int udf_unlink(struct inode *dir, struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | { |
| 891 | int retval; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 892 | struct inode *inode = dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | struct udf_fileident_bh fibh; |
| 894 | struct fileIdentDesc *fi; |
| 895 | struct fileIdentDesc cfi; |
| 896 | kernel_lb_addr tloc; |
| 897 | |
| 898 | retval = -ENOENT; |
| 899 | lock_kernel(); |
| 900 | fi = udf_find_entry(dir, dentry, &fibh, &cfi); |
| 901 | if (!fi) |
| 902 | goto out; |
| 903 | |
| 904 | retval = -EIO; |
| 905 | tloc = lelb_to_cpu(cfi.icb.extLocation); |
| 906 | if (udf_get_lb_pblock(dir->i_sb, tloc, 0) != inode->i_ino) |
| 907 | goto end_unlink; |
| 908 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 909 | if (!inode->i_nlink) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | udf_debug("Deleting nonexistent file (%lu), %d\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 911 | inode->i_ino, inode->i_nlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | inode->i_nlink = 1; |
| 913 | } |
| 914 | retval = udf_delete_entry(dir, fi, &fibh, &cfi); |
| 915 | if (retval) |
| 916 | goto end_unlink; |
| 917 | dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb); |
| 918 | mark_inode_dirty(dir); |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 919 | inode_dec_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | inode->i_ctime = dir->i_ctime; |
| 921 | retval = 0; |
| 922 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 923 | end_unlink: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 925 | brelse(fibh.ebh); |
| 926 | brelse(fibh.sbh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 927 | |
| 928 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | unlock_kernel(); |
| 930 | return retval; |
| 931 | } |
| 932 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 933 | static int udf_symlink(struct inode *dir, struct dentry *dentry, |
| 934 | const char *symname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 936 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | struct pathComponent *pc; |
| 938 | char *compstart; |
| 939 | struct udf_fileident_bh fibh; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 940 | struct extent_position epos = {}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | int eoffset, elen = 0; |
| 942 | struct fileIdentDesc *fi; |
| 943 | struct fileIdentDesc cfi; |
| 944 | char *ea; |
| 945 | int err; |
| 946 | int block; |
| 947 | char name[UDF_NAME_LEN]; |
| 948 | int namelen; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 949 | struct buffer_head *bh; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 950 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
| 952 | lock_kernel(); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 953 | inode = udf_new_inode(dir, S_IFLNK, &err); |
| 954 | if (!inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | goto out; |
| 956 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 957 | iinfo = UDF_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | inode->i_mode = S_IFLNK | S_IRWXUGO; |
| 959 | inode->i_data.a_ops = &udf_symlink_aops; |
| 960 | inode->i_op = &page_symlink_inode_operations; |
| 961 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 962 | if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 963 | kernel_lb_addr eloc; |
| 964 | uint32_t elen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
| 966 | block = udf_new_block(inode->i_sb, inode, |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 967 | iinfo->i_location.partitionReferenceNum, |
| 968 | iinfo->i_location.logicalBlockNum, &err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | if (!block) |
| 970 | goto out_no_entry; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 971 | epos.block = iinfo->i_location; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 972 | epos.offset = udf_file_entry_alloc_offset(inode); |
| 973 | epos.bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | eloc.logicalBlockNum = block; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 975 | eloc.partitionReferenceNum = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 976 | iinfo->i_location.partitionReferenceNum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | elen = inode->i_sb->s_blocksize; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 978 | iinfo->i_lenExtents = elen; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 979 | udf_add_aext(inode, &epos, eloc, elen, 0); |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 980 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
| 982 | block = udf_get_pblock(inode->i_sb, block, |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 983 | iinfo->i_location.partitionReferenceNum, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 984 | 0); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 985 | epos.bh = udf_tread(inode->i_sb, block); |
| 986 | lock_buffer(epos.bh); |
| 987 | memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); |
| 988 | set_buffer_uptodate(epos.bh); |
| 989 | unlock_buffer(epos.bh); |
| 990 | mark_buffer_dirty_inode(epos.bh, inode); |
| 991 | ea = epos.bh->b_data + udf_ext0_offset(inode); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 992 | } else |
| 993 | ea = iinfo->i_ext.i_data + iinfo->i_lenEAttr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
| 995 | eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); |
| 996 | pc = (struct pathComponent *)ea; |
| 997 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 998 | if (*symname == '/') { |
| 999 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | symname++; |
| 1001 | } while (*symname == '/'); |
| 1002 | |
| 1003 | pc->componentType = 1; |
| 1004 | pc->lengthComponentIdent = 0; |
| 1005 | pc->componentFileVersionNum = 0; |
| 1006 | pc += sizeof(struct pathComponent); |
| 1007 | elen += sizeof(struct pathComponent); |
| 1008 | } |
| 1009 | |
| 1010 | err = -ENAMETOOLONG; |
| 1011 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1012 | while (*symname) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | if (elen + sizeof(struct pathComponent) > eoffset) |
| 1014 | goto out_no_entry; |
| 1015 | |
| 1016 | pc = (struct pathComponent *)(ea + elen); |
| 1017 | |
| 1018 | compstart = (char *)symname; |
| 1019 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1020 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | symname++; |
| 1022 | } while (*symname && *symname != '/'); |
| 1023 | |
| 1024 | pc->componentType = 5; |
| 1025 | pc->lengthComponentIdent = 0; |
| 1026 | pc->componentFileVersionNum = 0; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1027 | if (compstart[0] == '.') { |
| 1028 | if ((symname - compstart) == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | pc->componentType = 4; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1030 | else if ((symname - compstart) == 2 && |
| 1031 | compstart[1] == '.') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | pc->componentType = 3; |
| 1033 | } |
| 1034 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1035 | if (pc->componentType == 5) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1036 | namelen = udf_put_filename(inode->i_sb, compstart, name, |
| 1037 | symname - compstart); |
| 1038 | if (!namelen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | goto out_no_entry; |
| 1040 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1041 | if (elen + sizeof(struct pathComponent) + namelen > |
| 1042 | eoffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | goto out_no_entry; |
| 1044 | else |
| 1045 | pc->lengthComponentIdent = namelen; |
| 1046 | |
| 1047 | memcpy(pc->componentIdent, name, namelen); |
| 1048 | } |
| 1049 | |
| 1050 | elen += sizeof(struct pathComponent) + pc->lengthComponentIdent; |
| 1051 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1052 | if (*symname) { |
| 1053 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | symname++; |
| 1055 | } while (*symname == '/'); |
| 1056 | } |
| 1057 | } |
| 1058 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1059 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | inode->i_size = elen; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1061 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 1062 | iinfo->i_lenAlloc = inode->i_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | mark_inode_dirty(inode); |
| 1064 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1065 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 1066 | if (!fi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | goto out_no_entry; |
| 1068 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1069 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1070 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; |
| 1071 | if (bh) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1072 | struct logicalVolIntegrityDesc *lvid = |
| 1073 | (struct logicalVolIntegrityDesc *)bh->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | struct logicalVolHeaderDesc *lvhd; |
| 1075 | uint64_t uniqueID; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1076 | lvhd = (struct logicalVolHeaderDesc *) |
| 1077 | lvid->logicalVolContentsUse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1079 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 1080 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
| 1082 | uniqueID += 16; |
| 1083 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1084 | mark_buffer_dirty(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | } |
| 1086 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 1087 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | mark_inode_dirty(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1090 | brelse(fibh.ebh); |
| 1091 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | d_instantiate(dentry, inode); |
| 1093 | err = 0; |
| 1094 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1095 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | unlock_kernel(); |
| 1097 | return err; |
| 1098 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1099 | out_no_entry: |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1100 | inode_dec_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | iput(inode); |
| 1102 | goto out; |
| 1103 | } |
| 1104 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1105 | static int udf_link(struct dentry *old_dentry, struct inode *dir, |
| 1106 | struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | { |
| 1108 | struct inode *inode = old_dentry->d_inode; |
| 1109 | struct udf_fileident_bh fibh; |
| 1110 | struct fileIdentDesc cfi, *fi; |
| 1111 | int err; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1112 | struct buffer_head *bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | |
| 1114 | lock_kernel(); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1115 | if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | unlock_kernel(); |
| 1117 | return -EMLINK; |
| 1118 | } |
| 1119 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1120 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 1121 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | unlock_kernel(); |
| 1123 | return err; |
| 1124 | } |
| 1125 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 1126 | cfi.icb.extLocation = cpu_to_lelb(UDF_I(inode)->i_location); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1127 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; |
| 1128 | if (bh) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1129 | struct logicalVolIntegrityDesc *lvid = |
| 1130 | (struct logicalVolIntegrityDesc *)bh->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | struct logicalVolHeaderDesc *lvhd; |
| 1132 | uint64_t uniqueID; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1133 | lvhd = (struct logicalVolHeaderDesc *) |
| 1134 | (lvid->logicalVolContentsUse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1136 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 1137 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
| 1139 | uniqueID += 16; |
| 1140 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1141 | mark_buffer_dirty(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | } |
| 1143 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 1144 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | mark_inode_dirty(dir); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1148 | brelse(fibh.ebh); |
| 1149 | brelse(fibh.sbh); |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1150 | inc_nlink(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | inode->i_ctime = current_fs_time(inode->i_sb); |
| 1152 | mark_inode_dirty(inode); |
| 1153 | atomic_inc(&inode->i_count); |
| 1154 | d_instantiate(dentry, inode); |
| 1155 | unlock_kernel(); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | return 0; |
| 1158 | } |
| 1159 | |
| 1160 | /* Anybody can rename anything with this: the permission checks are left to the |
| 1161 | * higher-level routines. |
| 1162 | */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1163 | static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 1164 | struct inode *new_dir, struct dentry *new_dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1166 | struct inode *old_inode = old_dentry->d_inode; |
| 1167 | struct inode *new_inode = new_dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | struct udf_fileident_bh ofibh, nfibh; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1169 | struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL; |
| 1170 | struct fileIdentDesc ocfi, ncfi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | struct buffer_head *dir_bh = NULL; |
| 1172 | int retval = -ENOENT; |
| 1173 | kernel_lb_addr tloc; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1174 | struct udf_inode_info *old_iinfo = UDF_I(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
| 1176 | lock_kernel(); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1177 | ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); |
| 1178 | if (ofi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | if (ofibh.sbh != ofibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1180 | brelse(ofibh.ebh); |
| 1181 | brelse(ofibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | } |
| 1183 | tloc = lelb_to_cpu(ocfi.icb.extLocation); |
| 1184 | if (!ofi || udf_get_lb_pblock(old_dir->i_sb, tloc, 0) |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1185 | != old_inode->i_ino) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | goto end_rename; |
| 1187 | |
| 1188 | nfi = udf_find_entry(new_dir, new_dentry, &nfibh, &ncfi); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1189 | if (nfi) { |
| 1190 | if (!new_inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | if (nfibh.sbh != nfibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1192 | brelse(nfibh.ebh); |
| 1193 | brelse(nfibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | nfi = NULL; |
| 1195 | } |
| 1196 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1197 | if (S_ISDIR(old_inode->i_mode)) { |
Marcin Slusarz | 7f3fbd0 | 2008-02-08 04:20:49 -0800 | [diff] [blame^] | 1198 | int offset = udf_ext0_offset(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1200 | if (new_inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | retval = -ENOTEMPTY; |
| 1202 | if (!empty_dir(new_inode)) |
| 1203 | goto end_rename; |
| 1204 | } |
| 1205 | retval = -EIO; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1206 | if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1207 | dir_fi = udf_get_fileident( |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1208 | old_iinfo->i_ext.i_data - |
| 1209 | (old_iinfo->i_efe ? |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1210 | sizeof(struct extendedFileEntry) : |
| 1211 | sizeof(struct fileEntry)), |
| 1212 | old_inode->i_sb->s_blocksize, &offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1213 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | dir_bh = udf_bread(old_inode, 0, 0, &retval); |
| 1215 | if (!dir_bh) |
| 1216 | goto end_rename; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1217 | dir_fi = udf_get_fileident(dir_bh->b_data, |
| 1218 | old_inode->i_sb->s_blocksize, &offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | } |
| 1220 | if (!dir_fi) |
| 1221 | goto end_rename; |
| 1222 | tloc = lelb_to_cpu(dir_fi->icb.extLocation); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1223 | if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != |
| 1224 | old_dir->i_ino) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | goto end_rename; |
| 1226 | |
| 1227 | retval = -EMLINK; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1228 | if (!new_inode && |
| 1229 | new_dir->i_nlink >= |
| 1230 | (256 << sizeof(new_dir->i_nlink)) - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | goto end_rename; |
| 1232 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1233 | if (!nfi) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1234 | nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, |
| 1235 | &retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | if (!nfi) |
| 1237 | goto end_rename; |
| 1238 | } |
| 1239 | |
| 1240 | /* |
| 1241 | * Like most other Unix systems, set the ctime for inodes on a |
| 1242 | * rename. |
| 1243 | */ |
| 1244 | old_inode->i_ctime = current_fs_time(old_inode->i_sb); |
| 1245 | mark_inode_dirty(old_inode); |
| 1246 | |
| 1247 | /* |
| 1248 | * ok, that's it |
| 1249 | */ |
| 1250 | ncfi.fileVersionNum = ocfi.fileVersionNum; |
| 1251 | ncfi.fileCharacteristics = ocfi.fileCharacteristics; |
| 1252 | memcpy(&(ncfi.icb), &(ocfi.icb), sizeof(long_ad)); |
| 1253 | udf_write_fi(new_dir, &ncfi, nfi, &nfibh, NULL, NULL); |
| 1254 | |
| 1255 | /* The old fid may have moved - find it again */ |
| 1256 | ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); |
| 1257 | udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); |
| 1258 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1259 | if (new_inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | new_inode->i_ctime = current_fs_time(new_inode->i_sb); |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1261 | inode_dec_link_count(new_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | old_dir->i_ctime = old_dir->i_mtime = current_fs_time(old_dir->i_sb); |
| 1264 | mark_inode_dirty(old_dir); |
| 1265 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1266 | if (dir_fi) { |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 1267 | dir_fi->icb.extLocation = cpu_to_lelb(UDF_I(new_dir)->i_location); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1268 | udf_update_tag((char *)dir_fi, |
| 1269 | (sizeof(struct fileIdentDesc) + |
| 1270 | le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1271 | if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | mark_inode_dirty(old_inode); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1273 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | mark_buffer_dirty_inode(dir_bh, old_inode); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1275 | |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1276 | inode_dec_link_count(old_dir); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1277 | if (new_inode) |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1278 | inode_dec_link_count(new_inode); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1279 | else { |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1280 | inc_nlink(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | mark_inode_dirty(new_dir); |
| 1282 | } |
| 1283 | } |
| 1284 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1285 | if (ofi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | if (ofibh.sbh != ofibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1287 | brelse(ofibh.ebh); |
| 1288 | brelse(ofibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | retval = 0; |
| 1292 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1293 | end_rename: |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1294 | brelse(dir_bh); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1295 | if (nfi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | if (nfibh.sbh != nfibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1297 | brelse(nfibh.ebh); |
| 1298 | brelse(nfibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | } |
| 1300 | unlock_kernel(); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | return retval; |
| 1303 | } |
| 1304 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 1305 | const struct inode_operations udf_dir_inode_operations = { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1306 | .lookup = udf_lookup, |
| 1307 | .create = udf_create, |
| 1308 | .link = udf_link, |
| 1309 | .unlink = udf_unlink, |
| 1310 | .symlink = udf_symlink, |
| 1311 | .mkdir = udf_mkdir, |
| 1312 | .rmdir = udf_rmdir, |
| 1313 | .mknod = udf_mknod, |
| 1314 | .rename = udf_rename, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | }; |