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