xattr.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. /*
  2. * linux/fs/reiserfs/xattr.c
  3. *
  4. * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com>
  5. *
  6. */
  7. /*
  8. * In order to implement EA/ACLs in a clean, backwards compatible manner,
  9. * they are implemented as files in a "private" directory.
  10. * Each EA is in it's own file, with the directory layout like so (/ is assumed
  11. * to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory,
  12. * directories named using the capital-hex form of the objectid and
  13. * generation number are used. Inside each directory are individual files
  14. * named with the name of the extended attribute.
  15. *
  16. * So, for objectid 12648430, we could have:
  17. * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access
  18. * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default
  19. * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type
  20. * .. or similar.
  21. *
  22. * The file contents are the text of the EA. The size is known based on the
  23. * stat data describing the file.
  24. *
  25. * In the case of system.posix_acl_access and system.posix_acl_default, since
  26. * these are special cases for filesystem ACLs, they are interpreted by the
  27. * kernel, in addition, they are negatively and positively cached and attached
  28. * to the inode so that unnecessary lookups are avoided.
  29. */
  30. #include <linux/reiserfs_fs.h>
  31. #include <linux/capability.h>
  32. #include <linux/dcache.h>
  33. #include <linux/namei.h>
  34. #include <linux/errno.h>
  35. #include <linux/fs.h>
  36. #include <linux/file.h>
  37. #include <linux/pagemap.h>
  38. #include <linux/xattr.h>
  39. #include <linux/reiserfs_xattr.h>
  40. #include <linux/reiserfs_acl.h>
  41. #include <asm/uaccess.h>
  42. #include <net/checksum.h>
  43. #include <linux/smp_lock.h>
  44. #include <linux/stat.h>
  45. #include <asm/semaphore.h>
  46. #define FL_READONLY 128
  47. #define FL_DIR_SEM_HELD 256
  48. #define PRIVROOT_NAME ".reiserfs_priv"
  49. #define XAROOT_NAME "xattrs"
  50. static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
  51. *prefix);
  52. /* Returns the dentry referring to the root of the extended attribute
  53. * directory tree. If it has already been retrieved, it is used. If it
  54. * hasn't been created and the flags indicate creation is allowed, we
  55. * attempt to create it. On error, we return a pointer-encoded error.
  56. */
  57. static struct dentry *get_xa_root(struct super_block *sb, int flags)
  58. {
  59. struct dentry *privroot = dget(REISERFS_SB(sb)->priv_root);
  60. struct dentry *xaroot;
  61. /* This needs to be created at mount-time */
  62. if (!privroot)
  63. return ERR_PTR(-ENODATA);
  64. mutex_lock_nested(&privroot->d_inode->i_mutex, I_MUTEX_XATTR);
  65. if (REISERFS_SB(sb)->xattr_root) {
  66. xaroot = dget(REISERFS_SB(sb)->xattr_root);
  67. goto out;
  68. }
  69. xaroot = lookup_one_len(XAROOT_NAME, privroot, strlen(XAROOT_NAME));
  70. if (IS_ERR(xaroot)) {
  71. goto out;
  72. } else if (!xaroot->d_inode) {
  73. int err = -ENODATA;
  74. if (flags == 0 || flags & XATTR_CREATE)
  75. err = privroot->d_inode->i_op->mkdir(privroot->d_inode,
  76. xaroot, 0700);
  77. if (err) {
  78. dput(xaroot);
  79. xaroot = ERR_PTR(err);
  80. goto out;
  81. }
  82. }
  83. REISERFS_SB(sb)->xattr_root = dget(xaroot);
  84. out:
  85. mutex_unlock(&privroot->d_inode->i_mutex);
  86. dput(privroot);
  87. return xaroot;
  88. }
  89. /* Opens the directory corresponding to the inode's extended attribute store.
  90. * If flags allow, the tree to the directory may be created. If creation is
  91. * prohibited, -ENODATA is returned. */
  92. static struct dentry *open_xa_dir(const struct inode *inode, int flags)
  93. {
  94. struct dentry *xaroot, *xadir;
  95. char namebuf[17];
  96. xaroot = get_xa_root(inode->i_sb, flags);
  97. if (IS_ERR(xaroot))
  98. return xaroot;
  99. /* ok, we have xaroot open */
  100. snprintf(namebuf, sizeof(namebuf), "%X.%X",
  101. le32_to_cpu(INODE_PKEY(inode)->k_objectid),
  102. inode->i_generation);
  103. xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
  104. if (IS_ERR(xadir)) {
  105. dput(xaroot);
  106. return xadir;
  107. }
  108. if (!xadir->d_inode) {
  109. int err;
  110. if (flags == 0 || flags & XATTR_CREATE) {
  111. /* Although there is nothing else trying to create this directory,
  112. * another directory with the same hash may be created, so we need
  113. * to protect against that */
  114. err =
  115. xaroot->d_inode->i_op->mkdir(xaroot->d_inode, xadir,
  116. 0700);
  117. if (err) {
  118. dput(xaroot);
  119. dput(xadir);
  120. return ERR_PTR(err);
  121. }
  122. }
  123. if (!xadir->d_inode) {
  124. dput(xaroot);
  125. dput(xadir);
  126. return ERR_PTR(-ENODATA);
  127. }
  128. }
  129. dput(xaroot);
  130. return xadir;
  131. }
  132. /* Returns a dentry corresponding to a specific extended attribute file
  133. * for the inode. If flags allow, the file is created. Otherwise, a
  134. * valid or negative dentry, or an error is returned. */
  135. static struct dentry *get_xa_file_dentry(const struct inode *inode,
  136. const char *name, int flags)
  137. {
  138. struct dentry *xadir, *xafile;
  139. int err = 0;
  140. xadir = open_xa_dir(inode, flags);
  141. if (IS_ERR(xadir)) {
  142. return ERR_PTR(PTR_ERR(xadir));
  143. } else if (xadir && !xadir->d_inode) {
  144. dput(xadir);
  145. return ERR_PTR(-ENODATA);
  146. }
  147. xafile = lookup_one_len(name, xadir, strlen(name));
  148. if (IS_ERR(xafile)) {
  149. dput(xadir);
  150. return ERR_PTR(PTR_ERR(xafile));
  151. }
  152. if (xafile->d_inode) { /* file exists */
  153. if (flags & XATTR_CREATE) {
  154. err = -EEXIST;
  155. dput(xafile);
  156. goto out;
  157. }
  158. } else if (flags & XATTR_REPLACE || flags & FL_READONLY) {
  159. goto out;
  160. } else {
  161. /* inode->i_mutex is down, so nothing else can try to create
  162. * the same xattr */
  163. err = xadir->d_inode->i_op->create(xadir->d_inode, xafile,
  164. 0700 | S_IFREG, NULL);
  165. if (err) {
  166. dput(xafile);
  167. goto out;
  168. }
  169. }
  170. out:
  171. dput(xadir);
  172. if (err)
  173. xafile = ERR_PTR(err);
  174. return xafile;
  175. }
  176. /* Opens a file pointer to the attribute associated with inode */
  177. static struct file *open_xa_file(const struct inode *inode, const char *name,
  178. int flags)
  179. {
  180. struct dentry *xafile;
  181. struct file *fp;
  182. xafile = get_xa_file_dentry(inode, name, flags);
  183. if (IS_ERR(xafile))
  184. return ERR_PTR(PTR_ERR(xafile));
  185. else if (!xafile->d_inode) {
  186. dput(xafile);
  187. return ERR_PTR(-ENODATA);
  188. }
  189. fp = dentry_open(xafile, NULL, O_RDWR);
  190. /* dentry_open dputs the dentry if it fails */
  191. return fp;
  192. }
  193. /*
  194. * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but
  195. * we need to drop the path before calling the filldir struct. That
  196. * would be a big performance hit to the non-xattr case, so I've copied
  197. * the whole thing for now. --clm
  198. *
  199. * the big difference is that I go backwards through the directory,
  200. * and don't mess with f->f_pos, but the idea is the same. Do some
  201. * action on each and every entry in the directory.
  202. *
  203. * we're called with i_mutex held, so there are no worries about the directory
  204. * changing underneath us.
  205. */
  206. static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
  207. {
  208. struct inode *inode = filp->f_path.dentry->d_inode;
  209. struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
  210. INITIALIZE_PATH(path_to_entry);
  211. struct buffer_head *bh;
  212. int entry_num;
  213. struct item_head *ih, tmp_ih;
  214. int search_res;
  215. char *local_buf;
  216. loff_t next_pos;
  217. char small_buf[32]; /* avoid kmalloc if we can */
  218. struct reiserfs_de_head *deh;
  219. int d_reclen;
  220. char *d_name;
  221. off_t d_off;
  222. ino_t d_ino;
  223. struct reiserfs_dir_entry de;
  224. /* form key for search the next directory entry using f_pos field of
  225. file structure */
  226. next_pos = max_reiserfs_offset(inode);
  227. while (1) {
  228. research:
  229. if (next_pos <= DOT_DOT_OFFSET)
  230. break;
  231. make_cpu_key(&pos_key, inode, next_pos, TYPE_DIRENTRY, 3);
  232. search_res =
  233. search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
  234. &de);
  235. if (search_res == IO_ERROR) {
  236. // FIXME: we could just skip part of directory which could
  237. // not be read
  238. pathrelse(&path_to_entry);
  239. return -EIO;
  240. }
  241. if (search_res == NAME_NOT_FOUND)
  242. de.de_entry_num--;
  243. set_de_name_and_namelen(&de);
  244. entry_num = de.de_entry_num;
  245. deh = &(de.de_deh[entry_num]);
  246. bh = de.de_bh;
  247. ih = de.de_ih;
  248. if (!is_direntry_le_ih(ih)) {
  249. reiserfs_warning(inode->i_sb, "not direntry %h", ih);
  250. break;
  251. }
  252. copy_item_head(&tmp_ih, ih);
  253. /* we must have found item, that is item of this directory, */
  254. RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key),
  255. "vs-9000: found item %h does not match to dir we readdir %K",
  256. ih, &pos_key);
  257. if (deh_offset(deh) <= DOT_DOT_OFFSET) {
  258. break;
  259. }
  260. /* look for the previous entry in the directory */
  261. next_pos = deh_offset(deh) - 1;
  262. if (!de_visible(deh))
  263. /* it is hidden entry */
  264. continue;
  265. d_reclen = entry_length(bh, ih, entry_num);
  266. d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh);
  267. d_off = deh_offset(deh);
  268. d_ino = deh_objectid(deh);
  269. if (!d_name[d_reclen - 1])
  270. d_reclen = strlen(d_name);
  271. if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)) {
  272. /* too big to send back to VFS */
  273. continue;
  274. }
  275. /* Ignore the .reiserfs_priv entry */
  276. if (reiserfs_xattrs(inode->i_sb) &&
  277. !old_format_only(inode->i_sb) &&
  278. deh_objectid(deh) ==
  279. le32_to_cpu(INODE_PKEY
  280. (REISERFS_SB(inode->i_sb)->priv_root->d_inode)->
  281. k_objectid))
  282. continue;
  283. if (d_reclen <= 32) {
  284. local_buf = small_buf;
  285. } else {
  286. local_buf = kmalloc(d_reclen, GFP_NOFS);
  287. if (!local_buf) {
  288. pathrelse(&path_to_entry);
  289. return -ENOMEM;
  290. }
  291. if (item_moved(&tmp_ih, &path_to_entry)) {
  292. kfree(local_buf);
  293. /* sigh, must retry. Do this same offset again */
  294. next_pos = d_off;
  295. goto research;
  296. }
  297. }
  298. // Note, that we copy name to user space via temporary
  299. // buffer (local_buf) because filldir will block if
  300. // user space buffer is swapped out. At that time
  301. // entry can move to somewhere else
  302. memcpy(local_buf, d_name, d_reclen);
  303. /* the filldir function might need to start transactions,
  304. * or do who knows what. Release the path now that we've
  305. * copied all the important stuff out of the deh
  306. */
  307. pathrelse(&path_to_entry);
  308. if (filldir(dirent, local_buf, d_reclen, d_off, d_ino,
  309. DT_UNKNOWN) < 0) {
  310. if (local_buf != small_buf) {
  311. kfree(local_buf);
  312. }
  313. goto end;
  314. }
  315. if (local_buf != small_buf) {
  316. kfree(local_buf);
  317. }
  318. } /* while */
  319. end:
  320. pathrelse(&path_to_entry);
  321. return 0;
  322. }
  323. /*
  324. * this could be done with dedicated readdir ops for the xattr files,
  325. * but I want to get something working asap
  326. * this is stolen from vfs_readdir
  327. *
  328. */
  329. static
  330. int xattr_readdir(struct file *file, filldir_t filler, void *buf)
  331. {
  332. struct inode *inode = file->f_path.dentry->d_inode;
  333. int res = -ENOTDIR;
  334. if (!file->f_op || !file->f_op->readdir)
  335. goto out;
  336. mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR);
  337. // down(&inode->i_zombie);
  338. res = -ENOENT;
  339. if (!IS_DEADDIR(inode)) {
  340. lock_kernel();
  341. res = __xattr_readdir(file, buf, filler);
  342. unlock_kernel();
  343. }
  344. // up(&inode->i_zombie);
  345. mutex_unlock(&inode->i_mutex);
  346. out:
  347. return res;
  348. }
  349. /* Internal operations on file data */
  350. static inline void reiserfs_put_page(struct page *page)
  351. {
  352. kunmap(page);
  353. page_cache_release(page);
  354. }
  355. static struct page *reiserfs_get_page(struct inode *dir, unsigned long n)
  356. {
  357. struct address_space *mapping = dir->i_mapping;
  358. struct page *page;
  359. /* We can deadlock if we try to free dentries,
  360. and an unlink/rmdir has just occured - GFP_NOFS avoids this */
  361. mapping_set_gfp_mask(mapping, GFP_NOFS);
  362. page = read_mapping_page(mapping, n, NULL);
  363. if (!IS_ERR(page)) {
  364. wait_on_page_locked(page);
  365. kmap(page);
  366. if (!PageUptodate(page))
  367. goto fail;
  368. if (PageError(page))
  369. goto fail;
  370. }
  371. return page;
  372. fail:
  373. reiserfs_put_page(page);
  374. return ERR_PTR(-EIO);
  375. }
  376. static inline __u32 xattr_hash(const char *msg, int len)
  377. {
  378. return csum_partial(msg, len, 0);
  379. }
  380. /* Generic extended attribute operations that can be used by xa plugins */
  381. /*
  382. * inode->i_mutex: down
  383. */
  384. int
  385. reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
  386. size_t buffer_size, int flags)
  387. {
  388. int err = 0;
  389. struct file *fp;
  390. struct page *page;
  391. char *data;
  392. struct address_space *mapping;
  393. size_t file_pos = 0;
  394. size_t buffer_pos = 0;
  395. struct inode *xinode;
  396. struct iattr newattrs;
  397. __u32 xahash = 0;
  398. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  399. return -EOPNOTSUPP;
  400. /* Empty xattrs are ok, they're just empty files, no hash */
  401. if (buffer && buffer_size)
  402. xahash = xattr_hash(buffer, buffer_size);
  403. open_file:
  404. fp = open_xa_file(inode, name, flags);
  405. if (IS_ERR(fp)) {
  406. err = PTR_ERR(fp);
  407. goto out;
  408. }
  409. xinode = fp->f_path.dentry->d_inode;
  410. REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
  411. /* we need to copy it off.. */
  412. if (xinode->i_nlink > 1) {
  413. fput(fp);
  414. err = reiserfs_xattr_del(inode, name);
  415. if (err < 0)
  416. goto out;
  417. /* We just killed the old one, we're not replacing anymore */
  418. if (flags & XATTR_REPLACE)
  419. flags &= ~XATTR_REPLACE;
  420. goto open_file;
  421. }
  422. /* Resize it so we're ok to write there */
  423. newattrs.ia_size = buffer_size;
  424. newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
  425. mutex_lock(&xinode->i_mutex);
  426. err = notify_change(fp->f_path.dentry, &newattrs);
  427. if (err)
  428. goto out_filp;
  429. mapping = xinode->i_mapping;
  430. while (buffer_pos < buffer_size || buffer_pos == 0) {
  431. size_t chunk;
  432. size_t skip = 0;
  433. size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1));
  434. if (buffer_size - buffer_pos > PAGE_CACHE_SIZE)
  435. chunk = PAGE_CACHE_SIZE;
  436. else
  437. chunk = buffer_size - buffer_pos;
  438. page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
  439. if (IS_ERR(page)) {
  440. err = PTR_ERR(page);
  441. goto out_filp;
  442. }
  443. lock_page(page);
  444. data = page_address(page);
  445. if (file_pos == 0) {
  446. struct reiserfs_xattr_header *rxh;
  447. skip = file_pos = sizeof(struct reiserfs_xattr_header);
  448. if (chunk + skip > PAGE_CACHE_SIZE)
  449. chunk = PAGE_CACHE_SIZE - skip;
  450. rxh = (struct reiserfs_xattr_header *)data;
  451. rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC);
  452. rxh->h_hash = cpu_to_le32(xahash);
  453. }
  454. err = mapping->a_ops->prepare_write(fp, page, page_offset,
  455. page_offset + chunk + skip);
  456. if (!err) {
  457. if (buffer)
  458. memcpy(data + skip, buffer + buffer_pos, chunk);
  459. err =
  460. mapping->a_ops->commit_write(fp, page, page_offset,
  461. page_offset + chunk +
  462. skip);
  463. }
  464. unlock_page(page);
  465. reiserfs_put_page(page);
  466. buffer_pos += chunk;
  467. file_pos += chunk;
  468. skip = 0;
  469. if (err || buffer_size == 0 || !buffer)
  470. break;
  471. }
  472. /* We can't mark the inode dirty if it's not hashed. This is the case
  473. * when we're inheriting the default ACL. If we dirty it, the inode
  474. * gets marked dirty, but won't (ever) make it onto the dirty list until
  475. * it's synced explicitly to clear I_DIRTY. This is bad. */
  476. if (!hlist_unhashed(&inode->i_hash)) {
  477. inode->i_ctime = CURRENT_TIME_SEC;
  478. mark_inode_dirty(inode);
  479. }
  480. out_filp:
  481. mutex_unlock(&xinode->i_mutex);
  482. fput(fp);
  483. out:
  484. return err;
  485. }
  486. /*
  487. * inode->i_mutex: down
  488. */
  489. int
  490. reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
  491. size_t buffer_size)
  492. {
  493. ssize_t err = 0;
  494. struct file *fp;
  495. size_t isize;
  496. size_t file_pos = 0;
  497. size_t buffer_pos = 0;
  498. struct page *page;
  499. struct inode *xinode;
  500. __u32 hash = 0;
  501. if (name == NULL)
  502. return -EINVAL;
  503. /* We can't have xattrs attached to v1 items since they don't have
  504. * generation numbers */
  505. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  506. return -EOPNOTSUPP;
  507. fp = open_xa_file(inode, name, FL_READONLY);
  508. if (IS_ERR(fp)) {
  509. err = PTR_ERR(fp);
  510. goto out;
  511. }
  512. xinode = fp->f_path.dentry->d_inode;
  513. isize = xinode->i_size;
  514. REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
  515. /* Just return the size needed */
  516. if (buffer == NULL) {
  517. err = isize - sizeof(struct reiserfs_xattr_header);
  518. goto out_dput;
  519. }
  520. if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
  521. err = -ERANGE;
  522. goto out_dput;
  523. }
  524. while (file_pos < isize) {
  525. size_t chunk;
  526. char *data;
  527. size_t skip = 0;
  528. if (isize - file_pos > PAGE_CACHE_SIZE)
  529. chunk = PAGE_CACHE_SIZE;
  530. else
  531. chunk = isize - file_pos;
  532. page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
  533. if (IS_ERR(page)) {
  534. err = PTR_ERR(page);
  535. goto out_dput;
  536. }
  537. lock_page(page);
  538. data = page_address(page);
  539. if (file_pos == 0) {
  540. struct reiserfs_xattr_header *rxh =
  541. (struct reiserfs_xattr_header *)data;
  542. skip = file_pos = sizeof(struct reiserfs_xattr_header);
  543. chunk -= skip;
  544. /* Magic doesn't match up.. */
  545. if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
  546. unlock_page(page);
  547. reiserfs_put_page(page);
  548. reiserfs_warning(inode->i_sb,
  549. "Invalid magic for xattr (%s) "
  550. "associated with %k", name,
  551. INODE_PKEY(inode));
  552. err = -EIO;
  553. goto out_dput;
  554. }
  555. hash = le32_to_cpu(rxh->h_hash);
  556. }
  557. memcpy(buffer + buffer_pos, data + skip, chunk);
  558. unlock_page(page);
  559. reiserfs_put_page(page);
  560. file_pos += chunk;
  561. buffer_pos += chunk;
  562. skip = 0;
  563. }
  564. err = isize - sizeof(struct reiserfs_xattr_header);
  565. if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
  566. hash) {
  567. reiserfs_warning(inode->i_sb,
  568. "Invalid hash for xattr (%s) associated "
  569. "with %k", name, INODE_PKEY(inode));
  570. err = -EIO;
  571. }
  572. out_dput:
  573. fput(fp);
  574. out:
  575. return err;
  576. }
  577. static int
  578. __reiserfs_xattr_del(struct dentry *xadir, const char *name, int namelen)
  579. {
  580. struct dentry *dentry;
  581. struct inode *dir = xadir->d_inode;
  582. int err = 0;
  583. dentry = lookup_one_len(name, xadir, namelen);
  584. if (IS_ERR(dentry)) {
  585. err = PTR_ERR(dentry);
  586. goto out;
  587. } else if (!dentry->d_inode) {
  588. err = -ENODATA;
  589. goto out_file;
  590. }
  591. /* Skip directories.. */
  592. if (S_ISDIR(dentry->d_inode->i_mode))
  593. goto out_file;
  594. if (!is_reiserfs_priv_object(dentry->d_inode)) {
  595. reiserfs_warning(dir->i_sb, "OID %08x [%.*s/%.*s] doesn't have "
  596. "priv flag set [parent is %sset].",
  597. le32_to_cpu(INODE_PKEY(dentry->d_inode)->
  598. k_objectid), xadir->d_name.len,
  599. xadir->d_name.name, namelen, name,
  600. is_reiserfs_priv_object(xadir->
  601. d_inode) ? "" :
  602. "not ");
  603. dput(dentry);
  604. return -EIO;
  605. }
  606. err = dir->i_op->unlink(dir, dentry);
  607. if (!err)
  608. d_delete(dentry);
  609. out_file:
  610. dput(dentry);
  611. out:
  612. return err;
  613. }
  614. int reiserfs_xattr_del(struct inode *inode, const char *name)
  615. {
  616. struct dentry *dir;
  617. int err;
  618. dir = open_xa_dir(inode, FL_READONLY);
  619. if (IS_ERR(dir)) {
  620. err = PTR_ERR(dir);
  621. goto out;
  622. }
  623. err = __reiserfs_xattr_del(dir, name, strlen(name));
  624. dput(dir);
  625. if (!err) {
  626. inode->i_ctime = CURRENT_TIME_SEC;
  627. mark_inode_dirty(inode);
  628. }
  629. out:
  630. return err;
  631. }
  632. /* The following are side effects of other operations that aren't explicitly
  633. * modifying extended attributes. This includes operations such as permissions
  634. * or ownership changes, object deletions, etc. */
  635. static int
  636. reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
  637. loff_t offset, u64 ino, unsigned int d_type)
  638. {
  639. struct dentry *xadir = (struct dentry *)buf;
  640. return __reiserfs_xattr_del(xadir, name, namelen);
  641. }
  642. /* This is called w/ inode->i_mutex downed */
  643. int reiserfs_delete_xattrs(struct inode *inode)
  644. {
  645. struct file *fp;
  646. struct dentry *dir, *root;
  647. int err = 0;
  648. /* Skip out, an xattr has no xattrs associated with it */
  649. if (is_reiserfs_priv_object(inode) ||
  650. get_inode_sd_version(inode) == STAT_DATA_V1 ||
  651. !reiserfs_xattrs(inode->i_sb)) {
  652. return 0;
  653. }
  654. reiserfs_read_lock_xattrs(inode->i_sb);
  655. dir = open_xa_dir(inode, FL_READONLY);
  656. reiserfs_read_unlock_xattrs(inode->i_sb);
  657. if (IS_ERR(dir)) {
  658. err = PTR_ERR(dir);
  659. goto out;
  660. } else if (!dir->d_inode) {
  661. dput(dir);
  662. return 0;
  663. }
  664. fp = dentry_open(dir, NULL, O_RDWR);
  665. if (IS_ERR(fp)) {
  666. err = PTR_ERR(fp);
  667. /* dentry_open dputs the dentry if it fails */
  668. goto out;
  669. }
  670. lock_kernel();
  671. err = xattr_readdir(fp, reiserfs_delete_xattrs_filler, dir);
  672. if (err) {
  673. unlock_kernel();
  674. goto out_dir;
  675. }
  676. /* Leftovers besides . and .. -- that's not good. */
  677. if (dir->d_inode->i_nlink <= 2) {
  678. root = get_xa_root(inode->i_sb, XATTR_REPLACE);
  679. reiserfs_write_lock_xattrs(inode->i_sb);
  680. err = vfs_rmdir(root->d_inode, dir);
  681. reiserfs_write_unlock_xattrs(inode->i_sb);
  682. dput(root);
  683. } else {
  684. reiserfs_warning(inode->i_sb,
  685. "Couldn't remove all entries in directory");
  686. }
  687. unlock_kernel();
  688. out_dir:
  689. fput(fp);
  690. out:
  691. if (!err)
  692. REISERFS_I(inode)->i_flags =
  693. REISERFS_I(inode)->i_flags & ~i_has_xattr_dir;
  694. return err;
  695. }
  696. struct reiserfs_chown_buf {
  697. struct inode *inode;
  698. struct dentry *xadir;
  699. struct iattr *attrs;
  700. };
  701. /* XXX: If there is a better way to do this, I'd love to hear about it */
  702. static int
  703. reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen,
  704. loff_t offset, u64 ino, unsigned int d_type)
  705. {
  706. struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf;
  707. struct dentry *xafile, *xadir = chown_buf->xadir;
  708. struct iattr *attrs = chown_buf->attrs;
  709. int err = 0;
  710. xafile = lookup_one_len(name, xadir, namelen);
  711. if (IS_ERR(xafile))
  712. return PTR_ERR(xafile);
  713. else if (!xafile->d_inode) {
  714. dput(xafile);
  715. return -ENODATA;
  716. }
  717. if (!S_ISDIR(xafile->d_inode->i_mode))
  718. err = notify_change(xafile, attrs);
  719. dput(xafile);
  720. return err;
  721. }
  722. int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
  723. {
  724. struct file *fp;
  725. struct dentry *dir;
  726. int err = 0;
  727. struct reiserfs_chown_buf buf;
  728. unsigned int ia_valid = attrs->ia_valid;
  729. /* Skip out, an xattr has no xattrs associated with it */
  730. if (is_reiserfs_priv_object(inode) ||
  731. get_inode_sd_version(inode) == STAT_DATA_V1 ||
  732. !reiserfs_xattrs(inode->i_sb)) {
  733. return 0;
  734. }
  735. reiserfs_read_lock_xattrs(inode->i_sb);
  736. dir = open_xa_dir(inode, FL_READONLY);
  737. reiserfs_read_unlock_xattrs(inode->i_sb);
  738. if (IS_ERR(dir)) {
  739. if (PTR_ERR(dir) != -ENODATA)
  740. err = PTR_ERR(dir);
  741. goto out;
  742. } else if (!dir->d_inode) {
  743. dput(dir);
  744. goto out;
  745. }
  746. fp = dentry_open(dir, NULL, O_RDWR);
  747. if (IS_ERR(fp)) {
  748. err = PTR_ERR(fp);
  749. /* dentry_open dputs the dentry if it fails */
  750. goto out;
  751. }
  752. lock_kernel();
  753. attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME);
  754. buf.xadir = dir;
  755. buf.attrs = attrs;
  756. buf.inode = inode;
  757. err = xattr_readdir(fp, reiserfs_chown_xattrs_filler, &buf);
  758. if (err) {
  759. unlock_kernel();
  760. goto out_dir;
  761. }
  762. err = notify_change(dir, attrs);
  763. unlock_kernel();
  764. out_dir:
  765. fput(fp);
  766. out:
  767. attrs->ia_valid = ia_valid;
  768. return err;
  769. }
  770. /* Actual operations that are exported to VFS-land */
  771. /*
  772. * Inode operation getxattr()
  773. * Preliminary locking: we down dentry->d_inode->i_mutex
  774. */
  775. ssize_t
  776. reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
  777. size_t size)
  778. {
  779. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  780. int err;
  781. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  782. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  783. return -EOPNOTSUPP;
  784. reiserfs_read_lock_xattr_i(dentry->d_inode);
  785. reiserfs_read_lock_xattrs(dentry->d_sb);
  786. err = xah->get(dentry->d_inode, name, buffer, size);
  787. reiserfs_read_unlock_xattrs(dentry->d_sb);
  788. reiserfs_read_unlock_xattr_i(dentry->d_inode);
  789. return err;
  790. }
  791. /*
  792. * Inode operation setxattr()
  793. *
  794. * dentry->d_inode->i_mutex down
  795. */
  796. int
  797. reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  798. size_t size, int flags)
  799. {
  800. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  801. int err;
  802. int lock;
  803. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  804. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  805. return -EOPNOTSUPP;
  806. reiserfs_write_lock_xattr_i(dentry->d_inode);
  807. lock = !has_xattr_dir(dentry->d_inode);
  808. if (lock)
  809. reiserfs_write_lock_xattrs(dentry->d_sb);
  810. else
  811. reiserfs_read_lock_xattrs(dentry->d_sb);
  812. err = xah->set(dentry->d_inode, name, value, size, flags);
  813. if (lock)
  814. reiserfs_write_unlock_xattrs(dentry->d_sb);
  815. else
  816. reiserfs_read_unlock_xattrs(dentry->d_sb);
  817. reiserfs_write_unlock_xattr_i(dentry->d_inode);
  818. return err;
  819. }
  820. /*
  821. * Inode operation removexattr()
  822. *
  823. * dentry->d_inode->i_mutex down
  824. */
  825. int reiserfs_removexattr(struct dentry *dentry, const char *name)
  826. {
  827. int err;
  828. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  829. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  830. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  831. return -EOPNOTSUPP;
  832. reiserfs_write_lock_xattr_i(dentry->d_inode);
  833. reiserfs_read_lock_xattrs(dentry->d_sb);
  834. /* Deletion pre-operation */
  835. if (xah->del) {
  836. err = xah->del(dentry->d_inode, name);
  837. if (err)
  838. goto out;
  839. }
  840. err = reiserfs_xattr_del(dentry->d_inode, name);
  841. dentry->d_inode->i_ctime = CURRENT_TIME_SEC;
  842. mark_inode_dirty(dentry->d_inode);
  843. out:
  844. reiserfs_read_unlock_xattrs(dentry->d_sb);
  845. reiserfs_write_unlock_xattr_i(dentry->d_inode);
  846. return err;
  847. }
  848. /* This is what filldir will use:
  849. * r_pos will always contain the amount of space required for the entire
  850. * list. If r_pos becomes larger than r_size, we need more space and we
  851. * return an error indicating this. If r_pos is less than r_size, then we've
  852. * filled the buffer successfully and we return success */
  853. struct reiserfs_listxattr_buf {
  854. int r_pos;
  855. int r_size;
  856. char *r_buf;
  857. struct inode *r_inode;
  858. };
  859. static int
  860. reiserfs_listxattr_filler(void *buf, const char *name, int namelen,
  861. loff_t offset, u64 ino, unsigned int d_type)
  862. {
  863. struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf;
  864. int len = 0;
  865. if (name[0] != '.'
  866. || (namelen != 1 && (name[1] != '.' || namelen != 2))) {
  867. struct reiserfs_xattr_handler *xah =
  868. find_xattr_handler_prefix(name);
  869. if (!xah)
  870. return 0; /* Unsupported xattr name, skip it */
  871. /* We call ->list() twice because the operation isn't required to just
  872. * return the name back - we want to make sure we have enough space */
  873. len += xah->list(b->r_inode, name, namelen, NULL);
  874. if (len) {
  875. if (b->r_pos + len + 1 <= b->r_size) {
  876. char *p = b->r_buf + b->r_pos;
  877. p += xah->list(b->r_inode, name, namelen, p);
  878. *p++ = '\0';
  879. }
  880. b->r_pos += len + 1;
  881. }
  882. }
  883. return 0;
  884. }
  885. /*
  886. * Inode operation listxattr()
  887. *
  888. * Preliminary locking: we down dentry->d_inode->i_mutex
  889. */
  890. ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
  891. {
  892. struct file *fp;
  893. struct dentry *dir;
  894. int err = 0;
  895. struct reiserfs_listxattr_buf buf;
  896. if (!dentry->d_inode)
  897. return -EINVAL;
  898. if (!reiserfs_xattrs(dentry->d_sb) ||
  899. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  900. return -EOPNOTSUPP;
  901. reiserfs_read_lock_xattr_i(dentry->d_inode);
  902. reiserfs_read_lock_xattrs(dentry->d_sb);
  903. dir = open_xa_dir(dentry->d_inode, FL_READONLY);
  904. reiserfs_read_unlock_xattrs(dentry->d_sb);
  905. if (IS_ERR(dir)) {
  906. err = PTR_ERR(dir);
  907. if (err == -ENODATA)
  908. err = 0; /* Not an error if there aren't any xattrs */
  909. goto out;
  910. }
  911. fp = dentry_open(dir, NULL, O_RDWR);
  912. if (IS_ERR(fp)) {
  913. err = PTR_ERR(fp);
  914. /* dentry_open dputs the dentry if it fails */
  915. goto out;
  916. }
  917. buf.r_buf = buffer;
  918. buf.r_size = buffer ? size : 0;
  919. buf.r_pos = 0;
  920. buf.r_inode = dentry->d_inode;
  921. REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir;
  922. err = xattr_readdir(fp, reiserfs_listxattr_filler, &buf);
  923. if (err)
  924. goto out_dir;
  925. if (buf.r_pos > buf.r_size && buffer != NULL)
  926. err = -ERANGE;
  927. else
  928. err = buf.r_pos;
  929. out_dir:
  930. fput(fp);
  931. out:
  932. reiserfs_read_unlock_xattr_i(dentry->d_inode);
  933. return err;
  934. }
  935. /* This is the implementation for the xattr plugin infrastructure */
  936. static struct list_head xattr_handlers = LIST_HEAD_INIT(xattr_handlers);
  937. static DEFINE_RWLOCK(handler_lock);
  938. static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
  939. *prefix)
  940. {
  941. struct reiserfs_xattr_handler *xah = NULL;
  942. struct list_head *p;
  943. read_lock(&handler_lock);
  944. list_for_each(p, &xattr_handlers) {
  945. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  946. if (strncmp(xah->prefix, prefix, strlen(xah->prefix)) == 0)
  947. break;
  948. xah = NULL;
  949. }
  950. read_unlock(&handler_lock);
  951. return xah;
  952. }
  953. static void __unregister_handlers(void)
  954. {
  955. struct reiserfs_xattr_handler *xah;
  956. struct list_head *p, *tmp;
  957. list_for_each_safe(p, tmp, &xattr_handlers) {
  958. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  959. if (xah->exit)
  960. xah->exit();
  961. list_del_init(p);
  962. }
  963. INIT_LIST_HEAD(&xattr_handlers);
  964. }
  965. int __init reiserfs_xattr_register_handlers(void)
  966. {
  967. int err = 0;
  968. struct reiserfs_xattr_handler *xah;
  969. struct list_head *p;
  970. write_lock(&handler_lock);
  971. /* If we're already initialized, nothing to do */
  972. if (!list_empty(&xattr_handlers)) {
  973. write_unlock(&handler_lock);
  974. return 0;
  975. }
  976. /* Add the handlers */
  977. list_add_tail(&user_handler.handlers, &xattr_handlers);
  978. list_add_tail(&trusted_handler.handlers, &xattr_handlers);
  979. #ifdef CONFIG_REISERFS_FS_SECURITY
  980. list_add_tail(&security_handler.handlers, &xattr_handlers);
  981. #endif
  982. #ifdef CONFIG_REISERFS_FS_POSIX_ACL
  983. list_add_tail(&posix_acl_access_handler.handlers, &xattr_handlers);
  984. list_add_tail(&posix_acl_default_handler.handlers, &xattr_handlers);
  985. #endif
  986. /* Run initializers, if available */
  987. list_for_each(p, &xattr_handlers) {
  988. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  989. if (xah->init) {
  990. err = xah->init();
  991. if (err) {
  992. list_del_init(p);
  993. break;
  994. }
  995. }
  996. }
  997. /* Clean up other handlers, if any failed */
  998. if (err)
  999. __unregister_handlers();
  1000. write_unlock(&handler_lock);
  1001. return err;
  1002. }
  1003. void reiserfs_xattr_unregister_handlers(void)
  1004. {
  1005. write_lock(&handler_lock);
  1006. __unregister_handlers();
  1007. write_unlock(&handler_lock);
  1008. }
  1009. /* This will catch lookups from the fs root to .reiserfs_priv */
  1010. static int
  1011. xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name)
  1012. {
  1013. struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root;
  1014. if (name->len == priv_root->d_name.len &&
  1015. name->hash == priv_root->d_name.hash &&
  1016. !memcmp(name->name, priv_root->d_name.name, name->len)) {
  1017. return -ENOENT;
  1018. } else if (q1->len == name->len &&
  1019. !memcmp(q1->name, name->name, name->len))
  1020. return 0;
  1021. return 1;
  1022. }
  1023. static struct dentry_operations xattr_lookup_poison_ops = {
  1024. .d_compare = xattr_lookup_poison,
  1025. };
  1026. /* We need to take a copy of the mount flags since things like
  1027. * MS_RDONLY don't get set until *after* we're called.
  1028. * mount_flags != mount_options */
  1029. int reiserfs_xattr_init(struct super_block *s, int mount_flags)
  1030. {
  1031. int err = 0;
  1032. /* We need generation numbers to ensure that the oid mapping is correct
  1033. * v3.5 filesystems don't have them. */
  1034. if (!old_format_only(s)) {
  1035. set_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1036. } else if (reiserfs_xattrs_optional(s)) {
  1037. /* Old format filesystem, but optional xattrs have been enabled
  1038. * at mount time. Error out. */
  1039. reiserfs_warning(s, "xattrs/ACLs not supported on pre v3.6 "
  1040. "format filesystem. Failing mount.");
  1041. err = -EOPNOTSUPP;
  1042. goto error;
  1043. } else {
  1044. /* Old format filesystem, but no optional xattrs have been enabled. This
  1045. * means we silently disable xattrs on the filesystem. */
  1046. clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1047. }
  1048. /* If we don't have the privroot located yet - go find it */
  1049. if (reiserfs_xattrs(s) && !REISERFS_SB(s)->priv_root) {
  1050. struct dentry *dentry;
  1051. dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
  1052. strlen(PRIVROOT_NAME));
  1053. if (!IS_ERR(dentry)) {
  1054. if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) {
  1055. struct inode *inode = dentry->d_parent->d_inode;
  1056. mutex_lock(&inode->i_mutex);
  1057. err = inode->i_op->mkdir(inode, dentry, 0700);
  1058. mutex_unlock(&inode->i_mutex);
  1059. if (err) {
  1060. dput(dentry);
  1061. dentry = NULL;
  1062. }
  1063. if (dentry && dentry->d_inode)
  1064. reiserfs_warning(s,
  1065. "Created %s on %s - reserved for "
  1066. "xattr storage.",
  1067. PRIVROOT_NAME,
  1068. reiserfs_bdevname
  1069. (inode->i_sb));
  1070. } else if (!dentry->d_inode) {
  1071. dput(dentry);
  1072. dentry = NULL;
  1073. }
  1074. } else
  1075. err = PTR_ERR(dentry);
  1076. if (!err && dentry) {
  1077. s->s_root->d_op = &xattr_lookup_poison_ops;
  1078. reiserfs_mark_inode_private(dentry->d_inode);
  1079. REISERFS_SB(s)->priv_root = dentry;
  1080. } else if (!(mount_flags & MS_RDONLY)) { /* xattrs are unavailable */
  1081. /* If we're read-only it just means that the dir hasn't been
  1082. * created. Not an error -- just no xattrs on the fs. We'll
  1083. * check again if we go read-write */
  1084. reiserfs_warning(s, "xattrs/ACLs enabled and couldn't "
  1085. "find/create .reiserfs_priv. Failing mount.");
  1086. err = -EOPNOTSUPP;
  1087. }
  1088. }
  1089. error:
  1090. /* This is only nonzero if there was an error initializing the xattr
  1091. * directory or if there is a condition where we don't support them. */
  1092. if (err) {
  1093. clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1094. clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt));
  1095. clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt));
  1096. }
  1097. /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */
  1098. s->s_flags = s->s_flags & ~MS_POSIXACL;
  1099. if (reiserfs_posixacl(s))
  1100. s->s_flags |= MS_POSIXACL;
  1101. return err;
  1102. }
  1103. static int reiserfs_check_acl(struct inode *inode, int mask)
  1104. {
  1105. struct posix_acl *acl;
  1106. int error = -EAGAIN; /* do regular unix permission checks by default */
  1107. reiserfs_read_lock_xattr_i(inode);
  1108. reiserfs_read_lock_xattrs(inode->i_sb);
  1109. acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
  1110. reiserfs_read_unlock_xattrs(inode->i_sb);
  1111. reiserfs_read_unlock_xattr_i(inode);
  1112. if (acl) {
  1113. if (!IS_ERR(acl)) {
  1114. error = posix_acl_permission(inode, acl, mask);
  1115. posix_acl_release(acl);
  1116. } else if (PTR_ERR(acl) != -ENODATA)
  1117. error = PTR_ERR(acl);
  1118. }
  1119. return error;
  1120. }
  1121. int reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd)
  1122. {
  1123. /*
  1124. * We don't do permission checks on the internal objects.
  1125. * Permissions are determined by the "owning" object.
  1126. */
  1127. if (is_reiserfs_priv_object(inode))
  1128. return 0;
  1129. /*
  1130. * Stat data v1 doesn't support ACLs.
  1131. */
  1132. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  1133. return generic_permission(inode, mask, NULL);
  1134. else
  1135. return generic_permission(inode, mask, reiserfs_check_acl);
  1136. }