xfs_iops.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_bit.h"
  21. #include "xfs_log.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_dir.h"
  27. #include "xfs_dir2.h"
  28. #include "xfs_alloc.h"
  29. #include "xfs_dmapi.h"
  30. #include "xfs_quota.h"
  31. #include "xfs_mount.h"
  32. #include "xfs_bmap_btree.h"
  33. #include "xfs_alloc_btree.h"
  34. #include "xfs_ialloc_btree.h"
  35. #include "xfs_dir_sf.h"
  36. #include "xfs_dir2_sf.h"
  37. #include "xfs_attr_sf.h"
  38. #include "xfs_dinode.h"
  39. #include "xfs_inode.h"
  40. #include "xfs_bmap.h"
  41. #include "xfs_btree.h"
  42. #include "xfs_ialloc.h"
  43. #include "xfs_rtalloc.h"
  44. #include "xfs_error.h"
  45. #include "xfs_itable.h"
  46. #include "xfs_rw.h"
  47. #include "xfs_acl.h"
  48. #include "xfs_cap.h"
  49. #include "xfs_mac.h"
  50. #include "xfs_attr.h"
  51. #include "xfs_buf_item.h"
  52. #include "xfs_utils.h"
  53. #include <linux/capability.h>
  54. #include <linux/xattr.h>
  55. #include <linux/namei.h>
  56. #define IS_NOATIME(inode) ((inode->i_sb->s_flags & MS_NOATIME) || \
  57. (S_ISDIR(inode->i_mode) && inode->i_sb->s_flags & MS_NODIRATIME))
  58. /*
  59. * Change the requested timestamp in the given inode.
  60. * We don't lock across timestamp updates, and we don't log them but
  61. * we do record the fact that there is dirty information in core.
  62. *
  63. * NOTE -- callers MUST combine XFS_ICHGTIME_MOD or XFS_ICHGTIME_CHG
  64. * with XFS_ICHGTIME_ACC to be sure that access time
  65. * update will take. Calling first with XFS_ICHGTIME_ACC
  66. * and then XFS_ICHGTIME_MOD may fail to modify the access
  67. * timestamp if the filesystem is mounted noacctm.
  68. */
  69. void
  70. xfs_ichgtime(
  71. xfs_inode_t *ip,
  72. int flags)
  73. {
  74. struct inode *inode = LINVFS_GET_IP(XFS_ITOV(ip));
  75. timespec_t tv;
  76. /*
  77. * We're not supposed to change timestamps in readonly-mounted
  78. * filesystems. Throw it away if anyone asks us.
  79. */
  80. if (unlikely(IS_RDONLY(inode)))
  81. return;
  82. /*
  83. * Don't update access timestamps on reads if mounted "noatime".
  84. * Throw it away if anyone asks us.
  85. */
  86. if (unlikely(
  87. (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
  88. (flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
  89. XFS_ICHGTIME_ACC))
  90. return;
  91. nanotime(&tv);
  92. if (flags & XFS_ICHGTIME_MOD) {
  93. inode->i_mtime = tv;
  94. ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
  95. ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
  96. }
  97. if (flags & XFS_ICHGTIME_ACC) {
  98. inode->i_atime = tv;
  99. ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
  100. ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
  101. }
  102. if (flags & XFS_ICHGTIME_CHG) {
  103. inode->i_ctime = tv;
  104. ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
  105. ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
  106. }
  107. /*
  108. * We update the i_update_core field _after_ changing
  109. * the timestamps in order to coordinate properly with
  110. * xfs_iflush() so that we don't lose timestamp updates.
  111. * This keeps us from having to hold the inode lock
  112. * while doing this. We use the SYNCHRONIZE macro to
  113. * ensure that the compiler does not reorder the update
  114. * of i_update_core above the timestamp updates above.
  115. */
  116. SYNCHRONIZE();
  117. ip->i_update_core = 1;
  118. if (!(inode->i_state & I_LOCK))
  119. mark_inode_dirty_sync(inode);
  120. }
  121. /*
  122. * Variant on the above which avoids querying the system clock
  123. * in situations where we know the Linux inode timestamps have
  124. * just been updated (and so we can update our inode cheaply).
  125. * We also skip the readonly and noatime checks here, they are
  126. * also catered for already.
  127. */
  128. void
  129. xfs_ichgtime_fast(
  130. xfs_inode_t *ip,
  131. struct inode *inode,
  132. int flags)
  133. {
  134. timespec_t *tvp;
  135. /*
  136. * We're not supposed to change timestamps in readonly-mounted
  137. * filesystems. Throw it away if anyone asks us.
  138. */
  139. if (unlikely(IS_RDONLY(inode)))
  140. return;
  141. /*
  142. * Don't update access timestamps on reads if mounted "noatime".
  143. * Throw it away if anyone asks us.
  144. */
  145. if (unlikely(
  146. (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
  147. ((flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
  148. XFS_ICHGTIME_ACC)))
  149. return;
  150. if (flags & XFS_ICHGTIME_MOD) {
  151. tvp = &inode->i_mtime;
  152. ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
  153. ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
  154. }
  155. if (flags & XFS_ICHGTIME_ACC) {
  156. tvp = &inode->i_atime;
  157. ip->i_d.di_atime.t_sec = (__int32_t)tvp->tv_sec;
  158. ip->i_d.di_atime.t_nsec = (__int32_t)tvp->tv_nsec;
  159. }
  160. if (flags & XFS_ICHGTIME_CHG) {
  161. tvp = &inode->i_ctime;
  162. ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
  163. ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
  164. }
  165. /*
  166. * We update the i_update_core field _after_ changing
  167. * the timestamps in order to coordinate properly with
  168. * xfs_iflush() so that we don't lose timestamp updates.
  169. * This keeps us from having to hold the inode lock
  170. * while doing this. We use the SYNCHRONIZE macro to
  171. * ensure that the compiler does not reorder the update
  172. * of i_update_core above the timestamp updates above.
  173. */
  174. SYNCHRONIZE();
  175. ip->i_update_core = 1;
  176. if (!(inode->i_state & I_LOCK))
  177. mark_inode_dirty_sync(inode);
  178. }
  179. /*
  180. * Pull the link count and size up from the xfs inode to the linux inode
  181. */
  182. STATIC void
  183. validate_fields(
  184. struct inode *ip)
  185. {
  186. vnode_t *vp = LINVFS_GET_VP(ip);
  187. vattr_t va;
  188. int error;
  189. va.va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS;
  190. VOP_GETATTR(vp, &va, ATTR_LAZY, NULL, error);
  191. if (likely(!error)) {
  192. ip->i_nlink = va.va_nlink;
  193. ip->i_blocks = va.va_nblocks;
  194. /* we're under i_mutex so i_size can't change under us */
  195. if (i_size_read(ip) != va.va_size)
  196. i_size_write(ip, va.va_size);
  197. }
  198. }
  199. /*
  200. * Determine whether a process has a valid fs_struct (kernel daemons
  201. * like knfsd don't have an fs_struct).
  202. *
  203. * XXX(hch): nfsd is broken, better fix it instead.
  204. */
  205. STATIC inline int
  206. has_fs_struct(struct task_struct *task)
  207. {
  208. return (task->fs != init_task.fs);
  209. }
  210. STATIC int
  211. linvfs_mknod(
  212. struct inode *dir,
  213. struct dentry *dentry,
  214. int mode,
  215. dev_t rdev)
  216. {
  217. struct inode *ip;
  218. vattr_t va;
  219. vnode_t *vp = NULL, *dvp = LINVFS_GET_VP(dir);
  220. xfs_acl_t *default_acl = NULL;
  221. attrexists_t test_default_acl = _ACL_DEFAULT_EXISTS;
  222. int error;
  223. /*
  224. * Irix uses Missed'em'V split, but doesn't want to see
  225. * the upper 5 bits of (14bit) major.
  226. */
  227. if (!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)
  228. return -EINVAL;
  229. if (test_default_acl && test_default_acl(dvp)) {
  230. if (!_ACL_ALLOC(default_acl))
  231. return -ENOMEM;
  232. if (!_ACL_GET_DEFAULT(dvp, default_acl)) {
  233. _ACL_FREE(default_acl);
  234. default_acl = NULL;
  235. }
  236. }
  237. if (IS_POSIXACL(dir) && !default_acl && has_fs_struct(current))
  238. mode &= ~current->fs->umask;
  239. memset(&va, 0, sizeof(va));
  240. va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
  241. va.va_mode = mode;
  242. switch (mode & S_IFMT) {
  243. case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK:
  244. va.va_rdev = sysv_encode_dev(rdev);
  245. va.va_mask |= XFS_AT_RDEV;
  246. /*FALLTHROUGH*/
  247. case S_IFREG:
  248. VOP_CREATE(dvp, dentry, &va, &vp, NULL, error);
  249. break;
  250. case S_IFDIR:
  251. VOP_MKDIR(dvp, dentry, &va, &vp, NULL, error);
  252. break;
  253. default:
  254. error = EINVAL;
  255. break;
  256. }
  257. if (default_acl) {
  258. if (!error) {
  259. error = _ACL_INHERIT(vp, &va, default_acl);
  260. if (!error) {
  261. VMODIFY(vp);
  262. } else {
  263. struct dentry teardown = {};
  264. int err2;
  265. /* Oh, the horror.
  266. * If we can't add the ACL we must back out.
  267. * ENOSPC can hit here, among other things.
  268. */
  269. teardown.d_inode = ip = LINVFS_GET_IP(vp);
  270. teardown.d_name = dentry->d_name;
  271. vn_mark_bad(vp);
  272. if (S_ISDIR(mode))
  273. VOP_RMDIR(dvp, &teardown, NULL, err2);
  274. else
  275. VOP_REMOVE(dvp, &teardown, NULL, err2);
  276. VN_RELE(vp);
  277. }
  278. }
  279. _ACL_FREE(default_acl);
  280. }
  281. if (!error) {
  282. ASSERT(vp);
  283. ip = LINVFS_GET_IP(vp);
  284. if (S_ISCHR(mode) || S_ISBLK(mode))
  285. ip->i_rdev = rdev;
  286. else if (S_ISDIR(mode))
  287. validate_fields(ip);
  288. d_instantiate(dentry, ip);
  289. validate_fields(dir);
  290. }
  291. return -error;
  292. }
  293. STATIC int
  294. linvfs_create(
  295. struct inode *dir,
  296. struct dentry *dentry,
  297. int mode,
  298. struct nameidata *nd)
  299. {
  300. return linvfs_mknod(dir, dentry, mode, 0);
  301. }
  302. STATIC int
  303. linvfs_mkdir(
  304. struct inode *dir,
  305. struct dentry *dentry,
  306. int mode)
  307. {
  308. return linvfs_mknod(dir, dentry, mode|S_IFDIR, 0);
  309. }
  310. STATIC struct dentry *
  311. linvfs_lookup(
  312. struct inode *dir,
  313. struct dentry *dentry,
  314. struct nameidata *nd)
  315. {
  316. struct vnode *vp = LINVFS_GET_VP(dir), *cvp;
  317. int error;
  318. if (dentry->d_name.len >= MAXNAMELEN)
  319. return ERR_PTR(-ENAMETOOLONG);
  320. VOP_LOOKUP(vp, dentry, &cvp, 0, NULL, NULL, error);
  321. if (error) {
  322. if (unlikely(error != ENOENT))
  323. return ERR_PTR(-error);
  324. d_add(dentry, NULL);
  325. return NULL;
  326. }
  327. return d_splice_alias(LINVFS_GET_IP(cvp), dentry);
  328. }
  329. STATIC int
  330. linvfs_link(
  331. struct dentry *old_dentry,
  332. struct inode *dir,
  333. struct dentry *dentry)
  334. {
  335. struct inode *ip; /* inode of guy being linked to */
  336. vnode_t *tdvp; /* target directory for new name/link */
  337. vnode_t *vp; /* vp of name being linked */
  338. int error;
  339. ip = old_dentry->d_inode; /* inode being linked to */
  340. if (S_ISDIR(ip->i_mode))
  341. return -EPERM;
  342. tdvp = LINVFS_GET_VP(dir);
  343. vp = LINVFS_GET_VP(ip);
  344. VOP_LINK(tdvp, vp, dentry, NULL, error);
  345. if (!error) {
  346. VMODIFY(tdvp);
  347. VN_HOLD(vp);
  348. validate_fields(ip);
  349. d_instantiate(dentry, ip);
  350. }
  351. return -error;
  352. }
  353. STATIC int
  354. linvfs_unlink(
  355. struct inode *dir,
  356. struct dentry *dentry)
  357. {
  358. struct inode *inode;
  359. vnode_t *dvp; /* directory containing name to remove */
  360. int error;
  361. inode = dentry->d_inode;
  362. dvp = LINVFS_GET_VP(dir);
  363. VOP_REMOVE(dvp, dentry, NULL, error);
  364. if (!error) {
  365. validate_fields(dir); /* For size only */
  366. validate_fields(inode);
  367. }
  368. return -error;
  369. }
  370. STATIC int
  371. linvfs_symlink(
  372. struct inode *dir,
  373. struct dentry *dentry,
  374. const char *symname)
  375. {
  376. struct inode *ip;
  377. vattr_t va;
  378. vnode_t *dvp; /* directory containing name of symlink */
  379. vnode_t *cvp; /* used to lookup symlink to put in dentry */
  380. int error;
  381. dvp = LINVFS_GET_VP(dir);
  382. cvp = NULL;
  383. memset(&va, 0, sizeof(va));
  384. va.va_mode = S_IFLNK |
  385. (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
  386. va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
  387. error = 0;
  388. VOP_SYMLINK(dvp, dentry, &va, (char *)symname, &cvp, NULL, error);
  389. if (!error && cvp) {
  390. ip = LINVFS_GET_IP(cvp);
  391. d_instantiate(dentry, ip);
  392. validate_fields(dir);
  393. validate_fields(ip); /* size needs update */
  394. }
  395. return -error;
  396. }
  397. STATIC int
  398. linvfs_rmdir(
  399. struct inode *dir,
  400. struct dentry *dentry)
  401. {
  402. struct inode *inode = dentry->d_inode;
  403. vnode_t *dvp = LINVFS_GET_VP(dir);
  404. int error;
  405. VOP_RMDIR(dvp, dentry, NULL, error);
  406. if (!error) {
  407. validate_fields(inode);
  408. validate_fields(dir);
  409. }
  410. return -error;
  411. }
  412. STATIC int
  413. linvfs_rename(
  414. struct inode *odir,
  415. struct dentry *odentry,
  416. struct inode *ndir,
  417. struct dentry *ndentry)
  418. {
  419. struct inode *new_inode = ndentry->d_inode;
  420. vnode_t *fvp; /* from directory */
  421. vnode_t *tvp; /* target directory */
  422. int error;
  423. fvp = LINVFS_GET_VP(odir);
  424. tvp = LINVFS_GET_VP(ndir);
  425. VOP_RENAME(fvp, odentry, tvp, ndentry, NULL, error);
  426. if (error)
  427. return -error;
  428. if (new_inode)
  429. validate_fields(new_inode);
  430. validate_fields(odir);
  431. if (ndir != odir)
  432. validate_fields(ndir);
  433. return 0;
  434. }
  435. /*
  436. * careful here - this function can get called recursively, so
  437. * we need to be very careful about how much stack we use.
  438. * uio is kmalloced for this reason...
  439. */
  440. STATIC void *
  441. linvfs_follow_link(
  442. struct dentry *dentry,
  443. struct nameidata *nd)
  444. {
  445. vnode_t *vp;
  446. uio_t *uio;
  447. iovec_t iov;
  448. int error;
  449. char *link;
  450. ASSERT(dentry);
  451. ASSERT(nd);
  452. link = (char *)kmalloc(MAXNAMELEN+1, GFP_KERNEL);
  453. if (!link) {
  454. nd_set_link(nd, ERR_PTR(-ENOMEM));
  455. return NULL;
  456. }
  457. uio = (uio_t *)kmalloc(sizeof(uio_t), GFP_KERNEL);
  458. if (!uio) {
  459. kfree(link);
  460. nd_set_link(nd, ERR_PTR(-ENOMEM));
  461. return NULL;
  462. }
  463. vp = LINVFS_GET_VP(dentry->d_inode);
  464. iov.iov_base = link;
  465. iov.iov_len = MAXNAMELEN;
  466. uio->uio_iov = &iov;
  467. uio->uio_offset = 0;
  468. uio->uio_segflg = UIO_SYSSPACE;
  469. uio->uio_resid = MAXNAMELEN;
  470. uio->uio_iovcnt = 1;
  471. VOP_READLINK(vp, uio, 0, NULL, error);
  472. if (error) {
  473. kfree(link);
  474. link = ERR_PTR(-error);
  475. } else {
  476. link[MAXNAMELEN - uio->uio_resid] = '\0';
  477. }
  478. kfree(uio);
  479. nd_set_link(nd, link);
  480. return NULL;
  481. }
  482. STATIC void
  483. linvfs_put_link(
  484. struct dentry *dentry,
  485. struct nameidata *nd,
  486. void *p)
  487. {
  488. char *s = nd_get_link(nd);
  489. if (!IS_ERR(s))
  490. kfree(s);
  491. }
  492. #ifdef CONFIG_XFS_POSIX_ACL
  493. STATIC int
  494. linvfs_permission(
  495. struct inode *inode,
  496. int mode,
  497. struct nameidata *nd)
  498. {
  499. vnode_t *vp = LINVFS_GET_VP(inode);
  500. int error;
  501. mode <<= 6; /* convert from linux to vnode access bits */
  502. VOP_ACCESS(vp, mode, NULL, error);
  503. return -error;
  504. }
  505. #else
  506. #define linvfs_permission NULL
  507. #endif
  508. STATIC int
  509. linvfs_getattr(
  510. struct vfsmount *mnt,
  511. struct dentry *dentry,
  512. struct kstat *stat)
  513. {
  514. struct inode *inode = dentry->d_inode;
  515. vnode_t *vp = LINVFS_GET_VP(inode);
  516. int error = 0;
  517. if (unlikely(vp->v_flag & VMODIFIED))
  518. error = vn_revalidate(vp);
  519. if (!error)
  520. generic_fillattr(inode, stat);
  521. return 0;
  522. }
  523. STATIC int
  524. linvfs_setattr(
  525. struct dentry *dentry,
  526. struct iattr *attr)
  527. {
  528. struct inode *inode = dentry->d_inode;
  529. unsigned int ia_valid = attr->ia_valid;
  530. vnode_t *vp = LINVFS_GET_VP(inode);
  531. vattr_t vattr;
  532. int flags = 0;
  533. int error;
  534. memset(&vattr, 0, sizeof(vattr_t));
  535. if (ia_valid & ATTR_UID) {
  536. vattr.va_mask |= XFS_AT_UID;
  537. vattr.va_uid = attr->ia_uid;
  538. }
  539. if (ia_valid & ATTR_GID) {
  540. vattr.va_mask |= XFS_AT_GID;
  541. vattr.va_gid = attr->ia_gid;
  542. }
  543. if (ia_valid & ATTR_SIZE) {
  544. vattr.va_mask |= XFS_AT_SIZE;
  545. vattr.va_size = attr->ia_size;
  546. }
  547. if (ia_valid & ATTR_ATIME) {
  548. vattr.va_mask |= XFS_AT_ATIME;
  549. vattr.va_atime = attr->ia_atime;
  550. }
  551. if (ia_valid & ATTR_MTIME) {
  552. vattr.va_mask |= XFS_AT_MTIME;
  553. vattr.va_mtime = attr->ia_mtime;
  554. }
  555. if (ia_valid & ATTR_CTIME) {
  556. vattr.va_mask |= XFS_AT_CTIME;
  557. vattr.va_ctime = attr->ia_ctime;
  558. }
  559. if (ia_valid & ATTR_MODE) {
  560. vattr.va_mask |= XFS_AT_MODE;
  561. vattr.va_mode = attr->ia_mode;
  562. if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
  563. inode->i_mode &= ~S_ISGID;
  564. }
  565. if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))
  566. flags |= ATTR_UTIME;
  567. #ifdef ATTR_NO_BLOCK
  568. if ((ia_valid & ATTR_NO_BLOCK))
  569. flags |= ATTR_NONBLOCK;
  570. #endif
  571. VOP_SETATTR(vp, &vattr, flags, NULL, error);
  572. if (error)
  573. return -error;
  574. vn_revalidate(vp);
  575. return error;
  576. }
  577. STATIC void
  578. linvfs_truncate(
  579. struct inode *inode)
  580. {
  581. block_truncate_page(inode->i_mapping, inode->i_size, linvfs_get_block);
  582. }
  583. STATIC int
  584. linvfs_setxattr(
  585. struct dentry *dentry,
  586. const char *name,
  587. const void *data,
  588. size_t size,
  589. int flags)
  590. {
  591. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  592. char *attr = (char *)name;
  593. attrnames_t *namesp;
  594. int xflags = 0;
  595. int error;
  596. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  597. if (!namesp)
  598. return -EOPNOTSUPP;
  599. attr += namesp->attr_namelen;
  600. error = namesp->attr_capable(vp, NULL);
  601. if (error)
  602. return error;
  603. /* Convert Linux syscall to XFS internal ATTR flags */
  604. if (flags & XATTR_CREATE)
  605. xflags |= ATTR_CREATE;
  606. if (flags & XATTR_REPLACE)
  607. xflags |= ATTR_REPLACE;
  608. xflags |= namesp->attr_flag;
  609. return namesp->attr_set(vp, attr, (void *)data, size, xflags);
  610. }
  611. STATIC ssize_t
  612. linvfs_getxattr(
  613. struct dentry *dentry,
  614. const char *name,
  615. void *data,
  616. size_t size)
  617. {
  618. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  619. char *attr = (char *)name;
  620. attrnames_t *namesp;
  621. int xflags = 0;
  622. ssize_t error;
  623. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  624. if (!namesp)
  625. return -EOPNOTSUPP;
  626. attr += namesp->attr_namelen;
  627. error = namesp->attr_capable(vp, NULL);
  628. if (error)
  629. return error;
  630. /* Convert Linux syscall to XFS internal ATTR flags */
  631. if (!size) {
  632. xflags |= ATTR_KERNOVAL;
  633. data = NULL;
  634. }
  635. xflags |= namesp->attr_flag;
  636. return namesp->attr_get(vp, attr, (void *)data, size, xflags);
  637. }
  638. STATIC ssize_t
  639. linvfs_listxattr(
  640. struct dentry *dentry,
  641. char *data,
  642. size_t size)
  643. {
  644. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  645. int error, xflags = ATTR_KERNAMELS;
  646. ssize_t result;
  647. if (!size)
  648. xflags |= ATTR_KERNOVAL;
  649. xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS;
  650. error = attr_generic_list(vp, data, size, xflags, &result);
  651. if (error < 0)
  652. return error;
  653. return result;
  654. }
  655. STATIC int
  656. linvfs_removexattr(
  657. struct dentry *dentry,
  658. const char *name)
  659. {
  660. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  661. char *attr = (char *)name;
  662. attrnames_t *namesp;
  663. int xflags = 0;
  664. int error;
  665. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  666. if (!namesp)
  667. return -EOPNOTSUPP;
  668. attr += namesp->attr_namelen;
  669. error = namesp->attr_capable(vp, NULL);
  670. if (error)
  671. return error;
  672. xflags |= namesp->attr_flag;
  673. return namesp->attr_remove(vp, attr, xflags);
  674. }
  675. struct inode_operations linvfs_file_inode_operations = {
  676. .permission = linvfs_permission,
  677. .truncate = linvfs_truncate,
  678. .getattr = linvfs_getattr,
  679. .setattr = linvfs_setattr,
  680. .setxattr = linvfs_setxattr,
  681. .getxattr = linvfs_getxattr,
  682. .listxattr = linvfs_listxattr,
  683. .removexattr = linvfs_removexattr,
  684. };
  685. struct inode_operations linvfs_dir_inode_operations = {
  686. .create = linvfs_create,
  687. .lookup = linvfs_lookup,
  688. .link = linvfs_link,
  689. .unlink = linvfs_unlink,
  690. .symlink = linvfs_symlink,
  691. .mkdir = linvfs_mkdir,
  692. .rmdir = linvfs_rmdir,
  693. .mknod = linvfs_mknod,
  694. .rename = linvfs_rename,
  695. .permission = linvfs_permission,
  696. .getattr = linvfs_getattr,
  697. .setattr = linvfs_setattr,
  698. .setxattr = linvfs_setxattr,
  699. .getxattr = linvfs_getxattr,
  700. .listxattr = linvfs_listxattr,
  701. .removexattr = linvfs_removexattr,
  702. };
  703. struct inode_operations linvfs_symlink_inode_operations = {
  704. .readlink = generic_readlink,
  705. .follow_link = linvfs_follow_link,
  706. .put_link = linvfs_put_link,
  707. .permission = linvfs_permission,
  708. .getattr = linvfs_getattr,
  709. .setattr = linvfs_setattr,
  710. .setxattr = linvfs_setxattr,
  711. .getxattr = linvfs_getxattr,
  712. .listxattr = linvfs_listxattr,
  713. .removexattr = linvfs_removexattr,
  714. };