inode.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. /**
  2. * eCryptfs: Linux filesystem encryption layer
  3. *
  4. * Copyright (C) 1997-2004 Erez Zadok
  5. * Copyright (C) 2001-2004 Stony Brook University
  6. * Copyright (C) 2004-2007 International Business Machines Corp.
  7. * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  8. * Michael C. Thompsion <mcthomps@us.ibm.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. * 02111-1307, USA.
  24. */
  25. #include <linux/file.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/dcache.h>
  29. #include <linux/namei.h>
  30. #include <linux/mount.h>
  31. #include <linux/crypto.h>
  32. #include <linux/fs_stack.h>
  33. #include <linux/slab.h>
  34. #include <linux/xattr.h>
  35. #include <asm/unaligned.h>
  36. #include "ecryptfs_kernel.h"
  37. static struct dentry *lock_parent(struct dentry *dentry)
  38. {
  39. struct dentry *dir;
  40. dir = dget_parent(dentry);
  41. mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT);
  42. return dir;
  43. }
  44. static void unlock_dir(struct dentry *dir)
  45. {
  46. mutex_unlock(&dir->d_inode->i_mutex);
  47. dput(dir);
  48. }
  49. static int ecryptfs_inode_test(struct inode *inode, void *lower_inode)
  50. {
  51. if (ecryptfs_inode_to_lower(inode) == (struct inode *)lower_inode)
  52. return 1;
  53. return 0;
  54. }
  55. static int ecryptfs_inode_set(struct inode *inode, void *opaque)
  56. {
  57. struct inode *lower_inode = opaque;
  58. ecryptfs_set_inode_lower(inode, lower_inode);
  59. fsstack_copy_attr_all(inode, lower_inode);
  60. /* i_size will be overwritten for encrypted regular files */
  61. fsstack_copy_inode_size(inode, lower_inode);
  62. inode->i_ino = lower_inode->i_ino;
  63. inode->i_version++;
  64. inode->i_mapping->a_ops = &ecryptfs_aops;
  65. inode->i_mapping->backing_dev_info = inode->i_sb->s_bdi;
  66. if (S_ISLNK(inode->i_mode))
  67. inode->i_op = &ecryptfs_symlink_iops;
  68. else if (S_ISDIR(inode->i_mode))
  69. inode->i_op = &ecryptfs_dir_iops;
  70. else
  71. inode->i_op = &ecryptfs_main_iops;
  72. if (S_ISDIR(inode->i_mode))
  73. inode->i_fop = &ecryptfs_dir_fops;
  74. else if (special_file(inode->i_mode))
  75. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  76. else
  77. inode->i_fop = &ecryptfs_main_fops;
  78. return 0;
  79. }
  80. static struct inode *__ecryptfs_get_inode(struct inode *lower_inode,
  81. struct super_block *sb)
  82. {
  83. struct inode *inode;
  84. if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb))
  85. return ERR_PTR(-EXDEV);
  86. if (!igrab(lower_inode))
  87. return ERR_PTR(-ESTALE);
  88. inode = iget5_locked(sb, (unsigned long)lower_inode,
  89. ecryptfs_inode_test, ecryptfs_inode_set,
  90. lower_inode);
  91. if (!inode) {
  92. iput(lower_inode);
  93. return ERR_PTR(-EACCES);
  94. }
  95. if (!(inode->i_state & I_NEW))
  96. iput(lower_inode);
  97. return inode;
  98. }
  99. struct inode *ecryptfs_get_inode(struct inode *lower_inode,
  100. struct super_block *sb)
  101. {
  102. struct inode *inode = __ecryptfs_get_inode(lower_inode, sb);
  103. if (!IS_ERR(inode) && (inode->i_state & I_NEW))
  104. unlock_new_inode(inode);
  105. return inode;
  106. }
  107. /**
  108. * ecryptfs_interpose
  109. * @lower_dentry: Existing dentry in the lower filesystem
  110. * @dentry: ecryptfs' dentry
  111. * @sb: ecryptfs's super_block
  112. *
  113. * Interposes upper and lower dentries.
  114. *
  115. * Returns zero on success; non-zero otherwise
  116. */
  117. static int ecryptfs_interpose(struct dentry *lower_dentry,
  118. struct dentry *dentry, struct super_block *sb)
  119. {
  120. struct inode *inode = ecryptfs_get_inode(lower_dentry->d_inode, sb);
  121. if (IS_ERR(inode))
  122. return PTR_ERR(inode);
  123. d_instantiate(dentry, inode);
  124. return 0;
  125. }
  126. /**
  127. * ecryptfs_do_create
  128. * @directory_inode: inode of the new file's dentry's parent in ecryptfs
  129. * @ecryptfs_dentry: New file's dentry in ecryptfs
  130. * @mode: The mode of the new file
  131. * @nd: nameidata of ecryptfs' parent's dentry & vfsmount
  132. *
  133. * Creates the underlying file and the eCryptfs inode which will link to
  134. * it. It will also update the eCryptfs directory inode to mimic the
  135. * stat of the lower directory inode.
  136. *
  137. * Returns the new eCryptfs inode on success; an ERR_PTR on error condition
  138. */
  139. static struct inode *
  140. ecryptfs_do_create(struct inode *directory_inode,
  141. struct dentry *ecryptfs_dentry, umode_t mode)
  142. {
  143. int rc;
  144. struct dentry *lower_dentry;
  145. struct dentry *lower_dir_dentry;
  146. struct inode *inode;
  147. lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
  148. lower_dir_dentry = lock_parent(lower_dentry);
  149. if (IS_ERR(lower_dir_dentry)) {
  150. ecryptfs_printk(KERN_ERR, "Error locking directory of "
  151. "dentry\n");
  152. inode = ERR_CAST(lower_dir_dentry);
  153. goto out;
  154. }
  155. rc = vfs_create(lower_dir_dentry->d_inode, lower_dentry, mode, true);
  156. if (rc) {
  157. printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
  158. "rc = [%d]\n", __func__, rc);
  159. inode = ERR_PTR(rc);
  160. goto out_lock;
  161. }
  162. inode = __ecryptfs_get_inode(lower_dentry->d_inode,
  163. directory_inode->i_sb);
  164. if (IS_ERR(inode))
  165. goto out_lock;
  166. fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode);
  167. fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode);
  168. out_lock:
  169. unlock_dir(lower_dir_dentry);
  170. out:
  171. return inode;
  172. }
  173. /**
  174. * ecryptfs_initialize_file
  175. *
  176. * Cause the file to be changed from a basic empty file to an ecryptfs
  177. * file with a header and first data page.
  178. *
  179. * Returns zero on success
  180. */
  181. static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
  182. struct inode *ecryptfs_inode)
  183. {
  184. struct ecryptfs_crypt_stat *crypt_stat =
  185. &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
  186. int rc = 0;
  187. if (S_ISDIR(ecryptfs_inode->i_mode)) {
  188. ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
  189. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  190. goto out;
  191. }
  192. ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
  193. rc = ecryptfs_new_file_context(ecryptfs_inode);
  194. if (rc) {
  195. ecryptfs_printk(KERN_ERR, "Error creating new file "
  196. "context; rc = [%d]\n", rc);
  197. goto out;
  198. }
  199. rc = ecryptfs_get_lower_file(ecryptfs_dentry, ecryptfs_inode);
  200. if (rc) {
  201. printk(KERN_ERR "%s: Error attempting to initialize "
  202. "the lower file for the dentry with name "
  203. "[%s]; rc = [%d]\n", __func__,
  204. ecryptfs_dentry->d_name.name, rc);
  205. goto out;
  206. }
  207. rc = ecryptfs_write_metadata(ecryptfs_dentry, ecryptfs_inode);
  208. if (rc)
  209. printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc);
  210. ecryptfs_put_lower_file(ecryptfs_inode);
  211. out:
  212. return rc;
  213. }
  214. /**
  215. * ecryptfs_create
  216. * @dir: The inode of the directory in which to create the file.
  217. * @dentry: The eCryptfs dentry
  218. * @mode: The mode of the new file.
  219. *
  220. * Creates a new file.
  221. *
  222. * Returns zero on success; non-zero on error condition
  223. */
  224. static int
  225. ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
  226. umode_t mode, bool excl)
  227. {
  228. struct inode *ecryptfs_inode;
  229. int rc;
  230. ecryptfs_inode = ecryptfs_do_create(directory_inode, ecryptfs_dentry,
  231. mode);
  232. if (unlikely(IS_ERR(ecryptfs_inode))) {
  233. ecryptfs_printk(KERN_WARNING, "Failed to create file in"
  234. "lower filesystem\n");
  235. rc = PTR_ERR(ecryptfs_inode);
  236. goto out;
  237. }
  238. /* At this point, a file exists on "disk"; we need to make sure
  239. * that this on disk file is prepared to be an ecryptfs file */
  240. rc = ecryptfs_initialize_file(ecryptfs_dentry, ecryptfs_inode);
  241. if (rc) {
  242. drop_nlink(ecryptfs_inode);
  243. unlock_new_inode(ecryptfs_inode);
  244. iput(ecryptfs_inode);
  245. goto out;
  246. }
  247. unlock_new_inode(ecryptfs_inode);
  248. d_instantiate(ecryptfs_dentry, ecryptfs_inode);
  249. out:
  250. return rc;
  251. }
  252. static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
  253. {
  254. struct ecryptfs_crypt_stat *crypt_stat;
  255. int rc;
  256. rc = ecryptfs_get_lower_file(dentry, inode);
  257. if (rc) {
  258. printk(KERN_ERR "%s: Error attempting to initialize "
  259. "the lower file for the dentry with name "
  260. "[%s]; rc = [%d]\n", __func__,
  261. dentry->d_name.name, rc);
  262. return rc;
  263. }
  264. crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
  265. /* TODO: lock for crypt_stat comparison */
  266. if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
  267. ecryptfs_set_default_sizes(crypt_stat);
  268. rc = ecryptfs_read_and_validate_header_region(inode);
  269. ecryptfs_put_lower_file(inode);
  270. if (rc) {
  271. rc = ecryptfs_read_and_validate_xattr_region(dentry, inode);
  272. if (!rc)
  273. crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
  274. }
  275. /* Must return 0 to allow non-eCryptfs files to be looked up, too */
  276. return 0;
  277. }
  278. /**
  279. * ecryptfs_lookup_interpose - Dentry interposition for a lookup
  280. */
  281. static int ecryptfs_lookup_interpose(struct dentry *dentry,
  282. struct dentry *lower_dentry,
  283. struct inode *dir_inode)
  284. {
  285. struct inode *inode, *lower_inode = lower_dentry->d_inode;
  286. struct ecryptfs_dentry_info *dentry_info;
  287. struct vfsmount *lower_mnt;
  288. int rc = 0;
  289. lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
  290. fsstack_copy_attr_atime(dir_inode, lower_dentry->d_parent->d_inode);
  291. BUG_ON(!lower_dentry->d_count);
  292. dentry_info = kmem_cache_alloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
  293. ecryptfs_set_dentry_private(dentry, dentry_info);
  294. if (!dentry_info) {
  295. printk(KERN_ERR "%s: Out of memory whilst attempting "
  296. "to allocate ecryptfs_dentry_info struct\n",
  297. __func__);
  298. dput(lower_dentry);
  299. mntput(lower_mnt);
  300. d_drop(dentry);
  301. return -ENOMEM;
  302. }
  303. ecryptfs_set_dentry_lower(dentry, lower_dentry);
  304. ecryptfs_set_dentry_lower_mnt(dentry, lower_mnt);
  305. if (!lower_dentry->d_inode) {
  306. /* We want to add because we couldn't find in lower */
  307. d_add(dentry, NULL);
  308. return 0;
  309. }
  310. inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb);
  311. if (IS_ERR(inode)) {
  312. printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n",
  313. __func__, PTR_ERR(inode));
  314. return PTR_ERR(inode);
  315. }
  316. if (S_ISREG(inode->i_mode)) {
  317. rc = ecryptfs_i_size_read(dentry, inode);
  318. if (rc) {
  319. make_bad_inode(inode);
  320. return rc;
  321. }
  322. }
  323. if (inode->i_state & I_NEW)
  324. unlock_new_inode(inode);
  325. d_add(dentry, inode);
  326. return rc;
  327. }
  328. /**
  329. * ecryptfs_lookup
  330. * @ecryptfs_dir_inode: The eCryptfs directory inode
  331. * @ecryptfs_dentry: The eCryptfs dentry that we are looking up
  332. * @ecryptfs_nd: nameidata; may be NULL
  333. *
  334. * Find a file on disk. If the file does not exist, then we'll add it to the
  335. * dentry cache and continue on to read it from the disk.
  336. */
  337. static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
  338. struct dentry *ecryptfs_dentry,
  339. unsigned int flags)
  340. {
  341. char *encrypted_and_encoded_name = NULL;
  342. size_t encrypted_and_encoded_name_size;
  343. struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
  344. struct dentry *lower_dir_dentry, *lower_dentry;
  345. int rc = 0;
  346. if ((ecryptfs_dentry->d_name.len == 1
  347. && !strcmp(ecryptfs_dentry->d_name.name, "."))
  348. || (ecryptfs_dentry->d_name.len == 2
  349. && !strcmp(ecryptfs_dentry->d_name.name, ".."))) {
  350. goto out_d_drop;
  351. }
  352. lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
  353. mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
  354. lower_dentry = lookup_one_len(ecryptfs_dentry->d_name.name,
  355. lower_dir_dentry,
  356. ecryptfs_dentry->d_name.len);
  357. mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
  358. if (IS_ERR(lower_dentry)) {
  359. rc = PTR_ERR(lower_dentry);
  360. ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
  361. "[%d] on lower_dentry = [%s]\n", __func__, rc,
  362. encrypted_and_encoded_name);
  363. goto out_d_drop;
  364. }
  365. if (lower_dentry->d_inode)
  366. goto interpose;
  367. mount_crypt_stat = &ecryptfs_superblock_to_private(
  368. ecryptfs_dentry->d_sb)->mount_crypt_stat;
  369. if (!(mount_crypt_stat
  370. && (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)))
  371. goto interpose;
  372. dput(lower_dentry);
  373. rc = ecryptfs_encrypt_and_encode_filename(
  374. &encrypted_and_encoded_name, &encrypted_and_encoded_name_size,
  375. NULL, mount_crypt_stat, ecryptfs_dentry->d_name.name,
  376. ecryptfs_dentry->d_name.len);
  377. if (rc) {
  378. printk(KERN_ERR "%s: Error attempting to encrypt and encode "
  379. "filename; rc = [%d]\n", __func__, rc);
  380. goto out_d_drop;
  381. }
  382. mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
  383. lower_dentry = lookup_one_len(encrypted_and_encoded_name,
  384. lower_dir_dentry,
  385. encrypted_and_encoded_name_size);
  386. mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
  387. if (IS_ERR(lower_dentry)) {
  388. rc = PTR_ERR(lower_dentry);
  389. ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
  390. "[%d] on lower_dentry = [%s]\n", __func__, rc,
  391. encrypted_and_encoded_name);
  392. goto out_d_drop;
  393. }
  394. interpose:
  395. rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry,
  396. ecryptfs_dir_inode);
  397. goto out;
  398. out_d_drop:
  399. d_drop(ecryptfs_dentry);
  400. out:
  401. kfree(encrypted_and_encoded_name);
  402. return ERR_PTR(rc);
  403. }
  404. static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
  405. struct dentry *new_dentry)
  406. {
  407. struct dentry *lower_old_dentry;
  408. struct dentry *lower_new_dentry;
  409. struct dentry *lower_dir_dentry;
  410. u64 file_size_save;
  411. int rc;
  412. file_size_save = i_size_read(old_dentry->d_inode);
  413. lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
  414. lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
  415. dget(lower_old_dentry);
  416. dget(lower_new_dentry);
  417. lower_dir_dentry = lock_parent(lower_new_dentry);
  418. rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
  419. lower_new_dentry);
  420. if (rc || !lower_new_dentry->d_inode)
  421. goto out_lock;
  422. rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb);
  423. if (rc)
  424. goto out_lock;
  425. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  426. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  427. set_nlink(old_dentry->d_inode,
  428. ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink);
  429. i_size_write(new_dentry->d_inode, file_size_save);
  430. out_lock:
  431. unlock_dir(lower_dir_dentry);
  432. dput(lower_new_dentry);
  433. dput(lower_old_dentry);
  434. return rc;
  435. }
  436. static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
  437. {
  438. int rc = 0;
  439. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  440. struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
  441. struct dentry *lower_dir_dentry;
  442. dget(lower_dentry);
  443. lower_dir_dentry = lock_parent(lower_dentry);
  444. rc = vfs_unlink(lower_dir_inode, lower_dentry);
  445. if (rc) {
  446. printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
  447. goto out_unlock;
  448. }
  449. fsstack_copy_attr_times(dir, lower_dir_inode);
  450. set_nlink(dentry->d_inode,
  451. ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink);
  452. dentry->d_inode->i_ctime = dir->i_ctime;
  453. d_drop(dentry);
  454. out_unlock:
  455. unlock_dir(lower_dir_dentry);
  456. dput(lower_dentry);
  457. return rc;
  458. }
  459. static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
  460. const char *symname)
  461. {
  462. int rc;
  463. struct dentry *lower_dentry;
  464. struct dentry *lower_dir_dentry;
  465. char *encoded_symname;
  466. size_t encoded_symlen;
  467. struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
  468. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  469. dget(lower_dentry);
  470. lower_dir_dentry = lock_parent(lower_dentry);
  471. mount_crypt_stat = &ecryptfs_superblock_to_private(
  472. dir->i_sb)->mount_crypt_stat;
  473. rc = ecryptfs_encrypt_and_encode_filename(&encoded_symname,
  474. &encoded_symlen,
  475. NULL,
  476. mount_crypt_stat, symname,
  477. strlen(symname));
  478. if (rc)
  479. goto out_lock;
  480. rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
  481. encoded_symname);
  482. kfree(encoded_symname);
  483. if (rc || !lower_dentry->d_inode)
  484. goto out_lock;
  485. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  486. if (rc)
  487. goto out_lock;
  488. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  489. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  490. out_lock:
  491. unlock_dir(lower_dir_dentry);
  492. dput(lower_dentry);
  493. if (!dentry->d_inode)
  494. d_drop(dentry);
  495. return rc;
  496. }
  497. static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  498. {
  499. int rc;
  500. struct dentry *lower_dentry;
  501. struct dentry *lower_dir_dentry;
  502. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  503. lower_dir_dentry = lock_parent(lower_dentry);
  504. rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
  505. if (rc || !lower_dentry->d_inode)
  506. goto out;
  507. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  508. if (rc)
  509. goto out;
  510. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  511. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  512. set_nlink(dir, lower_dir_dentry->d_inode->i_nlink);
  513. out:
  514. unlock_dir(lower_dir_dentry);
  515. if (!dentry->d_inode)
  516. d_drop(dentry);
  517. return rc;
  518. }
  519. static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
  520. {
  521. struct dentry *lower_dentry;
  522. struct dentry *lower_dir_dentry;
  523. int rc;
  524. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  525. dget(dentry);
  526. lower_dir_dentry = lock_parent(lower_dentry);
  527. dget(lower_dentry);
  528. rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
  529. dput(lower_dentry);
  530. if (!rc && dentry->d_inode)
  531. clear_nlink(dentry->d_inode);
  532. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  533. set_nlink(dir, lower_dir_dentry->d_inode->i_nlink);
  534. unlock_dir(lower_dir_dentry);
  535. if (!rc)
  536. d_drop(dentry);
  537. dput(dentry);
  538. return rc;
  539. }
  540. static int
  541. ecryptfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
  542. {
  543. int rc;
  544. struct dentry *lower_dentry;
  545. struct dentry *lower_dir_dentry;
  546. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  547. lower_dir_dentry = lock_parent(lower_dentry);
  548. rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
  549. if (rc || !lower_dentry->d_inode)
  550. goto out;
  551. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  552. if (rc)
  553. goto out;
  554. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  555. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  556. out:
  557. unlock_dir(lower_dir_dentry);
  558. if (!dentry->d_inode)
  559. d_drop(dentry);
  560. return rc;
  561. }
  562. static int
  563. ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
  564. struct inode *new_dir, struct dentry *new_dentry)
  565. {
  566. int rc;
  567. struct dentry *lower_old_dentry;
  568. struct dentry *lower_new_dentry;
  569. struct dentry *lower_old_dir_dentry;
  570. struct dentry *lower_new_dir_dentry;
  571. struct dentry *trap = NULL;
  572. lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
  573. lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
  574. dget(lower_old_dentry);
  575. dget(lower_new_dentry);
  576. lower_old_dir_dentry = dget_parent(lower_old_dentry);
  577. lower_new_dir_dentry = dget_parent(lower_new_dentry);
  578. trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
  579. /* source should not be ancestor of target */
  580. if (trap == lower_old_dentry) {
  581. rc = -EINVAL;
  582. goto out_lock;
  583. }
  584. /* target should not be ancestor of source */
  585. if (trap == lower_new_dentry) {
  586. rc = -ENOTEMPTY;
  587. goto out_lock;
  588. }
  589. rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
  590. lower_new_dir_dentry->d_inode, lower_new_dentry);
  591. if (rc)
  592. goto out_lock;
  593. fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode);
  594. if (new_dir != old_dir)
  595. fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode);
  596. out_lock:
  597. unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
  598. dput(lower_new_dir_dentry);
  599. dput(lower_old_dir_dentry);
  600. dput(lower_new_dentry);
  601. dput(lower_old_dentry);
  602. return rc;
  603. }
  604. static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
  605. size_t *bufsiz)
  606. {
  607. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  608. char *lower_buf;
  609. mm_segment_t old_fs;
  610. int rc;
  611. lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
  612. if (!lower_buf) {
  613. rc = -ENOMEM;
  614. goto out;
  615. }
  616. old_fs = get_fs();
  617. set_fs(get_ds());
  618. rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
  619. (char __user *)lower_buf,
  620. PATH_MAX);
  621. set_fs(old_fs);
  622. if (rc < 0)
  623. goto out;
  624. rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry,
  625. lower_buf, rc);
  626. out:
  627. kfree(lower_buf);
  628. return rc;
  629. }
  630. static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  631. {
  632. char *buf;
  633. size_t len = PATH_MAX;
  634. int rc;
  635. rc = ecryptfs_readlink_lower(dentry, &buf, &len);
  636. if (rc)
  637. goto out;
  638. fsstack_copy_attr_atime(dentry->d_inode,
  639. ecryptfs_dentry_to_lower(dentry)->d_inode);
  640. buf[len] = '\0';
  641. out:
  642. nd_set_link(nd, buf);
  643. return NULL;
  644. }
  645. static void
  646. ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
  647. {
  648. char *buf = nd_get_link(nd);
  649. if (!IS_ERR(buf)) {
  650. /* Free the char* */
  651. kfree(buf);
  652. }
  653. }
  654. /**
  655. * upper_size_to_lower_size
  656. * @crypt_stat: Crypt_stat associated with file
  657. * @upper_size: Size of the upper file
  658. *
  659. * Calculate the required size of the lower file based on the
  660. * specified size of the upper file. This calculation is based on the
  661. * number of headers in the underlying file and the extent size.
  662. *
  663. * Returns Calculated size of the lower file.
  664. */
  665. static loff_t
  666. upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
  667. loff_t upper_size)
  668. {
  669. loff_t lower_size;
  670. lower_size = ecryptfs_lower_header_size(crypt_stat);
  671. if (upper_size != 0) {
  672. loff_t num_extents;
  673. num_extents = upper_size >> crypt_stat->extent_shift;
  674. if (upper_size & ~crypt_stat->extent_mask)
  675. num_extents++;
  676. lower_size += (num_extents * crypt_stat->extent_size);
  677. }
  678. return lower_size;
  679. }
  680. /**
  681. * truncate_upper
  682. * @dentry: The ecryptfs layer dentry
  683. * @ia: Address of the ecryptfs inode's attributes
  684. * @lower_ia: Address of the lower inode's attributes
  685. *
  686. * Function to handle truncations modifying the size of the file. Note
  687. * that the file sizes are interpolated. When expanding, we are simply
  688. * writing strings of 0's out. When truncating, we truncate the upper
  689. * inode and update the lower_ia according to the page index
  690. * interpolations. If ATTR_SIZE is set in lower_ia->ia_valid upon return,
  691. * the caller must use lower_ia in a call to notify_change() to perform
  692. * the truncation of the lower inode.
  693. *
  694. * Returns zero on success; non-zero otherwise
  695. */
  696. static int truncate_upper(struct dentry *dentry, struct iattr *ia,
  697. struct iattr *lower_ia)
  698. {
  699. int rc = 0;
  700. struct inode *inode = dentry->d_inode;
  701. struct ecryptfs_crypt_stat *crypt_stat;
  702. loff_t i_size = i_size_read(inode);
  703. loff_t lower_size_before_truncate;
  704. loff_t lower_size_after_truncate;
  705. if (unlikely((ia->ia_size == i_size))) {
  706. lower_ia->ia_valid &= ~ATTR_SIZE;
  707. return 0;
  708. }
  709. rc = ecryptfs_get_lower_file(dentry, inode);
  710. if (rc)
  711. return rc;
  712. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  713. /* Switch on growing or shrinking file */
  714. if (ia->ia_size > i_size) {
  715. char zero[] = { 0x00 };
  716. lower_ia->ia_valid &= ~ATTR_SIZE;
  717. /* Write a single 0 at the last position of the file;
  718. * this triggers code that will fill in 0's throughout
  719. * the intermediate portion of the previous end of the
  720. * file and the new and of the file */
  721. rc = ecryptfs_write(inode, zero,
  722. (ia->ia_size - 1), 1);
  723. } else { /* ia->ia_size < i_size_read(inode) */
  724. /* We're chopping off all the pages down to the page
  725. * in which ia->ia_size is located. Fill in the end of
  726. * that page from (ia->ia_size & ~PAGE_CACHE_MASK) to
  727. * PAGE_CACHE_SIZE with zeros. */
  728. size_t num_zeros = (PAGE_CACHE_SIZE
  729. - (ia->ia_size & ~PAGE_CACHE_MASK));
  730. if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
  731. truncate_setsize(inode, ia->ia_size);
  732. lower_ia->ia_size = ia->ia_size;
  733. lower_ia->ia_valid |= ATTR_SIZE;
  734. goto out;
  735. }
  736. if (num_zeros) {
  737. char *zeros_virt;
  738. zeros_virt = kzalloc(num_zeros, GFP_KERNEL);
  739. if (!zeros_virt) {
  740. rc = -ENOMEM;
  741. goto out;
  742. }
  743. rc = ecryptfs_write(inode, zeros_virt,
  744. ia->ia_size, num_zeros);
  745. kfree(zeros_virt);
  746. if (rc) {
  747. printk(KERN_ERR "Error attempting to zero out "
  748. "the remainder of the end page on "
  749. "reducing truncate; rc = [%d]\n", rc);
  750. goto out;
  751. }
  752. }
  753. truncate_setsize(inode, ia->ia_size);
  754. rc = ecryptfs_write_inode_size_to_metadata(inode);
  755. if (rc) {
  756. printk(KERN_ERR "Problem with "
  757. "ecryptfs_write_inode_size_to_metadata; "
  758. "rc = [%d]\n", rc);
  759. goto out;
  760. }
  761. /* We are reducing the size of the ecryptfs file, and need to
  762. * know if we need to reduce the size of the lower file. */
  763. lower_size_before_truncate =
  764. upper_size_to_lower_size(crypt_stat, i_size);
  765. lower_size_after_truncate =
  766. upper_size_to_lower_size(crypt_stat, ia->ia_size);
  767. if (lower_size_after_truncate < lower_size_before_truncate) {
  768. lower_ia->ia_size = lower_size_after_truncate;
  769. lower_ia->ia_valid |= ATTR_SIZE;
  770. } else
  771. lower_ia->ia_valid &= ~ATTR_SIZE;
  772. }
  773. out:
  774. ecryptfs_put_lower_file(inode);
  775. return rc;
  776. }
  777. static int ecryptfs_inode_newsize_ok(struct inode *inode, loff_t offset)
  778. {
  779. struct ecryptfs_crypt_stat *crypt_stat;
  780. loff_t lower_oldsize, lower_newsize;
  781. crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
  782. lower_oldsize = upper_size_to_lower_size(crypt_stat,
  783. i_size_read(inode));
  784. lower_newsize = upper_size_to_lower_size(crypt_stat, offset);
  785. if (lower_newsize > lower_oldsize) {
  786. /*
  787. * The eCryptfs inode and the new *lower* size are mixed here
  788. * because we may not have the lower i_mutex held and/or it may
  789. * not be appropriate to call inode_newsize_ok() with inodes
  790. * from other filesystems.
  791. */
  792. return inode_newsize_ok(inode, lower_newsize);
  793. }
  794. return 0;
  795. }
  796. /**
  797. * ecryptfs_truncate
  798. * @dentry: The ecryptfs layer dentry
  799. * @new_length: The length to expand the file to
  800. *
  801. * Simple function that handles the truncation of an eCryptfs inode and
  802. * its corresponding lower inode.
  803. *
  804. * Returns zero on success; non-zero otherwise
  805. */
  806. int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
  807. {
  808. struct iattr ia = { .ia_valid = ATTR_SIZE, .ia_size = new_length };
  809. struct iattr lower_ia = { .ia_valid = 0 };
  810. int rc;
  811. rc = ecryptfs_inode_newsize_ok(dentry->d_inode, new_length);
  812. if (rc)
  813. return rc;
  814. rc = truncate_upper(dentry, &ia, &lower_ia);
  815. if (!rc && lower_ia.ia_valid & ATTR_SIZE) {
  816. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  817. mutex_lock(&lower_dentry->d_inode->i_mutex);
  818. rc = notify_change(lower_dentry, &lower_ia);
  819. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  820. }
  821. return rc;
  822. }
  823. static int
  824. ecryptfs_permission(struct inode *inode, int mask)
  825. {
  826. return inode_permission(ecryptfs_inode_to_lower(inode), mask);
  827. }
  828. /**
  829. * ecryptfs_setattr
  830. * @dentry: dentry handle to the inode to modify
  831. * @ia: Structure with flags of what to change and values
  832. *
  833. * Updates the metadata of an inode. If the update is to the size
  834. * i.e. truncation, then ecryptfs_truncate will handle the size modification
  835. * of both the ecryptfs inode and the lower inode.
  836. *
  837. * All other metadata changes will be passed right to the lower filesystem,
  838. * and we will just update our inode to look like the lower.
  839. */
  840. static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
  841. {
  842. int rc = 0;
  843. struct dentry *lower_dentry;
  844. struct iattr lower_ia;
  845. struct inode *inode;
  846. struct inode *lower_inode;
  847. struct ecryptfs_crypt_stat *crypt_stat;
  848. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  849. if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED))
  850. ecryptfs_init_crypt_stat(crypt_stat);
  851. inode = dentry->d_inode;
  852. lower_inode = ecryptfs_inode_to_lower(inode);
  853. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  854. mutex_lock(&crypt_stat->cs_mutex);
  855. if (S_ISDIR(dentry->d_inode->i_mode))
  856. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  857. else if (S_ISREG(dentry->d_inode->i_mode)
  858. && (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
  859. || !(crypt_stat->flags & ECRYPTFS_KEY_VALID))) {
  860. struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
  861. mount_crypt_stat = &ecryptfs_superblock_to_private(
  862. dentry->d_sb)->mount_crypt_stat;
  863. rc = ecryptfs_get_lower_file(dentry, inode);
  864. if (rc) {
  865. mutex_unlock(&crypt_stat->cs_mutex);
  866. goto out;
  867. }
  868. rc = ecryptfs_read_metadata(dentry);
  869. ecryptfs_put_lower_file(inode);
  870. if (rc) {
  871. if (!(mount_crypt_stat->flags
  872. & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
  873. rc = -EIO;
  874. printk(KERN_WARNING "Either the lower file "
  875. "is not in a valid eCryptfs format, "
  876. "or the key could not be retrieved. "
  877. "Plaintext passthrough mode is not "
  878. "enabled; returning -EIO\n");
  879. mutex_unlock(&crypt_stat->cs_mutex);
  880. goto out;
  881. }
  882. rc = 0;
  883. crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED
  884. | ECRYPTFS_ENCRYPTED);
  885. }
  886. }
  887. mutex_unlock(&crypt_stat->cs_mutex);
  888. rc = inode_change_ok(inode, ia);
  889. if (rc)
  890. goto out;
  891. if (ia->ia_valid & ATTR_SIZE) {
  892. rc = ecryptfs_inode_newsize_ok(inode, ia->ia_size);
  893. if (rc)
  894. goto out;
  895. }
  896. if (S_ISREG(inode->i_mode)) {
  897. rc = filemap_write_and_wait(inode->i_mapping);
  898. if (rc)
  899. goto out;
  900. fsstack_copy_attr_all(inode, lower_inode);
  901. }
  902. memcpy(&lower_ia, ia, sizeof(lower_ia));
  903. if (ia->ia_valid & ATTR_FILE)
  904. lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file);
  905. if (ia->ia_valid & ATTR_SIZE) {
  906. rc = truncate_upper(dentry, ia, &lower_ia);
  907. if (rc < 0)
  908. goto out;
  909. }
  910. /*
  911. * mode change is for clearing setuid/setgid bits. Allow lower fs
  912. * to interpret this in its own way.
  913. */
  914. if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
  915. lower_ia.ia_valid &= ~ATTR_MODE;
  916. mutex_lock(&lower_dentry->d_inode->i_mutex);
  917. rc = notify_change(lower_dentry, &lower_ia);
  918. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  919. out:
  920. fsstack_copy_attr_all(inode, lower_inode);
  921. return rc;
  922. }
  923. int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
  924. struct kstat *stat)
  925. {
  926. struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
  927. int rc = 0;
  928. mount_crypt_stat = &ecryptfs_superblock_to_private(
  929. dentry->d_sb)->mount_crypt_stat;
  930. generic_fillattr(dentry->d_inode, stat);
  931. if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) {
  932. char *target;
  933. size_t targetsiz;
  934. rc = ecryptfs_readlink_lower(dentry, &target, &targetsiz);
  935. if (!rc) {
  936. kfree(target);
  937. stat->size = targetsiz;
  938. }
  939. }
  940. return rc;
  941. }
  942. int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  943. struct kstat *stat)
  944. {
  945. struct kstat lower_stat;
  946. int rc;
  947. rc = vfs_getattr(ecryptfs_dentry_to_lower_mnt(dentry),
  948. ecryptfs_dentry_to_lower(dentry), &lower_stat);
  949. if (!rc) {
  950. fsstack_copy_attr_all(dentry->d_inode,
  951. ecryptfs_inode_to_lower(dentry->d_inode));
  952. generic_fillattr(dentry->d_inode, stat);
  953. stat->blocks = lower_stat.blocks;
  954. }
  955. return rc;
  956. }
  957. int
  958. ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  959. size_t size, int flags)
  960. {
  961. int rc = 0;
  962. struct dentry *lower_dentry;
  963. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  964. if (!lower_dentry->d_inode->i_op->setxattr) {
  965. rc = -EOPNOTSUPP;
  966. goto out;
  967. }
  968. rc = vfs_setxattr(lower_dentry, name, value, size, flags);
  969. if (!rc)
  970. fsstack_copy_attr_all(dentry->d_inode, lower_dentry->d_inode);
  971. out:
  972. return rc;
  973. }
  974. ssize_t
  975. ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
  976. void *value, size_t size)
  977. {
  978. int rc = 0;
  979. if (!lower_dentry->d_inode->i_op->getxattr) {
  980. rc = -EOPNOTSUPP;
  981. goto out;
  982. }
  983. mutex_lock(&lower_dentry->d_inode->i_mutex);
  984. rc = lower_dentry->d_inode->i_op->getxattr(lower_dentry, name, value,
  985. size);
  986. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  987. out:
  988. return rc;
  989. }
  990. static ssize_t
  991. ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
  992. size_t size)
  993. {
  994. return ecryptfs_getxattr_lower(ecryptfs_dentry_to_lower(dentry), name,
  995. value, size);
  996. }
  997. static ssize_t
  998. ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size)
  999. {
  1000. int rc = 0;
  1001. struct dentry *lower_dentry;
  1002. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  1003. if (!lower_dentry->d_inode->i_op->listxattr) {
  1004. rc = -EOPNOTSUPP;
  1005. goto out;
  1006. }
  1007. mutex_lock(&lower_dentry->d_inode->i_mutex);
  1008. rc = lower_dentry->d_inode->i_op->listxattr(lower_dentry, list, size);
  1009. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  1010. out:
  1011. return rc;
  1012. }
  1013. static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
  1014. {
  1015. int rc = 0;
  1016. struct dentry *lower_dentry;
  1017. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  1018. if (!lower_dentry->d_inode->i_op->removexattr) {
  1019. rc = -EOPNOTSUPP;
  1020. goto out;
  1021. }
  1022. mutex_lock(&lower_dentry->d_inode->i_mutex);
  1023. rc = lower_dentry->d_inode->i_op->removexattr(lower_dentry, name);
  1024. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  1025. out:
  1026. return rc;
  1027. }
  1028. const struct inode_operations ecryptfs_symlink_iops = {
  1029. .readlink = generic_readlink,
  1030. .follow_link = ecryptfs_follow_link,
  1031. .put_link = ecryptfs_put_link,
  1032. .permission = ecryptfs_permission,
  1033. .setattr = ecryptfs_setattr,
  1034. .getattr = ecryptfs_getattr_link,
  1035. .setxattr = ecryptfs_setxattr,
  1036. .getxattr = ecryptfs_getxattr,
  1037. .listxattr = ecryptfs_listxattr,
  1038. .removexattr = ecryptfs_removexattr
  1039. };
  1040. const struct inode_operations ecryptfs_dir_iops = {
  1041. .create = ecryptfs_create,
  1042. .lookup = ecryptfs_lookup,
  1043. .link = ecryptfs_link,
  1044. .unlink = ecryptfs_unlink,
  1045. .symlink = ecryptfs_symlink,
  1046. .mkdir = ecryptfs_mkdir,
  1047. .rmdir = ecryptfs_rmdir,
  1048. .mknod = ecryptfs_mknod,
  1049. .rename = ecryptfs_rename,
  1050. .permission = ecryptfs_permission,
  1051. .setattr = ecryptfs_setattr,
  1052. .setxattr = ecryptfs_setxattr,
  1053. .getxattr = ecryptfs_getxattr,
  1054. .listxattr = ecryptfs_listxattr,
  1055. .removexattr = ecryptfs_removexattr
  1056. };
  1057. const struct inode_operations ecryptfs_main_iops = {
  1058. .permission = ecryptfs_permission,
  1059. .setattr = ecryptfs_setattr,
  1060. .getattr = ecryptfs_getattr,
  1061. .setxattr = ecryptfs_setxattr,
  1062. .getxattr = ecryptfs_getxattr,
  1063. .listxattr = ecryptfs_listxattr,
  1064. .removexattr = ecryptfs_removexattr
  1065. };