inode.c 32 KB

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