blob: 701fcda18415b48d983a0862b8e0c5043b4a85fc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * namei.c
3 *
4 * PURPOSE
5 * Inode name handling routines for the OSTA-UDF(tm) filesystem.
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
31#include <linux/buffer_head.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040032#include <linux/sched.h>
Bob Copelandf845fce2008-04-17 09:47:48 +020033#include <linux/crc-itu-t.h>
Rasmus Rohde221e5832008-04-30 17:22:06 +020034#include <linux/exportfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Al Viro391e8bb2010-01-31 21:28:48 -050036static inline int udf_match(int len1, const unsigned char *name1, int len2,
37 const unsigned char *name2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 if (len1 != len2)
40 return 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 return !memcmp(name1, name2, len1);
43}
44
45int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070046 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh,
Marcin Slusarz4b111112008-02-08 04:20:36 -080047 uint8_t *impuse, uint8_t *fileident)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020049 uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(struct tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 uint16_t crc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 int offset;
52 uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse);
53 uint8_t lfi = cfi->lengthFileIdent;
54 int padlen = fibh->eoffset - fibh->soffset - liu - lfi -
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070055 sizeof(struct fileIdentDesc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 int adinicb = 0;
57
Marcin Slusarzc0b34432008-02-08 04:20:42 -080058 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 adinicb = 1;
60
61 offset = fibh->soffset + sizeof(struct fileIdentDesc);
62
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070063 if (impuse) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070064 if (adinicb || (offset + liu < 0)) {
65 memcpy((uint8_t *)sfi->impUse, impuse, liu);
66 } else if (offset >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 memcpy(fibh->ebh->b_data + offset, impuse, liu);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070068 } else {
69 memcpy((uint8_t *)sfi->impUse, impuse, -offset);
Marcin Slusarz4b111112008-02-08 04:20:36 -080070 memcpy(fibh->ebh->b_data, impuse - offset,
71 liu + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 }
73 }
74
75 offset += liu;
76
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070077 if (fileident) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070078 if (adinicb || (offset + lfi < 0)) {
79 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi);
80 } else if (offset >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 memcpy(fibh->ebh->b_data + offset, fileident, lfi);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070082 } else {
Marcin Slusarz4b111112008-02-08 04:20:36 -080083 memcpy((uint8_t *)sfi->fileIdent + liu, fileident,
84 -offset);
85 memcpy(fibh->ebh->b_data, fileident - offset,
86 lfi + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88 }
89
90 offset += lfi;
91
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070092 if (adinicb || (offset + padlen < 0)) {
93 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen);
94 } else if (offset >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 memset(fibh->ebh->b_data + offset, 0x00, padlen);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070096 } else {
97 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 memset(fibh->ebh->b_data, 0x00, padlen + offset);
99 }
100
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200101 crc = crc_itu_t(0, (uint8_t *)cfi + sizeof(struct tag),
102 sizeof(struct fileIdentDesc) - sizeof(struct tag));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700104 if (fibh->sbh == fibh->ebh) {
Bob Copelandf845fce2008-04-17 09:47:48 +0200105 crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200106 crclen + sizeof(struct tag) -
Bob Copelandf845fce2008-04-17 09:47:48 +0200107 sizeof(struct fileIdentDesc));
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700108 } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
Bob Copelandf845fce2008-04-17 09:47:48 +0200109 crc = crc_itu_t(crc, fibh->ebh->b_data +
Marcin Slusarz4b111112008-02-08 04:20:36 -0800110 sizeof(struct fileIdentDesc) +
111 fibh->soffset,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200112 crclen + sizeof(struct tag) -
Bob Copelandf845fce2008-04-17 09:47:48 +0200113 sizeof(struct fileIdentDesc));
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700114 } else {
Bob Copelandf845fce2008-04-17 09:47:48 +0200115 crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
116 -fibh->soffset - sizeof(struct fileIdentDesc));
117 crc = crc_itu_t(crc, fibh->ebh->b_data, fibh->eoffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119
120 cfi->descTag.descCRC = cpu_to_le16(crc);
121 cfi->descTag.descCRCLength = cpu_to_le16(crclen);
Marcin Slusarz3f2587b2008-02-08 04:20:39 -0800122 cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700124 if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) {
Marcin Slusarz4b111112008-02-08 04:20:36 -0800125 memcpy((uint8_t *)sfi, (uint8_t *)cfi,
126 sizeof(struct fileIdentDesc));
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700127 } else {
128 memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset);
129 memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset,
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700130 sizeof(struct fileIdentDesc) + fibh->soffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700133 if (adinicb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 mark_inode_dirty(inode);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700135 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 if (fibh->sbh != fibh->ebh)
137 mark_buffer_dirty_inode(fibh->ebh, inode);
138 mark_buffer_dirty_inode(fibh->sbh, inode);
139 }
140 return 0;
141}
142
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700143static struct fileIdentDesc *udf_find_entry(struct inode *dir,
Al Viro391e8bb2010-01-31 21:28:48 -0500144 const struct qstr *child,
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700145 struct udf_fileident_bh *fibh,
146 struct fileIdentDesc *cfi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700148 struct fileIdentDesc *fi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 loff_t f_pos;
150 int block, flen;
Al Viro391e8bb2010-01-31 21:28:48 -0500151 unsigned char *fname = NULL;
152 unsigned char *nameptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 uint8_t lfi;
154 uint16_t liu;
KAMBAROV, ZAURec471dc2005-06-28 20:45:10 -0700155 loff_t size;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200156 struct kernel_lb_addr eloc;
Jan Karaff116fc2007-05-08 00:35:14 -0700157 uint32_t elen;
Jan Kara60448b12007-05-08 00:35:13 -0700158 sector_t offset;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700159 struct extent_position epos = {};
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800160 struct udf_inode_info *dinfo = UDF_I(dir);
Al Viro9fbb76c2008-10-12 00:15:17 -0400161 int isdotdot = child->len == 2 &&
162 child->name[0] == '.' && child->name[1] == '.';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Jan Karaaf793292008-02-08 04:20:50 -0800164 size = udf_ext0_offset(dir) + dir->i_size;
165 f_pos = udf_ext0_offset(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Jan Karab80697c2008-03-04 14:14:05 +0100167 fibh->sbh = fibh->ebh = NULL;
Jan Karaaf793292008-02-08 04:20:50 -0800168 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
Jan Karab80697c2008-03-04 14:14:05 +0100169 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
170 if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, &epos,
171 &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30))
172 goto out_err;
Pekka Enberg97e961f2008-10-15 12:29:03 +0200173 block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700174 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800175 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200176 epos.offset -= sizeof(struct short_ad);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800177 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200178 epos.offset -= sizeof(struct long_ad);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800179 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 offset = 0;
181
Marcin Slusarz4b111112008-02-08 04:20:36 -0800182 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
Jan Karab80697c2008-03-04 14:14:05 +0100183 if (!fibh->sbh)
184 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
Jan Karab80697c2008-03-04 14:14:05 +0100187 fname = kmalloc(UDF_NAME_LEN, GFP_NOFS);
188 if (!fname)
189 goto out_err;
190
Jan Karaaf793292008-02-08 04:20:50 -0800191 while (f_pos < size) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700192 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
193 &elen, &offset);
Jan Karab80697c2008-03-04 14:14:05 +0100194 if (!fi)
195 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 liu = le16_to_cpu(cfi->lengthOfImpUse);
198 lfi = cfi->lengthFileIdent;
199
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700200 if (fibh->sbh == fibh->ebh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 nameptr = fi->fileIdent + liu;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700202 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 int poffset; /* Unpaded ending offset */
204
Marcin Slusarz4b111112008-02-08 04:20:36 -0800205 poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
206 liu + lfi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Marcin Slusarz4b111112008-02-08 04:20:36 -0800208 if (poffset >= lfi)
209 nameptr = (uint8_t *)(fibh->ebh->b_data +
210 poffset - lfi);
211 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 nameptr = fname;
Marcin Slusarz4b111112008-02-08 04:20:36 -0800213 memcpy(nameptr, fi->fileIdent + liu,
214 lfi - poffset);
215 memcpy(nameptr + lfi - poffset,
216 fibh->ebh->b_data, poffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 }
218 }
219
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700220 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
221 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 continue;
223 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700224
225 if ((cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
226 if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 continue;
228 }
229
Rasmus Rohde221e5832008-04-30 17:22:06 +0200230 if ((cfi->fileCharacteristics & FID_FILE_CHAR_PARENT) &&
231 isdotdot) {
232 brelse(epos.bh);
233 return fi;
234 }
235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 if (!lfi)
237 continue;
238
Marcin Slusarz4b111112008-02-08 04:20:36 -0800239 flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
Al Viro9fbb76c2008-10-12 00:15:17 -0400240 if (flen && udf_match(flen, fname, child->len, child->name))
Jan Karab80697c2008-03-04 14:14:05 +0100241 goto out_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700243
Jan Karab80697c2008-03-04 14:14:05 +0100244out_err:
245 fi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (fibh->sbh != fibh->ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700247 brelse(fibh->ebh);
248 brelse(fibh->sbh);
Jan Karab80697c2008-03-04 14:14:05 +0100249out_ok:
Jan Kara3bf25cb2007-05-08 00:35:16 -0700250 brelse(epos.bh);
Jan Karab80697c2008-03-04 14:14:05 +0100251 kfree(fname);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700252
Jan Karab80697c2008-03-04 14:14:05 +0100253 return fi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700256static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
257 struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 struct inode *inode = NULL;
Jayachandran Cdb9a3692006-02-03 03:04:50 -0800260 struct fileIdentDesc cfi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 struct udf_fileident_bh fibh;
262
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700263 if (dentry->d_name.len > UDF_NAME_LEN - 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return ERR_PTR(-ENAMETOOLONG);
265
266 lock_kernel();
267#ifdef UDF_RECOVERY
268 /* temporary shorthand for specifying files by inode number */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700269 if (!strncmp(dentry->d_name.name, ".B=", 3)) {
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200270 struct kernel_lb_addr lb = {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700271 .logicalBlockNum = 0,
Marcin Slusarz4b111112008-02-08 04:20:36 -0800272 .partitionReferenceNum =
273 simple_strtoul(dentry->d_name.name + 3,
274 NULL, 0),
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700275 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 inode = udf_iget(dir->i_sb, lb);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700277 if (!inode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 unlock_kernel();
279 return ERR_PTR(-EACCES);
280 }
Marcin Slusarz4b111112008-02-08 04:20:36 -0800281 } else
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700282#endif /* UDF_RECOVERY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Al Viro9fbb76c2008-10-12 00:15:17 -0400284 if (udf_find_entry(dir, &dentry->d_name, &fibh, &cfi)) {
Pekka Enberg97e961f2008-10-15 12:29:03 +0200285 struct kernel_lb_addr loc;
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700288 brelse(fibh.ebh);
289 brelse(fibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Pekka Enberg97e961f2008-10-15 12:29:03 +0200291 loc = lelb_to_cpu(cfi.icb.extLocation);
292 inode = udf_iget(dir->i_sb, &loc);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700293 if (!inode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 unlock_kernel();
295 return ERR_PTR(-EACCES);
296 }
297 }
298 unlock_kernel();
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700299
Rasmus Rohde221e5832008-04-30 17:22:06 +0200300 return d_splice_alias(inode, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700303static struct fileIdentDesc *udf_add_entry(struct inode *dir,
304 struct dentry *dentry,
305 struct udf_fileident_bh *fibh,
306 struct fileIdentDesc *cfi, int *err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800308 struct super_block *sb = dir->i_sb;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700309 struct fileIdentDesc *fi = NULL;
Al Viro391e8bb2010-01-31 21:28:48 -0500310 unsigned char *name = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 int namelen;
312 loff_t f_pos;
Jan Karaaf793292008-02-08 04:20:50 -0800313 loff_t size = udf_ext0_offset(dir) + dir->i_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 int nfidlen;
315 uint8_t lfi;
316 uint16_t liu;
317 int block;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200318 struct kernel_lb_addr eloc;
Jan Kara9afadc42008-05-06 18:26:17 +0200319 uint32_t elen = 0;
Jan Kara60448b12007-05-08 00:35:13 -0700320 sector_t offset;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700321 struct extent_position epos = {};
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800322 struct udf_inode_info *dinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Jan Karab80697c2008-03-04 14:14:05 +0100324 fibh->sbh = fibh->ebh = NULL;
325 name = kmalloc(UDF_NAME_LEN, GFP_NOFS);
326 if (!name) {
327 *err = -ENOMEM;
328 goto out_err;
329 }
330
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700331 if (dentry) {
332 if (!dentry->d_name.len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 *err = -EINVAL;
Jan Karab80697c2008-03-04 14:14:05 +0100334 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
Marcin Slusarz4b111112008-02-08 04:20:36 -0800336 namelen = udf_put_filename(sb, dentry->d_name.name, name,
337 dentry->d_name.len);
338 if (!namelen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 *err = -ENAMETOOLONG;
Jan Karab80697c2008-03-04 14:14:05 +0100340 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700342 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 namelen = 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3;
347
Jan Karaaf793292008-02-08 04:20:50 -0800348 f_pos = udf_ext0_offset(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Jan Karaaf793292008-02-08 04:20:50 -0800350 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800351 dinfo = UDF_I(dir);
Jan Karab80697c2008-03-04 14:14:05 +0100352 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
353 if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, &epos,
354 &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) {
355 block = udf_get_lb_pblock(dir->i_sb,
Pekka Enberg97e961f2008-10-15 12:29:03 +0200356 &dinfo->i_location, 0);
Jan Karab80697c2008-03-04 14:14:05 +0100357 fibh->soffset = fibh->eoffset = sb->s_blocksize;
358 goto add;
359 }
Pekka Enberg97e961f2008-10-15 12:29:03 +0200360 block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700361 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800362 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200363 epos.offset -= sizeof(struct short_ad);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800364 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200365 epos.offset -= sizeof(struct long_ad);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800366 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 offset = 0;
368
Marcin Slusarz4b111112008-02-08 04:20:36 -0800369 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
370 if (!fibh->sbh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 *err = -EIO;
Jan Karab80697c2008-03-04 14:14:05 +0100372 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800375 block = dinfo->i_location.logicalBlockNum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377
Jan Karaaf793292008-02-08 04:20:50 -0800378 while (f_pos < size) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700379 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
380 &elen, &offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700382 if (!fi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 *err = -EIO;
Jan Karab80697c2008-03-04 14:14:05 +0100384 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 }
386
387 liu = le16_to_cpu(cfi->lengthOfImpUse);
388 lfi = cfi->lengthFileIdent;
389
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700390 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
Marcin Slusarz4b111112008-02-08 04:20:36 -0800391 if (((sizeof(struct fileIdentDesc) +
392 liu + lfi + 3) & ~3) == nfidlen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 cfi->descTag.tagSerialNum = cpu_to_le16(1);
394 cfi->fileVersionNum = cpu_to_le16(1);
395 cfi->fileCharacteristics = 0;
396 cfi->lengthFileIdent = namelen;
397 cfi->lengthOfImpUse = cpu_to_le16(0);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800398 if (!udf_write_fi(dir, cfi, fi, fibh, NULL,
399 name))
Jan Karab80697c2008-03-04 14:14:05 +0100400 goto out_ok;
Marcin Slusarz4b111112008-02-08 04:20:36 -0800401 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 *err = -EIO;
Jan Karab80697c2008-03-04 14:14:05 +0100403 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405 }
406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
408
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700409add:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 f_pos += nfidlen;
411
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800412 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB &&
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700413 sb->s_blocksize - fibh->eoffset < nfidlen) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700414 brelse(epos.bh);
Jan Karaff116fc2007-05-08 00:35:14 -0700415 epos.bh = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 fibh->soffset -= udf_ext0_offset(dir);
417 fibh->eoffset -= udf_ext0_offset(dir);
Jan Karaaf793292008-02-08 04:20:50 -0800418 f_pos -= udf_ext0_offset(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 if (fibh->sbh != fibh->ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700420 brelse(fibh->ebh);
421 brelse(fibh->sbh);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800422 fibh->sbh = fibh->ebh =
423 udf_expand_dir_adinicb(dir, &block, err);
424 if (!fibh->sbh)
Jan Karab80697c2008-03-04 14:14:05 +0100425 goto out_err;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800426 epos.block = dinfo->i_location;
Jan Karaff116fc2007-05-08 00:35:14 -0700427 epos.offset = udf_file_entry_alloc_offset(dir);
Jan Kara05343c42008-02-08 04:20:51 -0800428 /* Load extent udf_expand_dir_adinicb() has created */
429 udf_current_aext(dir, &epos, &eloc, &elen, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
431
Jan Kara2c948b32009-12-03 13:39:28 +0100432 /* Entry fits into current block? */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700433 if (sb->s_blocksize - fibh->eoffset >= nfidlen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 fibh->soffset = fibh->eoffset;
435 fibh->eoffset += nfidlen;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700436 if (fibh->sbh != fibh->ebh) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700437 brelse(fibh->sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 fibh->sbh = fibh->ebh;
439 }
440
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800441 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
442 block = dinfo->i_location.logicalBlockNum;
Marcin Slusarz4b111112008-02-08 04:20:36 -0800443 fi = (struct fileIdentDesc *)
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800444 (dinfo->i_ext.i_data +
Marcin Slusarzc0b34432008-02-08 04:20:42 -0800445 fibh->soffset -
Marcin Slusarz4b111112008-02-08 04:20:36 -0800446 udf_ext0_offset(dir) +
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800447 dinfo->i_lenEAttr);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700448 } else {
Marcin Slusarz4b111112008-02-08 04:20:36 -0800449 block = eloc.logicalBlockNum +
450 ((elen - 1) >>
451 dir->i_sb->s_blocksize_bits);
452 fi = (struct fileIdentDesc *)
453 (fibh->sbh->b_data + fibh->soffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700455 } else {
Jan Kara2c948b32009-12-03 13:39:28 +0100456 /* Round up last extent in the file */
457 elen = (elen + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1);
458 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
459 epos.offset -= sizeof(struct short_ad);
460 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
461 epos.offset -= sizeof(struct long_ad);
462 udf_write_aext(dir, &epos, &eloc, elen, 1);
463 dinfo->i_lenExtents = (dinfo->i_lenExtents + sb->s_blocksize
464 - 1) & ~(sb->s_blocksize - 1);
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 fibh->soffset = fibh->eoffset - sb->s_blocksize;
467 fibh->eoffset += nfidlen - sb->s_blocksize;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700468 if (fibh->sbh != fibh->ebh) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700469 brelse(fibh->sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 fibh->sbh = fibh->ebh;
471 }
472
473 block = eloc.logicalBlockNum + ((elen - 1) >>
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700474 dir->i_sb->s_blocksize_bits);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800475 fibh->ebh = udf_bread(dir,
Jan Karaaf793292008-02-08 04:20:50 -0800476 f_pos >> dir->i_sb->s_blocksize_bits, 1, err);
Jan Karab80697c2008-03-04 14:14:05 +0100477 if (!fibh->ebh)
478 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700480 if (!fibh->soffset) {
Jan Karaff116fc2007-05-08 00:35:14 -0700481 if (udf_next_aext(dir, &epos, &eloc, &elen, 1) ==
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700482 (EXT_RECORDED_ALLOCATED >> 30)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 block = eloc.logicalBlockNum + ((elen - 1) >>
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700484 dir->i_sb->s_blocksize_bits);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800485 } else
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700486 block++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Jan Kara3bf25cb2007-05-08 00:35:16 -0700488 brelse(fibh->sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 fibh->sbh = fibh->ebh;
490 fi = (struct fileIdentDesc *)(fibh->sbh->b_data);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700491 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 fi = (struct fileIdentDesc *)
Marcin Slusarz4b111112008-02-08 04:20:36 -0800493 (fibh->sbh->b_data + sb->s_blocksize +
494 fibh->soffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496 }
497
498 memset(cfi, 0, sizeof(struct fileIdentDesc));
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800499 if (UDF_SB(sb)->s_udfrev >= 0x0200)
Marcin Slusarz4b111112008-02-08 04:20:36 -0800500 udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200501 sizeof(struct tag));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 else
Marcin Slusarz4b111112008-02-08 04:20:36 -0800503 udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200504 sizeof(struct tag));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 cfi->fileVersionNum = cpu_to_le16(1);
506 cfi->lengthFileIdent = namelen;
507 cfi->lengthOfImpUse = cpu_to_le16(0);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700508 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 dir->i_size += nfidlen;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800510 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
511 dinfo->i_lenAlloc += nfidlen;
Jan Kara2c948b32009-12-03 13:39:28 +0100512 else {
513 /* Find the last extent and truncate it to proper size */
514 while (udf_next_aext(dir, &epos, &eloc, &elen, 1) ==
515 (EXT_RECORDED_ALLOCATED >> 30))
516 ;
517 elen -= dinfo->i_lenExtents - dir->i_size;
518 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
519 epos.offset -= sizeof(struct short_ad);
520 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
521 epos.offset -= sizeof(struct long_ad);
522 udf_write_aext(dir, &epos, &eloc, elen, 1);
523 dinfo->i_lenExtents = dir->i_size;
524 }
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 mark_inode_dirty(dir);
Jan Karab80697c2008-03-04 14:14:05 +0100527 goto out_ok;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700528 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 *err = -EIO;
Jan Karab80697c2008-03-04 14:14:05 +0100530 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 }
Jan Karab80697c2008-03-04 14:14:05 +0100532
533out_err:
534 fi = NULL;
535 if (fibh->sbh != fibh->ebh)
536 brelse(fibh->ebh);
537 brelse(fibh->sbh);
538out_ok:
539 brelse(epos.bh);
540 kfree(name);
541 return fi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542}
543
544static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi,
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700545 struct udf_fileident_bh *fibh,
546 struct fileIdentDesc *cfi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
548 cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200551 memset(&(cfi->icb), 0x00, sizeof(struct long_ad));
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL);
554}
555
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700556static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
557 struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558{
559 struct udf_fileident_bh fibh;
560 struct inode *inode;
561 struct fileIdentDesc cfi, *fi;
562 int err;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800563 struct udf_inode_info *iinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 lock_kernel();
566 inode = udf_new_inode(dir, mode, &err);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700567 if (!inode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 unlock_kernel();
569 return err;
570 }
571
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800572 iinfo = UDF_I(inode);
573 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 inode->i_data.a_ops = &udf_adinicb_aops;
575 else
576 inode->i_data.a_ops = &udf_aops;
577 inode->i_op = &udf_file_inode_operations;
578 inode->i_fop = &udf_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 mark_inode_dirty(inode);
580
Marcin Slusarz4b111112008-02-08 04:20:36 -0800581 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
582 if (!fi) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700583 inode->i_nlink--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 mark_inode_dirty(inode);
585 iput(inode);
586 unlock_kernel();
587 return err;
588 }
589 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800590 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700591 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800592 cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
Marcin Slusarzc0b34432008-02-08 04:20:42 -0800594 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 mark_inode_dirty(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700597 brelse(fibh.ebh);
598 brelse(fibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 unlock_kernel();
600 d_instantiate(dentry, inode);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 return 0;
603}
604
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700605static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
606 dev_t rdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700608 struct inode *inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 struct udf_fileident_bh fibh;
610 struct fileIdentDesc cfi, *fi;
611 int err;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800612 struct udf_inode_info *iinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 if (!old_valid_dev(rdev))
615 return -EINVAL;
616
617 lock_kernel();
618 err = -EIO;
619 inode = udf_new_inode(dir, mode, &err);
620 if (!inode)
621 goto out;
622
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800623 iinfo = UDF_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 init_special_inode(inode, mode, rdev);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800625 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
626 if (!fi) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700627 inode->i_nlink--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 mark_inode_dirty(inode);
629 iput(inode);
630 unlock_kernel();
631 return err;
632 }
633 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800634 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700635 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800636 cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
Marcin Slusarzc0b34432008-02-08 04:20:42 -0800638 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 mark_inode_dirty(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 mark_inode_dirty(inode);
641
642 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700643 brelse(fibh.ebh);
644 brelse(fibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 d_instantiate(dentry, inode);
646 err = 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700647
648out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 unlock_kernel();
650 return err;
651}
652
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700653static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700655 struct inode *inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 struct udf_fileident_bh fibh;
657 struct fileIdentDesc cfi, *fi;
658 int err;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800659 struct udf_inode_info *dinfo = UDF_I(dir);
660 struct udf_inode_info *iinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 lock_kernel();
663 err = -EMLINK;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700664 if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 goto out;
666
667 err = -EIO;
Dmitry Monakhova6c5a032010-03-04 17:32:22 +0300668 inode = udf_new_inode(dir, S_IFDIR | mode, &err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (!inode)
670 goto out;
671
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800672 iinfo = UDF_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 inode->i_op = &udf_dir_inode_operations;
674 inode->i_fop = &udf_dir_operations;
Marcin Slusarz4b111112008-02-08 04:20:36 -0800675 fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err);
676 if (!fi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 inode->i_nlink--;
678 mark_inode_dirty(inode);
679 iput(inode);
680 goto out;
681 }
682 inode->i_nlink = 2;
683 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800684 cfi.icb.extLocation = cpu_to_lelb(dinfo->i_location);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700685 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800686 cpu_to_le32(dinfo->i_unique & 0x00000000FFFFFFFFUL);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800687 cfi.fileCharacteristics =
688 FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL);
Jan Kara3bf25cb2007-05-08 00:35:16 -0700690 brelse(fibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 mark_inode_dirty(inode);
692
Marcin Slusarz4b111112008-02-08 04:20:36 -0800693 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
694 if (!fi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 inode->i_nlink = 0;
696 mark_inode_dirty(inode);
697 iput(inode);
698 goto out;
699 }
700 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800701 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700702 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800703 cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY;
705 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
Dave Hansend8c76e62006-09-30 23:29:04 -0700706 inc_nlink(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 mark_inode_dirty(dir);
708 d_instantiate(dentry, inode);
709 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700710 brelse(fibh.ebh);
711 brelse(fibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 err = 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700713
714out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 unlock_kernel();
716 return err;
717}
718
719static int empty_dir(struct inode *dir)
720{
721 struct fileIdentDesc *fi, cfi;
722 struct udf_fileident_bh fibh;
723 loff_t f_pos;
Jan Karaaf793292008-02-08 04:20:50 -0800724 loff_t size = udf_ext0_offset(dir) + dir->i_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 int block;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200726 struct kernel_lb_addr eloc;
Jan Karaff116fc2007-05-08 00:35:14 -0700727 uint32_t elen;
Jan Kara60448b12007-05-08 00:35:13 -0700728 sector_t offset;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700729 struct extent_position epos = {};
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800730 struct udf_inode_info *dinfo = UDF_I(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Jan Karaaf793292008-02-08 04:20:50 -0800732 f_pos = udf_ext0_offset(dir);
733 fibh.soffset = fibh.eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800735 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 fibh.sbh = fibh.ebh = NULL;
Jan Karaaf793292008-02-08 04:20:50 -0800737 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
Marcin Slusarz4b111112008-02-08 04:20:36 -0800738 &epos, &eloc, &elen, &offset) ==
739 (EXT_RECORDED_ALLOCATED >> 30)) {
Pekka Enberg97e961f2008-10-15 12:29:03 +0200740 block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700741 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800742 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200743 epos.offset -= sizeof(struct short_ad);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800744 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200745 epos.offset -= sizeof(struct long_ad);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800746 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 offset = 0;
748
Marcin Slusarz4b111112008-02-08 04:20:36 -0800749 fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block);
750 if (!fibh.sbh) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700751 brelse(epos.bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 return 0;
753 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700754 } else {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700755 brelse(epos.bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 return 0;
757 }
758
Jan Karaaf793292008-02-08 04:20:50 -0800759 while (f_pos < size) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700760 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc,
761 &elen, &offset);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700762 if (!fi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700764 brelse(fibh.ebh);
765 brelse(fibh.sbh);
766 brelse(epos.bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 return 0;
768 }
769
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700770 if (cfi.lengthFileIdent &&
771 (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700773 brelse(fibh.ebh);
774 brelse(fibh.sbh);
775 brelse(epos.bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 return 0;
777 }
778 }
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700781 brelse(fibh.ebh);
782 brelse(fibh.sbh);
783 brelse(epos.bh);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 return 1;
786}
787
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700788static int udf_rmdir(struct inode *dir, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
790 int retval;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700791 struct inode *inode = dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 struct udf_fileident_bh fibh;
793 struct fileIdentDesc *fi, cfi;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200794 struct kernel_lb_addr tloc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 retval = -ENOENT;
797 lock_kernel();
Al Viro9fbb76c2008-10-12 00:15:17 -0400798 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (!fi)
800 goto out;
801
802 retval = -EIO;
803 tloc = lelb_to_cpu(cfi.icb.extLocation);
Pekka Enberg97e961f2008-10-15 12:29:03 +0200804 if (udf_get_lb_pblock(dir->i_sb, &tloc, 0) != inode->i_ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 goto end_rmdir;
806 retval = -ENOTEMPTY;
807 if (!empty_dir(inode))
808 goto end_rmdir;
809 retval = udf_delete_entry(dir, fi, &fibh, &cfi);
810 if (retval)
811 goto end_rmdir;
812 if (inode->i_nlink != 2)
813 udf_warning(inode->i_sb, "udf_rmdir",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700814 "empty directory has nlink != 2 (%d)",
815 inode->i_nlink);
Dave Hansence71ec32006-09-30 23:29:06 -0700816 clear_nlink(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 inode->i_size = 0;
Stephen Mollettc007c062007-05-08 00:31:31 -0700818 inode_dec_link_count(dir);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800819 inode->i_ctime = dir->i_ctime = dir->i_mtime =
820 current_fs_time(dir->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 mark_inode_dirty(dir);
822
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700823end_rmdir:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700825 brelse(fibh.ebh);
826 brelse(fibh.sbh);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700827
828out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 unlock_kernel();
830 return retval;
831}
832
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700833static int udf_unlink(struct inode *dir, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
835 int retval;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700836 struct inode *inode = dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 struct udf_fileident_bh fibh;
838 struct fileIdentDesc *fi;
839 struct fileIdentDesc cfi;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200840 struct kernel_lb_addr tloc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842 retval = -ENOENT;
843 lock_kernel();
Al Viro9fbb76c2008-10-12 00:15:17 -0400844 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 if (!fi)
846 goto out;
847
848 retval = -EIO;
849 tloc = lelb_to_cpu(cfi.icb.extLocation);
Pekka Enberg97e961f2008-10-15 12:29:03 +0200850 if (udf_get_lb_pblock(dir->i_sb, &tloc, 0) != inode->i_ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 goto end_unlink;
852
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700853 if (!inode->i_nlink) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 udf_debug("Deleting nonexistent file (%lu), %d\n",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700855 inode->i_ino, inode->i_nlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 inode->i_nlink = 1;
857 }
858 retval = udf_delete_entry(dir, fi, &fibh, &cfi);
859 if (retval)
860 goto end_unlink;
861 dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb);
862 mark_inode_dirty(dir);
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700863 inode_dec_link_count(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 inode->i_ctime = dir->i_ctime;
865 retval = 0;
866
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700867end_unlink:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -0700869 brelse(fibh.ebh);
870 brelse(fibh.sbh);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700871
872out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 unlock_kernel();
874 return retval;
875}
876
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700877static int udf_symlink(struct inode *dir, struct dentry *dentry,
878 const char *symname)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700880 struct inode *inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 struct pathComponent *pc;
Al Viro391e8bb2010-01-31 21:28:48 -0500882 const char *compstart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 struct udf_fileident_bh fibh;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700884 struct extent_position epos = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 int eoffset, elen = 0;
886 struct fileIdentDesc *fi;
887 struct fileIdentDesc cfi;
Al Viro391e8bb2010-01-31 21:28:48 -0500888 uint8_t *ea;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 int err;
890 int block;
Al Viro391e8bb2010-01-31 21:28:48 -0500891 unsigned char *name = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 int namelen;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800893 struct udf_inode_info *iinfo;
Jan Karad664b6a2010-10-20 18:28:46 +0200894 struct super_block *sb = dir->i_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 lock_kernel();
Dmitry Monakhova6c5a032010-03-04 17:32:22 +0300897 inode = udf_new_inode(dir, S_IFLNK | S_IRWXUGO, &err);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800898 if (!inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 goto out;
900
Jan Karab80697c2008-03-04 14:14:05 +0100901 name = kmalloc(UDF_NAME_LEN, GFP_NOFS);
902 if (!name) {
903 err = -ENOMEM;
904 goto out_no_entry;
905 }
906
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800907 iinfo = UDF_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 inode->i_data.a_ops = &udf_symlink_aops;
Dmitry Monakhovc15d0fc2010-03-29 11:05:21 +0400909 inode->i_op = &udf_symlink_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800911 if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200912 struct kernel_lb_addr eloc;
Harvey Harrison78e917d2008-04-28 02:16:19 -0700913 uint32_t bsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Jan Karad664b6a2010-10-20 18:28:46 +0200915 block = udf_new_block(sb, inode,
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800916 iinfo->i_location.partitionReferenceNum,
917 iinfo->i_location.logicalBlockNum, &err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if (!block)
919 goto out_no_entry;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800920 epos.block = iinfo->i_location;
Jan Karaff116fc2007-05-08 00:35:14 -0700921 epos.offset = udf_file_entry_alloc_offset(inode);
922 epos.bh = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 eloc.logicalBlockNum = block;
Marcin Slusarz4b111112008-02-08 04:20:36 -0800924 eloc.partitionReferenceNum =
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800925 iinfo->i_location.partitionReferenceNum;
Jan Karad664b6a2010-10-20 18:28:46 +0200926 bsize = sb->s_blocksize;
Harvey Harrison78e917d2008-04-28 02:16:19 -0700927 iinfo->i_lenExtents = bsize;
Pekka Enberg97e961f2008-10-15 12:29:03 +0200928 udf_add_aext(inode, &epos, &eloc, bsize, 0);
Jan Kara3bf25cb2007-05-08 00:35:16 -0700929 brelse(epos.bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Jan Karad664b6a2010-10-20 18:28:46 +0200931 block = udf_get_pblock(sb, block,
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800932 iinfo->i_location.partitionReferenceNum,
Marcin Slusarz4b111112008-02-08 04:20:36 -0800933 0);
Jan Karad664b6a2010-10-20 18:28:46 +0200934 epos.bh = udf_tgetblk(sb, block);
Jan Karaff116fc2007-05-08 00:35:14 -0700935 lock_buffer(epos.bh);
Jan Karad664b6a2010-10-20 18:28:46 +0200936 memset(epos.bh->b_data, 0x00, bsize);
Jan Karaff116fc2007-05-08 00:35:14 -0700937 set_buffer_uptodate(epos.bh);
938 unlock_buffer(epos.bh);
939 mark_buffer_dirty_inode(epos.bh, inode);
940 ea = epos.bh->b_data + udf_ext0_offset(inode);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -0800941 } else
942 ea = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Jan Karad664b6a2010-10-20 18:28:46 +0200944 eoffset = sb->s_blocksize - udf_ext0_offset(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 pc = (struct pathComponent *)ea;
946
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700947 if (*symname == '/') {
948 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 symname++;
950 } while (*symname == '/');
951
952 pc->componentType = 1;
953 pc->lengthComponentIdent = 0;
954 pc->componentFileVersionNum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 elen += sizeof(struct pathComponent);
956 }
957
958 err = -ENAMETOOLONG;
959
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700960 while (*symname) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (elen + sizeof(struct pathComponent) > eoffset)
962 goto out_no_entry;
963
964 pc = (struct pathComponent *)(ea + elen);
965
Al Viro391e8bb2010-01-31 21:28:48 -0500966 compstart = symname;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700968 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 symname++;
970 } while (*symname && *symname != '/');
971
972 pc->componentType = 5;
973 pc->lengthComponentIdent = 0;
974 pc->componentFileVersionNum = 0;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700975 if (compstart[0] == '.') {
976 if ((symname - compstart) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 pc->componentType = 4;
Marcin Slusarz4b111112008-02-08 04:20:36 -0800978 else if ((symname - compstart) == 2 &&
979 compstart[1] == '.')
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 pc->componentType = 3;
981 }
982
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700983 if (pc->componentType == 5) {
Jan Karad664b6a2010-10-20 18:28:46 +0200984 namelen = udf_put_filename(sb, compstart, name,
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700985 symname - compstart);
986 if (!namelen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 goto out_no_entry;
988
Marcin Slusarz4b111112008-02-08 04:20:36 -0800989 if (elen + sizeof(struct pathComponent) + namelen >
990 eoffset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 goto out_no_entry;
992 else
993 pc->lengthComponentIdent = namelen;
994
995 memcpy(pc->componentIdent, name, namelen);
996 }
997
998 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
999
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001000 if (*symname) {
1001 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 symname++;
1003 } while (*symname == '/');
1004 }
1005 }
1006
Jan Kara3bf25cb2007-05-08 00:35:16 -07001007 brelse(epos.bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 inode->i_size = elen;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -08001009 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1010 iinfo->i_lenAlloc = inode->i_size;
Jan Kara2c948b32009-12-03 13:39:28 +01001011 else
1012 udf_truncate_tail_extent(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 mark_inode_dirty(inode);
1014
Marcin Slusarz4b111112008-02-08 04:20:36 -08001015 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
1016 if (!fi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 goto out_no_entry;
Jan Karad664b6a2010-10-20 18:28:46 +02001018 cfi.icb.extLength = cpu_to_le32(sb->s_blocksize);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -08001019 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
Jan Karad664b6a2010-10-20 18:28:46 +02001020 if (UDF_SB(inode->i_sb)->s_lvid_bh) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001021 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
Jan Karad664b6a2010-10-20 18:28:46 +02001022 cpu_to_le32(lvid_get_unique_id(sb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
Marcin Slusarzc0b34432008-02-08 04:20:42 -08001025 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 mark_inode_dirty(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001028 brelse(fibh.ebh);
1029 brelse(fibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 d_instantiate(dentry, inode);
1031 err = 0;
1032
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001033out:
Jan Karab80697c2008-03-04 14:14:05 +01001034 kfree(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 unlock_kernel();
1036 return err;
1037
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001038out_no_entry:
Dave Hansen9a53c3a2006-09-30 23:29:03 -07001039 inode_dec_link_count(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 iput(inode);
1041 goto out;
1042}
1043
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001044static int udf_link(struct dentry *old_dentry, struct inode *dir,
1045 struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
1047 struct inode *inode = old_dentry->d_inode;
1048 struct udf_fileident_bh fibh;
1049 struct fileIdentDesc cfi, *fi;
1050 int err;
1051
1052 lock_kernel();
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001053 if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 unlock_kernel();
1055 return -EMLINK;
1056 }
1057
Marcin Slusarz4b111112008-02-08 04:20:36 -08001058 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
1059 if (!fi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 unlock_kernel();
1061 return err;
1062 }
1063 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
Marcin Slusarzc0b34432008-02-08 04:20:42 -08001064 cfi.icb.extLocation = cpu_to_lelb(UDF_I(inode)->i_location);
Jan Karad664b6a2010-10-20 18:28:46 +02001065 if (UDF_SB(inode->i_sb)->s_lvid_bh) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001066 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
Jan Karad664b6a2010-10-20 18:28:46 +02001067 cpu_to_le32(lvid_get_unique_id(inode->i_sb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
Marcin Slusarzc0b34432008-02-08 04:20:42 -08001070 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 mark_inode_dirty(dir);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 if (fibh.sbh != fibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001074 brelse(fibh.ebh);
1075 brelse(fibh.sbh);
Dave Hansend8c76e62006-09-30 23:29:04 -07001076 inc_nlink(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 inode->i_ctime = current_fs_time(inode->i_sb);
1078 mark_inode_dirty(inode);
Al Viro7de9c6ee2010-10-23 11:11:40 -04001079 ihold(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 d_instantiate(dentry, inode);
1081 unlock_kernel();
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 return 0;
1084}
1085
1086/* Anybody can rename anything with this: the permission checks are left to the
1087 * higher-level routines.
1088 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001089static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1090 struct inode *new_dir, struct dentry *new_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001092 struct inode *old_inode = old_dentry->d_inode;
1093 struct inode *new_inode = new_dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 struct udf_fileident_bh ofibh, nfibh;
Marcin Slusarz4b111112008-02-08 04:20:36 -08001095 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL;
1096 struct fileIdentDesc ocfi, ncfi;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 struct buffer_head *dir_bh = NULL;
1098 int retval = -ENOENT;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001099 struct kernel_lb_addr tloc;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -08001100 struct udf_inode_info *old_iinfo = UDF_I(old_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 lock_kernel();
Al Viro9fbb76c2008-10-12 00:15:17 -04001103 ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
Marcin Slusarz4b111112008-02-08 04:20:36 -08001104 if (ofi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 if (ofibh.sbh != ofibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001106 brelse(ofibh.ebh);
1107 brelse(ofibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
1109 tloc = lelb_to_cpu(ocfi.icb.extLocation);
Pekka Enberg97e961f2008-10-15 12:29:03 +02001110 if (!ofi || udf_get_lb_pblock(old_dir->i_sb, &tloc, 0)
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001111 != old_inode->i_ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 goto end_rename;
1113
Al Viro9fbb76c2008-10-12 00:15:17 -04001114 nfi = udf_find_entry(new_dir, &new_dentry->d_name, &nfibh, &ncfi);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001115 if (nfi) {
1116 if (!new_inode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 if (nfibh.sbh != nfibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001118 brelse(nfibh.ebh);
1119 brelse(nfibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 nfi = NULL;
1121 }
1122 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001123 if (S_ISDIR(old_inode->i_mode)) {
Marcin Slusarz7f3fbd02008-02-08 04:20:49 -08001124 int offset = udf_ext0_offset(old_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001126 if (new_inode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 retval = -ENOTEMPTY;
1128 if (!empty_dir(new_inode))
1129 goto end_rename;
1130 }
1131 retval = -EIO;
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -08001132 if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
Marcin Slusarz4b111112008-02-08 04:20:36 -08001133 dir_fi = udf_get_fileident(
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -08001134 old_iinfo->i_ext.i_data -
1135 (old_iinfo->i_efe ?
Marcin Slusarz4b111112008-02-08 04:20:36 -08001136 sizeof(struct extendedFileEntry) :
1137 sizeof(struct fileEntry)),
1138 old_inode->i_sb->s_blocksize, &offset);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001139 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 dir_bh = udf_bread(old_inode, 0, 0, &retval);
1141 if (!dir_bh)
1142 goto end_rename;
Marcin Slusarz4b111112008-02-08 04:20:36 -08001143 dir_fi = udf_get_fileident(dir_bh->b_data,
1144 old_inode->i_sb->s_blocksize, &offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
1146 if (!dir_fi)
1147 goto end_rename;
1148 tloc = lelb_to_cpu(dir_fi->icb.extLocation);
Pekka Enberg97e961f2008-10-15 12:29:03 +02001149 if (udf_get_lb_pblock(old_inode->i_sb, &tloc, 0) !=
Marcin Slusarz4b111112008-02-08 04:20:36 -08001150 old_dir->i_ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 goto end_rename;
1152
1153 retval = -EMLINK;
Marcin Slusarz4b111112008-02-08 04:20:36 -08001154 if (!new_inode &&
1155 new_dir->i_nlink >=
1156 (256 << sizeof(new_dir->i_nlink)) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 goto end_rename;
1158 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001159 if (!nfi) {
Marcin Slusarz4b111112008-02-08 04:20:36 -08001160 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi,
1161 &retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 if (!nfi)
1163 goto end_rename;
1164 }
1165
1166 /*
1167 * Like most other Unix systems, set the ctime for inodes on a
1168 * rename.
1169 */
1170 old_inode->i_ctime = current_fs_time(old_inode->i_sb);
1171 mark_inode_dirty(old_inode);
1172
1173 /*
1174 * ok, that's it
1175 */
1176 ncfi.fileVersionNum = ocfi.fileVersionNum;
1177 ncfi.fileCharacteristics = ocfi.fileCharacteristics;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001178 memcpy(&(ncfi.icb), &(ocfi.icb), sizeof(struct long_ad));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 udf_write_fi(new_dir, &ncfi, nfi, &nfibh, NULL, NULL);
1180
1181 /* The old fid may have moved - find it again */
Al Viro9fbb76c2008-10-12 00:15:17 -04001182 ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 udf_delete_entry(old_dir, ofi, &ofibh, &ocfi);
1184
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001185 if (new_inode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 new_inode->i_ctime = current_fs_time(new_inode->i_sb);
Dave Hansen9a53c3a2006-09-30 23:29:03 -07001187 inode_dec_link_count(new_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 }
1189 old_dir->i_ctime = old_dir->i_mtime = current_fs_time(old_dir->i_sb);
1190 mark_inode_dirty(old_dir);
1191
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001192 if (dir_fi) {
Marcin Slusarzc0b34432008-02-08 04:20:42 -08001193 dir_fi->icb.extLocation = cpu_to_lelb(UDF_I(new_dir)->i_location);
Marcin Slusarz4b111112008-02-08 04:20:36 -08001194 udf_update_tag((char *)dir_fi,
1195 (sizeof(struct fileIdentDesc) +
1196 le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3);
Marcin Slusarz48d6d8ff2008-02-08 04:20:44 -08001197 if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 mark_inode_dirty(old_inode);
Marcin Slusarz4b111112008-02-08 04:20:36 -08001199 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 mark_buffer_dirty_inode(dir_bh, old_inode);
Marcin Slusarz4b111112008-02-08 04:20:36 -08001201
Dave Hansen9a53c3a2006-09-30 23:29:03 -07001202 inode_dec_link_count(old_dir);
Marcin Slusarz4b111112008-02-08 04:20:36 -08001203 if (new_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -07001204 inode_dec_link_count(new_inode);
Marcin Slusarz4b111112008-02-08 04:20:36 -08001205 else {
Dave Hansend8c76e62006-09-30 23:29:04 -07001206 inc_nlink(new_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 mark_inode_dirty(new_dir);
1208 }
1209 }
1210
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001211 if (ofi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 if (ofibh.sbh != ofibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001213 brelse(ofibh.ebh);
1214 brelse(ofibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 }
1216
1217 retval = 0;
1218
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001219end_rename:
Jan Kara3bf25cb2007-05-08 00:35:16 -07001220 brelse(dir_bh);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001221 if (nfi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 if (nfibh.sbh != nfibh.ebh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001223 brelse(nfibh.ebh);
1224 brelse(nfibh.sbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 }
1226 unlock_kernel();
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 return retval;
1229}
1230
Rasmus Rohde221e5832008-04-30 17:22:06 +02001231static struct dentry *udf_get_parent(struct dentry *child)
1232{
Pekka Enberg97e961f2008-10-15 12:29:03 +02001233 struct kernel_lb_addr tloc;
Rasmus Rohde221e5832008-04-30 17:22:06 +02001234 struct inode *inode = NULL;
Al Viro9fbb76c2008-10-12 00:15:17 -04001235 struct qstr dotdot = {.name = "..", .len = 2};
Rasmus Rohde221e5832008-04-30 17:22:06 +02001236 struct fileIdentDesc cfi;
1237 struct udf_fileident_bh fibh;
1238
Rasmus Rohde221e5832008-04-30 17:22:06 +02001239 lock_kernel();
1240 if (!udf_find_entry(child->d_inode, &dotdot, &fibh, &cfi))
1241 goto out_unlock;
1242
1243 if (fibh.sbh != fibh.ebh)
1244 brelse(fibh.ebh);
1245 brelse(fibh.sbh);
1246
Pekka Enberg97e961f2008-10-15 12:29:03 +02001247 tloc = lelb_to_cpu(cfi.icb.extLocation);
1248 inode = udf_iget(child->d_inode->i_sb, &tloc);
Rasmus Rohde221e5832008-04-30 17:22:06 +02001249 if (!inode)
1250 goto out_unlock;
1251 unlock_kernel();
1252
Christoph Hellwig44003722008-08-11 15:49:04 +02001253 return d_obtain_alias(inode);
Rasmus Rohde221e5832008-04-30 17:22:06 +02001254out_unlock:
1255 unlock_kernel();
1256 return ERR_PTR(-EACCES);
1257}
1258
1259
1260static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block,
1261 u16 partref, __u32 generation)
1262{
1263 struct inode *inode;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001264 struct kernel_lb_addr loc;
Rasmus Rohde221e5832008-04-30 17:22:06 +02001265
1266 if (block == 0)
1267 return ERR_PTR(-ESTALE);
1268
1269 loc.logicalBlockNum = block;
1270 loc.partitionReferenceNum = partref;
Pekka Enberg97e961f2008-10-15 12:29:03 +02001271 inode = udf_iget(sb, &loc);
Rasmus Rohde221e5832008-04-30 17:22:06 +02001272
1273 if (inode == NULL)
1274 return ERR_PTR(-ENOMEM);
1275
1276 if (generation && inode->i_generation != generation) {
1277 iput(inode);
1278 return ERR_PTR(-ESTALE);
1279 }
Christoph Hellwig44003722008-08-11 15:49:04 +02001280 return d_obtain_alias(inode);
Rasmus Rohde221e5832008-04-30 17:22:06 +02001281}
1282
1283static struct dentry *udf_fh_to_dentry(struct super_block *sb,
1284 struct fid *fid, int fh_len, int fh_type)
1285{
1286 if ((fh_len != 3 && fh_len != 5) ||
1287 (fh_type != FILEID_UDF_WITH_PARENT &&
1288 fh_type != FILEID_UDF_WITHOUT_PARENT))
1289 return NULL;
1290
1291 return udf_nfs_get_inode(sb, fid->udf.block, fid->udf.partref,
1292 fid->udf.generation);
1293}
1294
1295static struct dentry *udf_fh_to_parent(struct super_block *sb,
1296 struct fid *fid, int fh_len, int fh_type)
1297{
1298 if (fh_len != 5 || fh_type != FILEID_UDF_WITH_PARENT)
1299 return NULL;
1300
1301 return udf_nfs_get_inode(sb, fid->udf.parent_block,
1302 fid->udf.parent_partref,
1303 fid->udf.parent_generation);
1304}
1305static int udf_encode_fh(struct dentry *de, __u32 *fh, int *lenp,
1306 int connectable)
1307{
1308 int len = *lenp;
1309 struct inode *inode = de->d_inode;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001310 struct kernel_lb_addr location = UDF_I(inode)->i_location;
Rasmus Rohde221e5832008-04-30 17:22:06 +02001311 struct fid *fid = (struct fid *)fh;
1312 int type = FILEID_UDF_WITHOUT_PARENT;
1313
1314 if (len < 3 || (connectable && len < 5))
1315 return 255;
1316
1317 *lenp = 3;
1318 fid->udf.block = location.logicalBlockNum;
1319 fid->udf.partref = location.partitionReferenceNum;
1320 fid->udf.generation = inode->i_generation;
1321
1322 if (connectable && !S_ISDIR(inode->i_mode)) {
1323 spin_lock(&de->d_lock);
1324 inode = de->d_parent->d_inode;
1325 location = UDF_I(inode)->i_location;
1326 fid->udf.parent_block = location.logicalBlockNum;
1327 fid->udf.parent_partref = location.partitionReferenceNum;
1328 fid->udf.parent_generation = inode->i_generation;
1329 spin_unlock(&de->d_lock);
1330 *lenp = 5;
1331 type = FILEID_UDF_WITH_PARENT;
1332 }
1333
1334 return type;
1335}
1336
1337const struct export_operations udf_export_ops = {
1338 .encode_fh = udf_encode_fh,
1339 .fh_to_dentry = udf_fh_to_dentry,
1340 .fh_to_parent = udf_fh_to_parent,
1341 .get_parent = udf_get_parent,
1342};
1343
Arjan van de Venc5ef1c42007-02-12 00:55:40 -08001344const struct inode_operations udf_dir_inode_operations = {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001345 .lookup = udf_lookup,
1346 .create = udf_create,
1347 .link = udf_link,
1348 .unlink = udf_unlink,
1349 .symlink = udf_symlink,
1350 .mkdir = udf_mkdir,
1351 .rmdir = udf_rmdir,
1352 .mknod = udf_mknod,
1353 .rename = udf_rename,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354};
Dmitry Monakhovc15d0fc2010-03-29 11:05:21 +04001355const struct inode_operations udf_symlink_inode_operations = {
1356 .readlink = generic_readlink,
1357 .follow_link = page_follow_link_light,
1358 .put_link = page_put_link,
Dmitry Monakhovc15d0fc2010-03-29 11:05:21 +04001359};