inode.c 32 KB

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