inode.c 32 KB

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