inode.c 33 KB

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