inode.c 32 KB

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