inode.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122
  1. /*
  2. * inode.c
  3. *
  4. * PURPOSE
  5. * Inode handling routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * COPYRIGHT
  8. * This file is distributed under the terms of the GNU General Public
  9. * License (GPL). Copies of the GPL can be obtained from:
  10. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  11. * Each contributing author retains all rights to their own work.
  12. *
  13. * (C) 1998 Dave Boynton
  14. * (C) 1998-2004 Ben Fennema
  15. * (C) 1999-2000 Stelias Computing Inc
  16. *
  17. * HISTORY
  18. *
  19. * 10/04/98 dgb Added rudimentary directory functions
  20. * 10/07/98 Fully working udf_block_map! It works!
  21. * 11/25/98 bmap altered to better support extents
  22. * 12/06/98 blf partition support in udf_iget, udf_block_map
  23. * and udf_read_inode
  24. * 12/12/98 rewrote udf_block_map to handle next extents and descs across
  25. * block boundaries (which is not actually allowed)
  26. * 12/20/98 added support for strategy 4096
  27. * 03/07/99 rewrote udf_block_map (again)
  28. * New funcs, inode_bmap, udf_next_aext
  29. * 04/19/99 Support for writing device EA's for major/minor #
  30. */
  31. #include "udfdecl.h"
  32. #include <linux/mm.h>
  33. #include <linux/smp_lock.h>
  34. #include <linux/module.h>
  35. #include <linux/pagemap.h>
  36. #include <linux/buffer_head.h>
  37. #include <linux/writeback.h>
  38. #include <linux/slab.h>
  39. #include "udf_i.h"
  40. #include "udf_sb.h"
  41. MODULE_AUTHOR("Ben Fennema");
  42. MODULE_DESCRIPTION("Universal Disk Format Filesystem");
  43. MODULE_LICENSE("GPL");
  44. #define EXTENT_MERGE_SIZE 5
  45. static mode_t udf_convert_permissions(struct fileEntry *);
  46. static int udf_update_inode(struct inode *, int);
  47. static void udf_fill_inode(struct inode *, struct buffer_head *);
  48. static int udf_alloc_i_data(struct inode *inode, size_t size);
  49. static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
  50. long *, int *);
  51. static int8_t udf_insert_aext(struct inode *, struct extent_position,
  52. kernel_lb_addr, uint32_t);
  53. static void udf_split_extents(struct inode *, int *, int, int,
  54. kernel_long_ad[EXTENT_MERGE_SIZE], int *);
  55. static void udf_prealloc_extents(struct inode *, int, int,
  56. kernel_long_ad[EXTENT_MERGE_SIZE], int *);
  57. static void udf_merge_extents(struct inode *,
  58. kernel_long_ad[EXTENT_MERGE_SIZE], int *);
  59. static void udf_update_extents(struct inode *,
  60. kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
  61. struct extent_position *);
  62. static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
  63. /*
  64. * udf_delete_inode
  65. *
  66. * PURPOSE
  67. * Clean-up before the specified inode is destroyed.
  68. *
  69. * DESCRIPTION
  70. * This routine is called when the kernel destroys an inode structure
  71. * ie. when iput() finds i_count == 0.
  72. *
  73. * HISTORY
  74. * July 1, 1997 - Andrew E. Mileski
  75. * Written, tested, and released.
  76. *
  77. * Called at the last iput() if i_nlink is zero.
  78. */
  79. void udf_delete_inode(struct inode *inode)
  80. {
  81. truncate_inode_pages(&inode->i_data, 0);
  82. if (is_bad_inode(inode))
  83. goto no_delete;
  84. inode->i_size = 0;
  85. udf_truncate(inode);
  86. lock_kernel();
  87. udf_update_inode(inode, IS_SYNC(inode));
  88. udf_free_inode(inode);
  89. unlock_kernel();
  90. return;
  91. no_delete:
  92. clear_inode(inode);
  93. }
  94. /*
  95. * If we are going to release inode from memory, we discard preallocation and
  96. * truncate last inode extent to proper length. We could use drop_inode() but
  97. * it's called under inode_lock and thus we cannot mark inode dirty there. We
  98. * use clear_inode() but we have to make sure to write inode as it's not written
  99. * automatically.
  100. */
  101. void udf_clear_inode(struct inode *inode)
  102. {
  103. if (!(inode->i_sb->s_flags & MS_RDONLY)) {
  104. lock_kernel();
  105. /* Discard preallocation for directories, symlinks, etc. */
  106. udf_discard_prealloc(inode);
  107. udf_truncate_tail_extent(inode);
  108. unlock_kernel();
  109. write_inode_now(inode, 1);
  110. }
  111. kfree(UDF_I_DATA(inode));
  112. UDF_I_DATA(inode) = NULL;
  113. }
  114. static int udf_writepage(struct page *page, struct writeback_control *wbc)
  115. {
  116. return block_write_full_page(page, udf_get_block, wbc);
  117. }
  118. static int udf_readpage(struct file *file, struct page *page)
  119. {
  120. return block_read_full_page(page, udf_get_block);
  121. }
  122. static int udf_write_begin(struct file *file, struct address_space *mapping,
  123. loff_t pos, unsigned len, unsigned flags,
  124. struct page **pagep, void **fsdata)
  125. {
  126. *pagep = NULL;
  127. return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  128. udf_get_block);
  129. }
  130. static sector_t udf_bmap(struct address_space *mapping, sector_t block)
  131. {
  132. return generic_block_bmap(mapping, block, udf_get_block);
  133. }
  134. const struct address_space_operations udf_aops = {
  135. .readpage = udf_readpage,
  136. .writepage = udf_writepage,
  137. .sync_page = block_sync_page,
  138. .write_begin = udf_write_begin,
  139. .write_end = generic_write_end,
  140. .bmap = udf_bmap,
  141. };
  142. void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
  143. {
  144. struct page *page;
  145. char *kaddr;
  146. struct writeback_control udf_wbc = {
  147. .sync_mode = WB_SYNC_NONE,
  148. .nr_to_write = 1,
  149. };
  150. /* from now on we have normal address_space methods */
  151. inode->i_data.a_ops = &udf_aops;
  152. if (!UDF_I_LENALLOC(inode)) {
  153. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  154. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
  155. else
  156. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
  157. mark_inode_dirty(inode);
  158. return;
  159. }
  160. page = grab_cache_page(inode->i_mapping, 0);
  161. BUG_ON(!PageLocked(page));
  162. if (!PageUptodate(page)) {
  163. kaddr = kmap(page);
  164. memset(kaddr + UDF_I_LENALLOC(inode), 0x00,
  165. PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
  166. memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
  167. UDF_I_LENALLOC(inode));
  168. flush_dcache_page(page);
  169. SetPageUptodate(page);
  170. kunmap(page);
  171. }
  172. memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
  173. UDF_I_LENALLOC(inode));
  174. UDF_I_LENALLOC(inode) = 0;
  175. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  176. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
  177. else
  178. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
  179. inode->i_data.a_ops->writepage(page, &udf_wbc);
  180. page_cache_release(page);
  181. mark_inode_dirty(inode);
  182. }
  183. struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
  184. int *err)
  185. {
  186. int newblock;
  187. struct buffer_head *dbh = NULL;
  188. kernel_lb_addr eloc;
  189. uint32_t elen;
  190. uint8_t alloctype;
  191. struct extent_position epos;
  192. struct udf_fileident_bh sfibh, dfibh;
  193. loff_t f_pos = udf_ext0_offset(inode) >> 2;
  194. int size = (udf_ext0_offset(inode) + inode->i_size) >> 2;
  195. struct fileIdentDesc cfi, *sfi, *dfi;
  196. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  197. alloctype = ICBTAG_FLAG_AD_SHORT;
  198. else
  199. alloctype = ICBTAG_FLAG_AD_LONG;
  200. if (!inode->i_size) {
  201. UDF_I_ALLOCTYPE(inode) = alloctype;
  202. mark_inode_dirty(inode);
  203. return NULL;
  204. }
  205. /* alloc block, and copy data to it */
  206. *block = udf_new_block(inode->i_sb, inode,
  207. UDF_I_LOCATION(inode).partitionReferenceNum,
  208. UDF_I_LOCATION(inode).logicalBlockNum, err);
  209. if (!(*block))
  210. return NULL;
  211. newblock = udf_get_pblock(inode->i_sb, *block,
  212. UDF_I_LOCATION(inode).partitionReferenceNum,
  213. 0);
  214. if (!newblock)
  215. return NULL;
  216. dbh = udf_tgetblk(inode->i_sb, newblock);
  217. if (!dbh)
  218. return NULL;
  219. lock_buffer(dbh);
  220. memset(dbh->b_data, 0x00, inode->i_sb->s_blocksize);
  221. set_buffer_uptodate(dbh);
  222. unlock_buffer(dbh);
  223. mark_buffer_dirty_inode(dbh, inode);
  224. sfibh.soffset = sfibh.eoffset =
  225. (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
  226. sfibh.sbh = sfibh.ebh = NULL;
  227. dfibh.soffset = dfibh.eoffset = 0;
  228. dfibh.sbh = dfibh.ebh = dbh;
  229. while ((f_pos < size)) {
  230. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
  231. sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL,
  232. NULL, NULL, NULL);
  233. if (!sfi) {
  234. brelse(dbh);
  235. return NULL;
  236. }
  237. UDF_I_ALLOCTYPE(inode) = alloctype;
  238. sfi->descTag.tagLocation = cpu_to_le32(*block);
  239. dfibh.soffset = dfibh.eoffset;
  240. dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
  241. dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
  242. if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
  243. sfi->fileIdent +
  244. le16_to_cpu(sfi->lengthOfImpUse))) {
  245. UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
  246. brelse(dbh);
  247. return NULL;
  248. }
  249. }
  250. mark_buffer_dirty_inode(dbh, inode);
  251. memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0,
  252. UDF_I_LENALLOC(inode));
  253. UDF_I_LENALLOC(inode) = 0;
  254. eloc.logicalBlockNum = *block;
  255. eloc.partitionReferenceNum =
  256. UDF_I_LOCATION(inode).partitionReferenceNum;
  257. elen = inode->i_size;
  258. UDF_I_LENEXTENTS(inode) = elen;
  259. epos.bh = NULL;
  260. epos.block = UDF_I_LOCATION(inode);
  261. epos.offset = udf_file_entry_alloc_offset(inode);
  262. udf_add_aext(inode, &epos, eloc, elen, 0);
  263. /* UniqueID stuff */
  264. brelse(epos.bh);
  265. mark_inode_dirty(inode);
  266. return dbh;
  267. }
  268. static int udf_get_block(struct inode *inode, sector_t block,
  269. struct buffer_head *bh_result, int create)
  270. {
  271. int err, new;
  272. struct buffer_head *bh;
  273. unsigned long phys;
  274. if (!create) {
  275. phys = udf_block_map(inode, block);
  276. if (phys)
  277. map_bh(bh_result, inode->i_sb, phys);
  278. return 0;
  279. }
  280. err = -EIO;
  281. new = 0;
  282. bh = NULL;
  283. lock_kernel();
  284. if (block < 0)
  285. goto abort_negative;
  286. if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) {
  287. UDF_I_NEXT_ALLOC_BLOCK(inode)++;
  288. UDF_I_NEXT_ALLOC_GOAL(inode)++;
  289. }
  290. err = 0;
  291. bh = inode_getblk(inode, block, &err, &phys, &new);
  292. BUG_ON(bh);
  293. if (err)
  294. goto abort;
  295. BUG_ON(!phys);
  296. if (new)
  297. set_buffer_new(bh_result);
  298. map_bh(bh_result, inode->i_sb, phys);
  299. abort:
  300. unlock_kernel();
  301. return err;
  302. abort_negative:
  303. udf_warning(inode->i_sb, "udf_get_block", "block < 0");
  304. goto abort;
  305. }
  306. static struct buffer_head *udf_getblk(struct inode *inode, long block,
  307. int create, int *err)
  308. {
  309. struct buffer_head *bh;
  310. struct buffer_head dummy;
  311. dummy.b_state = 0;
  312. dummy.b_blocknr = -1000;
  313. *err = udf_get_block(inode, block, &dummy, create);
  314. if (!*err && buffer_mapped(&dummy)) {
  315. bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
  316. if (buffer_new(&dummy)) {
  317. lock_buffer(bh);
  318. memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
  319. set_buffer_uptodate(bh);
  320. unlock_buffer(bh);
  321. mark_buffer_dirty_inode(bh, inode);
  322. }
  323. return bh;
  324. }
  325. return NULL;
  326. }
  327. /* Extend the file by 'blocks' blocks, return the number of extents added */
  328. int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
  329. kernel_long_ad *last_ext, sector_t blocks)
  330. {
  331. sector_t add;
  332. int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
  333. struct super_block *sb = inode->i_sb;
  334. kernel_lb_addr prealloc_loc = {};
  335. int prealloc_len = 0;
  336. /* The previous extent is fake and we should not extend by anything
  337. * - there's nothing to do... */
  338. if (!blocks && fake)
  339. return 0;
  340. /* Round the last extent up to a multiple of block size */
  341. if (last_ext->extLength & (sb->s_blocksize - 1)) {
  342. last_ext->extLength =
  343. (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
  344. (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
  345. sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
  346. UDF_I_LENEXTENTS(inode) =
  347. (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
  348. ~(sb->s_blocksize - 1);
  349. }
  350. /* Last extent are just preallocated blocks? */
  351. if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
  352. EXT_NOT_RECORDED_ALLOCATED) {
  353. /* Save the extent so that we can reattach it to the end */
  354. prealloc_loc = last_ext->extLocation;
  355. prealloc_len = last_ext->extLength;
  356. /* Mark the extent as a hole */
  357. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  358. (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
  359. last_ext->extLocation.logicalBlockNum = 0;
  360. last_ext->extLocation.partitionReferenceNum = 0;
  361. }
  362. /* Can we merge with the previous extent? */
  363. if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
  364. EXT_NOT_RECORDED_NOT_ALLOCATED) {
  365. add = ((1 << 30) - sb->s_blocksize -
  366. (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >>
  367. sb->s_blocksize_bits;
  368. if (add > blocks)
  369. add = blocks;
  370. blocks -= add;
  371. last_ext->extLength += add << sb->s_blocksize_bits;
  372. }
  373. if (fake) {
  374. udf_add_aext(inode, last_pos, last_ext->extLocation,
  375. last_ext->extLength, 1);
  376. count++;
  377. } else
  378. udf_write_aext(inode, last_pos, last_ext->extLocation,
  379. last_ext->extLength, 1);
  380. /* Managed to do everything necessary? */
  381. if (!blocks)
  382. goto out;
  383. /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
  384. last_ext->extLocation.logicalBlockNum = 0;
  385. last_ext->extLocation.partitionReferenceNum = 0;
  386. add = (1 << (30-sb->s_blocksize_bits)) - 1;
  387. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  388. (add << sb->s_blocksize_bits);
  389. /* Create enough extents to cover the whole hole */
  390. while (blocks > add) {
  391. blocks -= add;
  392. if (udf_add_aext(inode, last_pos, last_ext->extLocation,
  393. last_ext->extLength, 1) == -1)
  394. return -1;
  395. count++;
  396. }
  397. if (blocks) {
  398. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  399. (blocks << sb->s_blocksize_bits);
  400. if (udf_add_aext(inode, last_pos, last_ext->extLocation,
  401. last_ext->extLength, 1) == -1)
  402. return -1;
  403. count++;
  404. }
  405. out:
  406. /* Do we have some preallocated blocks saved? */
  407. if (prealloc_len) {
  408. if (udf_add_aext(inode, last_pos, prealloc_loc,
  409. prealloc_len, 1) == -1)
  410. return -1;
  411. last_ext->extLocation = prealloc_loc;
  412. last_ext->extLength = prealloc_len;
  413. count++;
  414. }
  415. /* last_pos should point to the last written extent... */
  416. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
  417. last_pos->offset -= sizeof(short_ad);
  418. else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
  419. last_pos->offset -= sizeof(long_ad);
  420. else
  421. return -1;
  422. return count;
  423. }
  424. static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
  425. int *err, long *phys, int *new)
  426. {
  427. static sector_t last_block;
  428. struct buffer_head *result = NULL;
  429. kernel_long_ad laarr[EXTENT_MERGE_SIZE];
  430. struct extent_position prev_epos, cur_epos, next_epos;
  431. int count = 0, startnum = 0, endnum = 0;
  432. uint32_t elen = 0, tmpelen;
  433. kernel_lb_addr eloc, tmpeloc;
  434. int c = 1;
  435. loff_t lbcount = 0, b_off = 0;
  436. uint32_t newblocknum, newblock;
  437. sector_t offset = 0;
  438. int8_t etype;
  439. int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
  440. int lastblock = 0;
  441. prev_epos.offset = udf_file_entry_alloc_offset(inode);
  442. prev_epos.block = UDF_I_LOCATION(inode);
  443. prev_epos.bh = NULL;
  444. cur_epos = next_epos = prev_epos;
  445. b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
  446. /* find the extent which contains the block we are looking for.
  447. alternate between laarr[0] and laarr[1] for locations of the
  448. current extent, and the previous extent */
  449. do {
  450. if (prev_epos.bh != cur_epos.bh) {
  451. brelse(prev_epos.bh);
  452. get_bh(cur_epos.bh);
  453. prev_epos.bh = cur_epos.bh;
  454. }
  455. if (cur_epos.bh != next_epos.bh) {
  456. brelse(cur_epos.bh);
  457. get_bh(next_epos.bh);
  458. cur_epos.bh = next_epos.bh;
  459. }
  460. lbcount += elen;
  461. prev_epos.block = cur_epos.block;
  462. cur_epos.block = next_epos.block;
  463. prev_epos.offset = cur_epos.offset;
  464. cur_epos.offset = next_epos.offset;
  465. etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1);
  466. if (etype == -1)
  467. break;
  468. c = !c;
  469. laarr[c].extLength = (etype << 30) | elen;
  470. laarr[c].extLocation = eloc;
  471. if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
  472. pgoal = eloc.logicalBlockNum +
  473. ((elen + inode->i_sb->s_blocksize - 1) >>
  474. inode->i_sb->s_blocksize_bits);
  475. count++;
  476. } while (lbcount + elen <= b_off);
  477. b_off -= lbcount;
  478. offset = b_off >> inode->i_sb->s_blocksize_bits;
  479. /*
  480. * Move prev_epos and cur_epos into indirect extent if we are at
  481. * the pointer to it
  482. */
  483. udf_next_aext(inode, &prev_epos, &tmpeloc, &tmpelen, 0);
  484. udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
  485. /* if the extent is allocated and recorded, return the block
  486. if the extent is not a multiple of the blocksize, round up */
  487. if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
  488. if (elen & (inode->i_sb->s_blocksize - 1)) {
  489. elen = EXT_RECORDED_ALLOCATED |
  490. ((elen + inode->i_sb->s_blocksize - 1) &
  491. ~(inode->i_sb->s_blocksize - 1));
  492. etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
  493. }
  494. brelse(prev_epos.bh);
  495. brelse(cur_epos.bh);
  496. brelse(next_epos.bh);
  497. newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset);
  498. *phys = newblock;
  499. return NULL;
  500. }
  501. last_block = block;
  502. /* Are we beyond EOF? */
  503. if (etype == -1) {
  504. int ret;
  505. if (count) {
  506. if (c)
  507. laarr[0] = laarr[1];
  508. startnum = 1;
  509. } else {
  510. /* Create a fake extent when there's not one */
  511. memset(&laarr[0].extLocation, 0x00,
  512. sizeof(kernel_lb_addr));
  513. laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
  514. /* Will udf_extend_file() create real extent from
  515. a fake one? */
  516. startnum = (offset > 0);
  517. }
  518. /* Create extents for the hole between EOF and offset */
  519. ret = udf_extend_file(inode, &prev_epos, laarr, offset);
  520. if (ret == -1) {
  521. brelse(prev_epos.bh);
  522. brelse(cur_epos.bh);
  523. brelse(next_epos.bh);
  524. /* We don't really know the error here so we just make
  525. * something up */
  526. *err = -ENOSPC;
  527. return NULL;
  528. }
  529. c = 0;
  530. offset = 0;
  531. count += ret;
  532. /* We are not covered by a preallocated extent? */
  533. if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
  534. EXT_NOT_RECORDED_ALLOCATED) {
  535. /* Is there any real extent? - otherwise we overwrite
  536. * the fake one... */
  537. if (count)
  538. c = !c;
  539. laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  540. inode->i_sb->s_blocksize;
  541. memset(&laarr[c].extLocation, 0x00,
  542. sizeof(kernel_lb_addr));
  543. count++;
  544. endnum++;
  545. }
  546. endnum = c + 1;
  547. lastblock = 1;
  548. } else {
  549. endnum = startnum = ((count > 2) ? 2 : count);
  550. /* if the current extent is in position 0,
  551. swap it with the previous */
  552. if (!c && count != 1) {
  553. laarr[2] = laarr[0];
  554. laarr[0] = laarr[1];
  555. laarr[1] = laarr[2];
  556. c = 1;
  557. }
  558. /* if the current block is located in an extent,
  559. read the next extent */
  560. etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0);
  561. if (etype != -1) {
  562. laarr[c + 1].extLength = (etype << 30) | elen;
  563. laarr[c + 1].extLocation = eloc;
  564. count++;
  565. startnum++;
  566. endnum++;
  567. } else
  568. lastblock = 1;
  569. }
  570. /* if the current extent is not recorded but allocated, get the
  571. * block in the extent corresponding to the requested block */
  572. if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  573. newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
  574. else { /* otherwise, allocate a new block */
  575. if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
  576. goal = UDF_I_NEXT_ALLOC_GOAL(inode);
  577. if (!goal) {
  578. if (!(goal = pgoal)) /* XXX: what was intended here? */
  579. goal = UDF_I_LOCATION(inode).logicalBlockNum+1;
  580. }
  581. newblocknum = udf_new_block(inode->i_sb, inode,
  582. UDF_I_LOCATION(inode).partitionReferenceNum,
  583. goal, err);
  584. if (!newblocknum) {
  585. brelse(prev_epos.bh);
  586. *err = -ENOSPC;
  587. return NULL;
  588. }
  589. UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize;
  590. }
  591. /* if the extent the requsted block is located in contains multiple
  592. * blocks, split the extent into at most three extents. blocks prior
  593. * to requested block, requested block, and blocks after requested
  594. * block */
  595. udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
  596. #ifdef UDF_PREALLOCATE
  597. /* preallocate blocks */
  598. udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
  599. #endif
  600. /* merge any continuous blocks in laarr */
  601. udf_merge_extents(inode, laarr, &endnum);
  602. /* write back the new extents, inserting new extents if the new number
  603. * of extents is greater than the old number, and deleting extents if
  604. * the new number of extents is less than the old number */
  605. udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
  606. brelse(prev_epos.bh);
  607. newblock = udf_get_pblock(inode->i_sb, newblocknum,
  608. UDF_I_LOCATION(inode).partitionReferenceNum, 0);
  609. if (!newblock)
  610. return NULL;
  611. *phys = newblock;
  612. *err = 0;
  613. *new = 1;
  614. UDF_I_NEXT_ALLOC_BLOCK(inode) = block;
  615. UDF_I_NEXT_ALLOC_GOAL(inode) = newblocknum;
  616. inode->i_ctime = current_fs_time(inode->i_sb);
  617. if (IS_SYNC(inode))
  618. udf_sync_inode(inode);
  619. else
  620. mark_inode_dirty(inode);
  621. return result;
  622. }
  623. static void udf_split_extents(struct inode *inode, int *c, int offset,
  624. int newblocknum,
  625. kernel_long_ad laarr[EXTENT_MERGE_SIZE],
  626. int *endnum)
  627. {
  628. unsigned long blocksize = inode->i_sb->s_blocksize;
  629. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  630. if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
  631. (laarr[*c].extLength >> 30) ==
  632. (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
  633. int curr = *c;
  634. int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
  635. blocksize - 1) >> blocksize_bits;
  636. int8_t etype = (laarr[curr].extLength >> 30);
  637. if (blen == 1)
  638. ;
  639. else if (!offset || blen == offset + 1) {
  640. laarr[curr + 2] = laarr[curr + 1];
  641. laarr[curr + 1] = laarr[curr];
  642. } else {
  643. laarr[curr + 3] = laarr[curr + 1];
  644. laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
  645. }
  646. if (offset) {
  647. if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
  648. udf_free_blocks(inode->i_sb, inode,
  649. laarr[curr].extLocation,
  650. 0, offset);
  651. laarr[curr].extLength =
  652. EXT_NOT_RECORDED_NOT_ALLOCATED |
  653. (offset << blocksize_bits);
  654. laarr[curr].extLocation.logicalBlockNum = 0;
  655. laarr[curr].extLocation.
  656. partitionReferenceNum = 0;
  657. } else
  658. laarr[curr].extLength = (etype << 30) |
  659. (offset << blocksize_bits);
  660. curr++;
  661. (*c)++;
  662. (*endnum)++;
  663. }
  664. laarr[curr].extLocation.logicalBlockNum = newblocknum;
  665. if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
  666. laarr[curr].extLocation.partitionReferenceNum =
  667. UDF_I_LOCATION(inode).partitionReferenceNum;
  668. laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
  669. blocksize;
  670. curr++;
  671. if (blen != offset + 1) {
  672. if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  673. laarr[curr].extLocation.logicalBlockNum +=
  674. offset + 1;
  675. laarr[curr].extLength = (etype << 30) |
  676. ((blen - (offset + 1)) << blocksize_bits);
  677. curr++;
  678. (*endnum)++;
  679. }
  680. }
  681. }
  682. static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
  683. kernel_long_ad laarr[EXTENT_MERGE_SIZE],
  684. int *endnum)
  685. {
  686. int start, length = 0, currlength = 0, i;
  687. if (*endnum >= (c + 1)) {
  688. if (!lastblock)
  689. return;
  690. else
  691. start = c;
  692. } else {
  693. if ((laarr[c + 1].extLength >> 30) ==
  694. (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
  695. start = c + 1;
  696. length = currlength =
  697. (((laarr[c + 1].extLength &
  698. UDF_EXTENT_LENGTH_MASK) +
  699. inode->i_sb->s_blocksize - 1) >>
  700. inode->i_sb->s_blocksize_bits);
  701. } else
  702. start = c;
  703. }
  704. for (i = start + 1; i <= *endnum; i++) {
  705. if (i == *endnum) {
  706. if (lastblock)
  707. length += UDF_DEFAULT_PREALLOC_BLOCKS;
  708. } else if ((laarr[i].extLength >> 30) ==
  709. (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
  710. length += (((laarr[i].extLength &
  711. UDF_EXTENT_LENGTH_MASK) +
  712. inode->i_sb->s_blocksize - 1) >>
  713. inode->i_sb->s_blocksize_bits);
  714. } else
  715. break;
  716. }
  717. if (length) {
  718. int next = laarr[start].extLocation.logicalBlockNum +
  719. (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
  720. inode->i_sb->s_blocksize - 1) >>
  721. inode->i_sb->s_blocksize_bits);
  722. int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
  723. laarr[start].extLocation.partitionReferenceNum,
  724. next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ?
  725. length : UDF_DEFAULT_PREALLOC_BLOCKS) -
  726. currlength);
  727. if (numalloc) {
  728. if (start == (c + 1))
  729. laarr[start].extLength +=
  730. (numalloc <<
  731. inode->i_sb->s_blocksize_bits);
  732. else {
  733. memmove(&laarr[c + 2], &laarr[c + 1],
  734. sizeof(long_ad) * (*endnum - (c + 1)));
  735. (*endnum)++;
  736. laarr[c + 1].extLocation.logicalBlockNum = next;
  737. laarr[c + 1].extLocation.partitionReferenceNum =
  738. laarr[c].extLocation.
  739. partitionReferenceNum;
  740. laarr[c + 1].extLength =
  741. EXT_NOT_RECORDED_ALLOCATED |
  742. (numalloc <<
  743. inode->i_sb->s_blocksize_bits);
  744. start = c + 1;
  745. }
  746. for (i = start + 1; numalloc && i < *endnum; i++) {
  747. int elen = ((laarr[i].extLength &
  748. UDF_EXTENT_LENGTH_MASK) +
  749. inode->i_sb->s_blocksize - 1) >>
  750. inode->i_sb->s_blocksize_bits;
  751. if (elen > numalloc) {
  752. laarr[i].extLength -=
  753. (numalloc <<
  754. inode->i_sb->s_blocksize_bits);
  755. numalloc = 0;
  756. } else {
  757. numalloc -= elen;
  758. if (*endnum > (i + 1))
  759. memmove(&laarr[i],
  760. &laarr[i + 1],
  761. sizeof(long_ad) *
  762. (*endnum - (i + 1)));
  763. i--;
  764. (*endnum)--;
  765. }
  766. }
  767. UDF_I_LENEXTENTS(inode) +=
  768. numalloc << inode->i_sb->s_blocksize_bits;
  769. }
  770. }
  771. }
  772. static void udf_merge_extents(struct inode *inode,
  773. kernel_long_ad laarr[EXTENT_MERGE_SIZE],
  774. int *endnum)
  775. {
  776. int i;
  777. unsigned long blocksize = inode->i_sb->s_blocksize;
  778. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  779. for (i = 0; i < (*endnum - 1); i++) {
  780. kernel_long_ad *li /*l[i]*/ = &laarr[i];
  781. kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1];
  782. if (((li->extLength >> 30) == (lip1->extLength >> 30)) &&
  783. (((li->extLength >> 30) ==
  784. (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
  785. ((lip1->extLocation.logicalBlockNum -
  786. li->extLocation.logicalBlockNum) ==
  787. (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
  788. blocksize - 1) >> blocksize_bits)))) {
  789. if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
  790. (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
  791. blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
  792. lip1->extLength = (lip1->extLength -
  793. (li->extLength &
  794. UDF_EXTENT_LENGTH_MASK) +
  795. UDF_EXTENT_LENGTH_MASK) &
  796. ~(blocksize - 1);
  797. li->extLength = (li->extLength &
  798. UDF_EXTENT_FLAG_MASK) +
  799. (UDF_EXTENT_LENGTH_MASK + 1) -
  800. blocksize;
  801. lip1->extLocation.logicalBlockNum =
  802. li->extLocation.logicalBlockNum +
  803. ((li->extLength &
  804. UDF_EXTENT_LENGTH_MASK) >>
  805. blocksize_bits);
  806. } else {
  807. li->extLength = lip1->extLength +
  808. (((li->extLength &
  809. UDF_EXTENT_LENGTH_MASK) +
  810. blocksize - 1) & ~(blocksize - 1));
  811. if (*endnum > (i + 2))
  812. memmove(&laarr[i + 1], &laarr[i + 2],
  813. sizeof(long_ad) *
  814. (*endnum - (i + 2)));
  815. i--;
  816. (*endnum)--;
  817. }
  818. } else if (((li->extLength >> 30) ==
  819. (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
  820. ((lip1->extLength >> 30) ==
  821. (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
  822. udf_free_blocks(inode->i_sb, inode, li->extLocation, 0,
  823. ((li->extLength &
  824. UDF_EXTENT_LENGTH_MASK) +
  825. blocksize - 1) >> blocksize_bits);
  826. li->extLocation.logicalBlockNum = 0;
  827. li->extLocation.partitionReferenceNum = 0;
  828. if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
  829. (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
  830. blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
  831. lip1->extLength = (lip1->extLength -
  832. (li->extLength &
  833. UDF_EXTENT_LENGTH_MASK) +
  834. UDF_EXTENT_LENGTH_MASK) &
  835. ~(blocksize - 1);
  836. li->extLength = (li->extLength &
  837. UDF_EXTENT_FLAG_MASK) +
  838. (UDF_EXTENT_LENGTH_MASK + 1) -
  839. blocksize;
  840. } else {
  841. li->extLength = lip1->extLength +
  842. (((li->extLength &
  843. UDF_EXTENT_LENGTH_MASK) +
  844. blocksize - 1) & ~(blocksize - 1));
  845. if (*endnum > (i + 2))
  846. memmove(&laarr[i + 1], &laarr[i + 2],
  847. sizeof(long_ad) *
  848. (*endnum - (i + 2)));
  849. i--;
  850. (*endnum)--;
  851. }
  852. } else if ((li->extLength >> 30) ==
  853. (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
  854. udf_free_blocks(inode->i_sb, inode,
  855. li->extLocation, 0,
  856. ((li->extLength &
  857. UDF_EXTENT_LENGTH_MASK) +
  858. blocksize - 1) >> blocksize_bits);
  859. li->extLocation.logicalBlockNum = 0;
  860. li->extLocation.partitionReferenceNum = 0;
  861. li->extLength = (li->extLength &
  862. UDF_EXTENT_LENGTH_MASK) |
  863. EXT_NOT_RECORDED_NOT_ALLOCATED;
  864. }
  865. }
  866. }
  867. static void udf_update_extents(struct inode *inode,
  868. kernel_long_ad laarr[EXTENT_MERGE_SIZE],
  869. int startnum, int endnum,
  870. struct extent_position *epos)
  871. {
  872. int start = 0, i;
  873. kernel_lb_addr tmploc;
  874. uint32_t tmplen;
  875. if (startnum > endnum) {
  876. for (i = 0; i < (startnum - endnum); i++)
  877. udf_delete_aext(inode, *epos, laarr[i].extLocation,
  878. laarr[i].extLength);
  879. } else if (startnum < endnum) {
  880. for (i = 0; i < (endnum - startnum); i++) {
  881. udf_insert_aext(inode, *epos, laarr[i].extLocation,
  882. laarr[i].extLength);
  883. udf_next_aext(inode, epos, &laarr[i].extLocation,
  884. &laarr[i].extLength, 1);
  885. start++;
  886. }
  887. }
  888. for (i = start; i < endnum; i++) {
  889. udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
  890. udf_write_aext(inode, epos, laarr[i].extLocation,
  891. laarr[i].extLength, 1);
  892. }
  893. }
  894. struct buffer_head *udf_bread(struct inode *inode, int block,
  895. int create, int *err)
  896. {
  897. struct buffer_head *bh = NULL;
  898. bh = udf_getblk(inode, block, create, err);
  899. if (!bh)
  900. return NULL;
  901. if (buffer_uptodate(bh))
  902. return bh;
  903. ll_rw_block(READ, 1, &bh);
  904. wait_on_buffer(bh);
  905. if (buffer_uptodate(bh))
  906. return bh;
  907. brelse(bh);
  908. *err = -EIO;
  909. return NULL;
  910. }
  911. void udf_truncate(struct inode *inode)
  912. {
  913. int offset;
  914. int err;
  915. if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
  916. S_ISLNK(inode->i_mode)))
  917. return;
  918. if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
  919. return;
  920. lock_kernel();
  921. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
  922. if (inode->i_sb->s_blocksize <
  923. (udf_file_entry_alloc_offset(inode) +
  924. inode->i_size)) {
  925. udf_expand_file_adinicb(inode, inode->i_size, &err);
  926. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
  927. inode->i_size = UDF_I_LENALLOC(inode);
  928. unlock_kernel();
  929. return;
  930. } else
  931. udf_truncate_extents(inode);
  932. } else {
  933. offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
  934. memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) +
  935. offset, 0x00, inode->i_sb->s_blocksize -
  936. offset - udf_file_entry_alloc_offset(inode));
  937. UDF_I_LENALLOC(inode) = inode->i_size;
  938. }
  939. } else {
  940. block_truncate_page(inode->i_mapping, inode->i_size,
  941. udf_get_block);
  942. udf_truncate_extents(inode);
  943. }
  944. inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
  945. if (IS_SYNC(inode))
  946. udf_sync_inode(inode);
  947. else
  948. mark_inode_dirty(inode);
  949. unlock_kernel();
  950. }
  951. static void __udf_read_inode(struct inode *inode)
  952. {
  953. struct buffer_head *bh = NULL;
  954. struct fileEntry *fe;
  955. uint16_t ident;
  956. /*
  957. * Set defaults, but the inode is still incomplete!
  958. * Note: get_new_inode() sets the following on a new inode:
  959. * i_sb = sb
  960. * i_no = ino
  961. * i_flags = sb->s_flags
  962. * i_state = 0
  963. * clean_inode(): zero fills and sets
  964. * i_count = 1
  965. * i_nlink = 1
  966. * i_op = NULL;
  967. */
  968. bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
  969. if (!bh) {
  970. printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
  971. inode->i_ino);
  972. make_bad_inode(inode);
  973. return;
  974. }
  975. if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
  976. ident != TAG_IDENT_USE) {
  977. printk(KERN_ERR "udf: udf_read_inode(ino %ld) "
  978. "failed ident=%d\n", inode->i_ino, ident);
  979. brelse(bh);
  980. make_bad_inode(inode);
  981. return;
  982. }
  983. fe = (struct fileEntry *)bh->b_data;
  984. if (le16_to_cpu(fe->icbTag.strategyType) == 4096) {
  985. struct buffer_head *ibh = NULL, *nbh = NULL;
  986. struct indirectEntry *ie;
  987. ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1,
  988. &ident);
  989. if (ident == TAG_IDENT_IE) {
  990. if (ibh) {
  991. kernel_lb_addr loc;
  992. ie = (struct indirectEntry *)ibh->b_data;
  993. loc = lelb_to_cpu(ie->indirectICB.extLocation);
  994. if (ie->indirectICB.extLength &&
  995. (nbh = udf_read_ptagged(inode->i_sb, loc, 0,
  996. &ident))) {
  997. if (ident == TAG_IDENT_FE ||
  998. ident == TAG_IDENT_EFE) {
  999. memcpy(&UDF_I_LOCATION(inode),
  1000. &loc,
  1001. sizeof(kernel_lb_addr));
  1002. brelse(bh);
  1003. brelse(ibh);
  1004. brelse(nbh);
  1005. __udf_read_inode(inode);
  1006. return;
  1007. } else {
  1008. brelse(nbh);
  1009. brelse(ibh);
  1010. }
  1011. } else {
  1012. brelse(ibh);
  1013. }
  1014. }
  1015. } else {
  1016. brelse(ibh);
  1017. }
  1018. } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) {
  1019. printk(KERN_ERR "udf: unsupported strategy type: %d\n",
  1020. le16_to_cpu(fe->icbTag.strategyType));
  1021. brelse(bh);
  1022. make_bad_inode(inode);
  1023. return;
  1024. }
  1025. udf_fill_inode(inode, bh);
  1026. brelse(bh);
  1027. }
  1028. static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
  1029. {
  1030. struct fileEntry *fe;
  1031. struct extendedFileEntry *efe;
  1032. time_t convtime;
  1033. long convtime_usec;
  1034. int offset;
  1035. struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
  1036. fe = (struct fileEntry *)bh->b_data;
  1037. efe = (struct extendedFileEntry *)bh->b_data;
  1038. if (le16_to_cpu(fe->icbTag.strategyType) == 4)
  1039. UDF_I_STRAT4096(inode) = 0;
  1040. else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
  1041. UDF_I_STRAT4096(inode) = 1;
  1042. UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) &
  1043. ICBTAG_FLAG_AD_MASK;
  1044. UDF_I_UNIQUE(inode) = 0;
  1045. UDF_I_LENEATTR(inode) = 0;
  1046. UDF_I_LENEXTENTS(inode) = 0;
  1047. UDF_I_LENALLOC(inode) = 0;
  1048. UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
  1049. UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
  1050. if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) {
  1051. UDF_I_EFE(inode) = 1;
  1052. UDF_I_USE(inode) = 0;
  1053. if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
  1054. sizeof(struct extendedFileEntry))) {
  1055. make_bad_inode(inode);
  1056. return;
  1057. }
  1058. memcpy(UDF_I_DATA(inode),
  1059. bh->b_data + sizeof(struct extendedFileEntry),
  1060. inode->i_sb->s_blocksize -
  1061. sizeof(struct extendedFileEntry));
  1062. } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) {
  1063. UDF_I_EFE(inode) = 0;
  1064. UDF_I_USE(inode) = 0;
  1065. if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
  1066. sizeof(struct fileEntry))) {
  1067. make_bad_inode(inode);
  1068. return;
  1069. }
  1070. memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry),
  1071. inode->i_sb->s_blocksize - sizeof(struct fileEntry));
  1072. } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
  1073. UDF_I_EFE(inode) = 0;
  1074. UDF_I_USE(inode) = 1;
  1075. UDF_I_LENALLOC(inode) = le32_to_cpu(
  1076. ((struct unallocSpaceEntry *)bh->b_data)->
  1077. lengthAllocDescs);
  1078. if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
  1079. sizeof(struct unallocSpaceEntry))) {
  1080. make_bad_inode(inode);
  1081. return;
  1082. }
  1083. memcpy(UDF_I_DATA(inode),
  1084. bh->b_data + sizeof(struct unallocSpaceEntry),
  1085. inode->i_sb->s_blocksize -
  1086. sizeof(struct unallocSpaceEntry));
  1087. return;
  1088. }
  1089. inode->i_uid = le32_to_cpu(fe->uid);
  1090. if (inode->i_uid == -1 ||
  1091. UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_IGNORE) ||
  1092. UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET))
  1093. inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
  1094. inode->i_gid = le32_to_cpu(fe->gid);
  1095. if (inode->i_gid == -1 ||
  1096. UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_IGNORE) ||
  1097. UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET))
  1098. inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
  1099. inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
  1100. if (!inode->i_nlink)
  1101. inode->i_nlink = 1;
  1102. inode->i_size = le64_to_cpu(fe->informationLength);
  1103. UDF_I_LENEXTENTS(inode) = inode->i_size;
  1104. inode->i_mode = udf_convert_permissions(fe);
  1105. inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
  1106. if (UDF_I_EFE(inode) == 0) {
  1107. inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
  1108. (inode->i_sb->s_blocksize_bits - 9);
  1109. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1110. lets_to_cpu(fe->accessTime))) {
  1111. inode->i_atime.tv_sec = convtime;
  1112. inode->i_atime.tv_nsec = convtime_usec * 1000;
  1113. } else {
  1114. inode->i_atime = sbi->s_record_time;
  1115. }
  1116. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1117. lets_to_cpu(fe->modificationTime))) {
  1118. inode->i_mtime.tv_sec = convtime;
  1119. inode->i_mtime.tv_nsec = convtime_usec * 1000;
  1120. } else {
  1121. inode->i_mtime = sbi->s_record_time;
  1122. }
  1123. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1124. lets_to_cpu(fe->attrTime))) {
  1125. inode->i_ctime.tv_sec = convtime;
  1126. inode->i_ctime.tv_nsec = convtime_usec * 1000;
  1127. } else {
  1128. inode->i_ctime = sbi->s_record_time;
  1129. }
  1130. UDF_I_UNIQUE(inode) = le64_to_cpu(fe->uniqueID);
  1131. UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
  1132. UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
  1133. offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
  1134. } else {
  1135. inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
  1136. (inode->i_sb->s_blocksize_bits - 9);
  1137. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1138. lets_to_cpu(efe->accessTime))) {
  1139. inode->i_atime.tv_sec = convtime;
  1140. inode->i_atime.tv_nsec = convtime_usec * 1000;
  1141. } else {
  1142. inode->i_atime = sbi->s_record_time;
  1143. }
  1144. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1145. lets_to_cpu(efe->modificationTime))) {
  1146. inode->i_mtime.tv_sec = convtime;
  1147. inode->i_mtime.tv_nsec = convtime_usec * 1000;
  1148. } else {
  1149. inode->i_mtime = sbi->s_record_time;
  1150. }
  1151. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1152. lets_to_cpu(efe->createTime))) {
  1153. UDF_I_CRTIME(inode).tv_sec = convtime;
  1154. UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
  1155. } else {
  1156. UDF_I_CRTIME(inode) = sbi->s_record_time;
  1157. }
  1158. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1159. lets_to_cpu(efe->attrTime))) {
  1160. inode->i_ctime.tv_sec = convtime;
  1161. inode->i_ctime.tv_nsec = convtime_usec * 1000;
  1162. } else {
  1163. inode->i_ctime = sbi->s_record_time;
  1164. }
  1165. UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
  1166. UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
  1167. UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
  1168. offset = sizeof(struct extendedFileEntry) +
  1169. UDF_I_LENEATTR(inode);
  1170. }
  1171. switch (fe->icbTag.fileType) {
  1172. case ICBTAG_FILE_TYPE_DIRECTORY:
  1173. inode->i_op = &udf_dir_inode_operations;
  1174. inode->i_fop = &udf_dir_operations;
  1175. inode->i_mode |= S_IFDIR;
  1176. inc_nlink(inode);
  1177. break;
  1178. case ICBTAG_FILE_TYPE_REALTIME:
  1179. case ICBTAG_FILE_TYPE_REGULAR:
  1180. case ICBTAG_FILE_TYPE_UNDEF:
  1181. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
  1182. inode->i_data.a_ops = &udf_adinicb_aops;
  1183. else
  1184. inode->i_data.a_ops = &udf_aops;
  1185. inode->i_op = &udf_file_inode_operations;
  1186. inode->i_fop = &udf_file_operations;
  1187. inode->i_mode |= S_IFREG;
  1188. break;
  1189. case ICBTAG_FILE_TYPE_BLOCK:
  1190. inode->i_mode |= S_IFBLK;
  1191. break;
  1192. case ICBTAG_FILE_TYPE_CHAR:
  1193. inode->i_mode |= S_IFCHR;
  1194. break;
  1195. case ICBTAG_FILE_TYPE_FIFO:
  1196. init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
  1197. break;
  1198. case ICBTAG_FILE_TYPE_SOCKET:
  1199. init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
  1200. break;
  1201. case ICBTAG_FILE_TYPE_SYMLINK:
  1202. inode->i_data.a_ops = &udf_symlink_aops;
  1203. inode->i_op = &page_symlink_inode_operations;
  1204. inode->i_mode = S_IFLNK | S_IRWXUGO;
  1205. break;
  1206. default:
  1207. printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown "
  1208. "file type=%d\n", inode->i_ino,
  1209. fe->icbTag.fileType);
  1210. make_bad_inode(inode);
  1211. return;
  1212. }
  1213. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
  1214. struct deviceSpec *dsea =
  1215. (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
  1216. if (dsea) {
  1217. init_special_inode(inode, inode->i_mode,
  1218. MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
  1219. le32_to_cpu(dsea->minorDeviceIdent)));
  1220. /* Developer ID ??? */
  1221. } else
  1222. make_bad_inode(inode);
  1223. }
  1224. }
  1225. static int udf_alloc_i_data(struct inode *inode, size_t size)
  1226. {
  1227. UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL);
  1228. if (!UDF_I_DATA(inode)) {
  1229. printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) "
  1230. "no free memory\n", inode->i_ino);
  1231. return -ENOMEM;
  1232. }
  1233. return 0;
  1234. }
  1235. static mode_t udf_convert_permissions(struct fileEntry *fe)
  1236. {
  1237. mode_t mode;
  1238. uint32_t permissions;
  1239. uint32_t flags;
  1240. permissions = le32_to_cpu(fe->permissions);
  1241. flags = le16_to_cpu(fe->icbTag.flags);
  1242. mode = ((permissions) & S_IRWXO) |
  1243. ((permissions >> 2) & S_IRWXG) |
  1244. ((permissions >> 4) & S_IRWXU) |
  1245. ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
  1246. ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
  1247. ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
  1248. return mode;
  1249. }
  1250. /*
  1251. * udf_write_inode
  1252. *
  1253. * PURPOSE
  1254. * Write out the specified inode.
  1255. *
  1256. * DESCRIPTION
  1257. * This routine is called whenever an inode is synced.
  1258. * Currently this routine is just a placeholder.
  1259. *
  1260. * HISTORY
  1261. * July 1, 1997 - Andrew E. Mileski
  1262. * Written, tested, and released.
  1263. */
  1264. int udf_write_inode(struct inode *inode, int sync)
  1265. {
  1266. int ret;
  1267. lock_kernel();
  1268. ret = udf_update_inode(inode, sync);
  1269. unlock_kernel();
  1270. return ret;
  1271. }
  1272. int udf_sync_inode(struct inode *inode)
  1273. {
  1274. return udf_update_inode(inode, 1);
  1275. }
  1276. static int udf_update_inode(struct inode *inode, int do_sync)
  1277. {
  1278. struct buffer_head *bh = NULL;
  1279. struct fileEntry *fe;
  1280. struct extendedFileEntry *efe;
  1281. uint32_t udfperms;
  1282. uint16_t icbflags;
  1283. uint16_t crclen;
  1284. kernel_timestamp cpu_time;
  1285. int err = 0;
  1286. struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
  1287. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  1288. bh = udf_tread(inode->i_sb,
  1289. udf_get_lb_pblock(inode->i_sb,
  1290. UDF_I_LOCATION(inode), 0));
  1291. if (!bh) {
  1292. udf_debug("bread failure\n");
  1293. return -EIO;
  1294. }
  1295. memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
  1296. fe = (struct fileEntry *)bh->b_data;
  1297. efe = (struct extendedFileEntry *)bh->b_data;
  1298. if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
  1299. struct unallocSpaceEntry *use =
  1300. (struct unallocSpaceEntry *)bh->b_data;
  1301. use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
  1302. memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
  1303. UDF_I_DATA(inode), inode->i_sb->s_blocksize -
  1304. sizeof(struct unallocSpaceEntry));
  1305. crclen = sizeof(struct unallocSpaceEntry) +
  1306. UDF_I_LENALLOC(inode) - sizeof(tag);
  1307. use->descTag.tagLocation = cpu_to_le32(
  1308. UDF_I_LOCATION(inode).
  1309. logicalBlockNum);
  1310. use->descTag.descCRCLength = cpu_to_le16(crclen);
  1311. use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
  1312. sizeof(tag), crclen,
  1313. 0));
  1314. use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
  1315. mark_buffer_dirty(bh);
  1316. brelse(bh);
  1317. return err;
  1318. }
  1319. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
  1320. fe->uid = cpu_to_le32(-1);
  1321. else
  1322. fe->uid = cpu_to_le32(inode->i_uid);
  1323. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
  1324. fe->gid = cpu_to_le32(-1);
  1325. else
  1326. fe->gid = cpu_to_le32(inode->i_gid);
  1327. udfperms = ((inode->i_mode & S_IRWXO)) |
  1328. ((inode->i_mode & S_IRWXG) << 2) |
  1329. ((inode->i_mode & S_IRWXU) << 4);
  1330. udfperms |= (le32_to_cpu(fe->permissions) &
  1331. (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
  1332. FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
  1333. FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
  1334. fe->permissions = cpu_to_le32(udfperms);
  1335. if (S_ISDIR(inode->i_mode))
  1336. fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
  1337. else
  1338. fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
  1339. fe->informationLength = cpu_to_le64(inode->i_size);
  1340. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
  1341. regid *eid;
  1342. struct deviceSpec *dsea =
  1343. (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
  1344. if (!dsea) {
  1345. dsea = (struct deviceSpec *)
  1346. udf_add_extendedattr(inode,
  1347. sizeof(struct deviceSpec) +
  1348. sizeof(regid), 12, 0x3);
  1349. dsea->attrType = cpu_to_le32(12);
  1350. dsea->attrSubtype = 1;
  1351. dsea->attrLength = cpu_to_le32(
  1352. sizeof(struct deviceSpec) +
  1353. sizeof(regid));
  1354. dsea->impUseLength = cpu_to_le32(sizeof(regid));
  1355. }
  1356. eid = (regid *)dsea->impUse;
  1357. memset(eid, 0, sizeof(regid));
  1358. strcpy(eid->ident, UDF_ID_DEVELOPER);
  1359. eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
  1360. eid->identSuffix[1] = UDF_OS_ID_LINUX;
  1361. dsea->majorDeviceIdent = cpu_to_le32(imajor(inode));
  1362. dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
  1363. }
  1364. if (UDF_I_EFE(inode) == 0) {
  1365. memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode),
  1366. inode->i_sb->s_blocksize - sizeof(struct fileEntry));
  1367. fe->logicalBlocksRecorded = cpu_to_le64(
  1368. (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
  1369. (blocksize_bits - 9));
  1370. if (udf_time_to_stamp(&cpu_time, inode->i_atime))
  1371. fe->accessTime = cpu_to_lets(cpu_time);
  1372. if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
  1373. fe->modificationTime = cpu_to_lets(cpu_time);
  1374. if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
  1375. fe->attrTime = cpu_to_lets(cpu_time);
  1376. memset(&(fe->impIdent), 0, sizeof(regid));
  1377. strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
  1378. fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1379. fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1380. fe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
  1381. fe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
  1382. fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
  1383. fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
  1384. crclen = sizeof(struct fileEntry);
  1385. } else {
  1386. memcpy(bh->b_data + sizeof(struct extendedFileEntry),
  1387. UDF_I_DATA(inode),
  1388. inode->i_sb->s_blocksize -
  1389. sizeof(struct extendedFileEntry));
  1390. efe->objectSize = cpu_to_le64(inode->i_size);
  1391. efe->logicalBlocksRecorded = cpu_to_le64(
  1392. (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
  1393. (blocksize_bits - 9));
  1394. if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
  1395. (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
  1396. UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec))
  1397. UDF_I_CRTIME(inode) = inode->i_atime;
  1398. if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec ||
  1399. (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec &&
  1400. UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec))
  1401. UDF_I_CRTIME(inode) = inode->i_mtime;
  1402. if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec ||
  1403. (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec &&
  1404. UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec))
  1405. UDF_I_CRTIME(inode) = inode->i_ctime;
  1406. if (udf_time_to_stamp(&cpu_time, inode->i_atime))
  1407. efe->accessTime = cpu_to_lets(cpu_time);
  1408. if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
  1409. efe->modificationTime = cpu_to_lets(cpu_time);
  1410. if (udf_time_to_stamp(&cpu_time, UDF_I_CRTIME(inode)))
  1411. efe->createTime = cpu_to_lets(cpu_time);
  1412. if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
  1413. efe->attrTime = cpu_to_lets(cpu_time);
  1414. memset(&(efe->impIdent), 0, sizeof(regid));
  1415. strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
  1416. efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1417. efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1418. efe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
  1419. efe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
  1420. efe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
  1421. efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
  1422. crclen = sizeof(struct extendedFileEntry);
  1423. }
  1424. if (UDF_I_STRAT4096(inode)) {
  1425. fe->icbTag.strategyType = cpu_to_le16(4096);
  1426. fe->icbTag.strategyParameter = cpu_to_le16(1);
  1427. fe->icbTag.numEntries = cpu_to_le16(2);
  1428. } else {
  1429. fe->icbTag.strategyType = cpu_to_le16(4);
  1430. fe->icbTag.numEntries = cpu_to_le16(1);
  1431. }
  1432. if (S_ISDIR(inode->i_mode))
  1433. fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
  1434. else if (S_ISREG(inode->i_mode))
  1435. fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
  1436. else if (S_ISLNK(inode->i_mode))
  1437. fe->icbTag.fileType = ICBTAG_FILE_TYPE_SYMLINK;
  1438. else if (S_ISBLK(inode->i_mode))
  1439. fe->icbTag.fileType = ICBTAG_FILE_TYPE_BLOCK;
  1440. else if (S_ISCHR(inode->i_mode))
  1441. fe->icbTag.fileType = ICBTAG_FILE_TYPE_CHAR;
  1442. else if (S_ISFIFO(inode->i_mode))
  1443. fe->icbTag.fileType = ICBTAG_FILE_TYPE_FIFO;
  1444. else if (S_ISSOCK(inode->i_mode))
  1445. fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
  1446. icbflags = UDF_I_ALLOCTYPE(inode) |
  1447. ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
  1448. ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
  1449. ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
  1450. (le16_to_cpu(fe->icbTag.flags) &
  1451. ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
  1452. ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
  1453. fe->icbTag.flags = cpu_to_le16(icbflags);
  1454. if (sbi->s_udfrev >= 0x0200)
  1455. fe->descTag.descVersion = cpu_to_le16(3);
  1456. else
  1457. fe->descTag.descVersion = cpu_to_le16(2);
  1458. fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number);
  1459. fe->descTag.tagLocation = cpu_to_le32(
  1460. UDF_I_LOCATION(inode).logicalBlockNum);
  1461. crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
  1462. fe->descTag.descCRCLength = cpu_to_le16(crclen);
  1463. fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
  1464. crclen, 0));
  1465. fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
  1466. /* write the data blocks */
  1467. mark_buffer_dirty(bh);
  1468. if (do_sync) {
  1469. sync_dirty_buffer(bh);
  1470. if (buffer_req(bh) && !buffer_uptodate(bh)) {
  1471. printk(KERN_WARNING "IO error syncing udf inode "
  1472. "[%s:%08lx]\n", inode->i_sb->s_id,
  1473. inode->i_ino);
  1474. err = -EIO;
  1475. }
  1476. }
  1477. brelse(bh);
  1478. return err;
  1479. }
  1480. struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
  1481. {
  1482. unsigned long block = udf_get_lb_pblock(sb, ino, 0);
  1483. struct inode *inode = iget_locked(sb, block);
  1484. if (!inode)
  1485. return NULL;
  1486. if (inode->i_state & I_NEW) {
  1487. memcpy(&UDF_I_LOCATION(inode), &ino, sizeof(kernel_lb_addr));
  1488. __udf_read_inode(inode);
  1489. unlock_new_inode(inode);
  1490. }
  1491. if (is_bad_inode(inode))
  1492. goto out_iput;
  1493. if (ino.logicalBlockNum >= UDF_SB(sb)->
  1494. s_partmaps[ino.partitionReferenceNum].s_partition_len) {
  1495. udf_debug("block=%d, partition=%d out of range\n",
  1496. ino.logicalBlockNum, ino.partitionReferenceNum);
  1497. make_bad_inode(inode);
  1498. goto out_iput;
  1499. }
  1500. return inode;
  1501. out_iput:
  1502. iput(inode);
  1503. return NULL;
  1504. }
  1505. int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
  1506. kernel_lb_addr eloc, uint32_t elen, int inc)
  1507. {
  1508. int adsize;
  1509. short_ad *sad = NULL;
  1510. long_ad *lad = NULL;
  1511. struct allocExtDesc *aed;
  1512. int8_t etype;
  1513. uint8_t *ptr;
  1514. if (!epos->bh)
  1515. ptr = UDF_I_DATA(inode) + epos->offset -
  1516. udf_file_entry_alloc_offset(inode) +
  1517. UDF_I_LENEATTR(inode);
  1518. else
  1519. ptr = epos->bh->b_data + epos->offset;
  1520. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
  1521. adsize = sizeof(short_ad);
  1522. else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
  1523. adsize = sizeof(long_ad);
  1524. else
  1525. return -1;
  1526. if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
  1527. char *sptr, *dptr;
  1528. struct buffer_head *nbh;
  1529. int err, loffset;
  1530. kernel_lb_addr obloc = epos->block;
  1531. epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
  1532. obloc.partitionReferenceNum,
  1533. obloc.logicalBlockNum, &err);
  1534. if (!epos->block.logicalBlockNum)
  1535. return -1;
  1536. nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
  1537. epos->block,
  1538. 0));
  1539. if (!nbh)
  1540. return -1;
  1541. lock_buffer(nbh);
  1542. memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize);
  1543. set_buffer_uptodate(nbh);
  1544. unlock_buffer(nbh);
  1545. mark_buffer_dirty_inode(nbh, inode);
  1546. aed = (struct allocExtDesc *)(nbh->b_data);
  1547. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
  1548. aed->previousAllocExtLocation =
  1549. cpu_to_le32(obloc.logicalBlockNum);
  1550. if (epos->offset + adsize > inode->i_sb->s_blocksize) {
  1551. loffset = epos->offset;
  1552. aed->lengthAllocDescs = cpu_to_le32(adsize);
  1553. sptr = ptr - adsize;
  1554. dptr = nbh->b_data + sizeof(struct allocExtDesc);
  1555. memcpy(dptr, sptr, adsize);
  1556. epos->offset = sizeof(struct allocExtDesc) + adsize;
  1557. } else {
  1558. loffset = epos->offset + adsize;
  1559. aed->lengthAllocDescs = cpu_to_le32(0);
  1560. sptr = ptr;
  1561. epos->offset = sizeof(struct allocExtDesc);
  1562. if (epos->bh) {
  1563. aed = (struct allocExtDesc *)epos->bh->b_data;
  1564. aed->lengthAllocDescs =
  1565. cpu_to_le32(le32_to_cpu(
  1566. aed->lengthAllocDescs) + adsize);
  1567. } else {
  1568. UDF_I_LENALLOC(inode) += adsize;
  1569. mark_inode_dirty(inode);
  1570. }
  1571. }
  1572. if (UDF_SB(inode->i_sb)->s_udfrev >= 0x0200)
  1573. udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
  1574. epos->block.logicalBlockNum, sizeof(tag));
  1575. else
  1576. udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
  1577. epos->block.logicalBlockNum, sizeof(tag));
  1578. switch (UDF_I_ALLOCTYPE(inode)) {
  1579. case ICBTAG_FLAG_AD_SHORT:
  1580. sad = (short_ad *)sptr;
  1581. sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
  1582. inode->i_sb->s_blocksize);
  1583. sad->extPosition =
  1584. cpu_to_le32(epos->block.logicalBlockNum);
  1585. break;
  1586. case ICBTAG_FLAG_AD_LONG:
  1587. lad = (long_ad *)sptr;
  1588. lad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
  1589. inode->i_sb->s_blocksize);
  1590. lad->extLocation = cpu_to_lelb(epos->block);
  1591. memset(lad->impUse, 0x00, sizeof(lad->impUse));
  1592. break;
  1593. }
  1594. if (epos->bh) {
  1595. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1596. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
  1597. udf_update_tag(epos->bh->b_data, loffset);
  1598. else
  1599. udf_update_tag(epos->bh->b_data,
  1600. sizeof(struct allocExtDesc));
  1601. mark_buffer_dirty_inode(epos->bh, inode);
  1602. brelse(epos->bh);
  1603. } else {
  1604. mark_inode_dirty(inode);
  1605. }
  1606. epos->bh = nbh;
  1607. }
  1608. etype = udf_write_aext(inode, epos, eloc, elen, inc);
  1609. if (!epos->bh) {
  1610. UDF_I_LENALLOC(inode) += adsize;
  1611. mark_inode_dirty(inode);
  1612. } else {
  1613. aed = (struct allocExtDesc *)epos->bh->b_data;
  1614. aed->lengthAllocDescs =
  1615. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) +
  1616. adsize);
  1617. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1618. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
  1619. udf_update_tag(epos->bh->b_data,
  1620. epos->offset + (inc ? 0 : adsize));
  1621. else
  1622. udf_update_tag(epos->bh->b_data,
  1623. sizeof(struct allocExtDesc));
  1624. mark_buffer_dirty_inode(epos->bh, inode);
  1625. }
  1626. return etype;
  1627. }
  1628. int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
  1629. kernel_lb_addr eloc, uint32_t elen, int inc)
  1630. {
  1631. int adsize;
  1632. uint8_t *ptr;
  1633. short_ad *sad;
  1634. long_ad *lad;
  1635. if (!epos->bh)
  1636. ptr = UDF_I_DATA(inode) + epos->offset -
  1637. udf_file_entry_alloc_offset(inode) +
  1638. UDF_I_LENEATTR(inode);
  1639. else
  1640. ptr = epos->bh->b_data + epos->offset;
  1641. switch (UDF_I_ALLOCTYPE(inode)) {
  1642. case ICBTAG_FLAG_AD_SHORT:
  1643. sad = (short_ad *)ptr;
  1644. sad->extLength = cpu_to_le32(elen);
  1645. sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
  1646. adsize = sizeof(short_ad);
  1647. break;
  1648. case ICBTAG_FLAG_AD_LONG:
  1649. lad = (long_ad *)ptr;
  1650. lad->extLength = cpu_to_le32(elen);
  1651. lad->extLocation = cpu_to_lelb(eloc);
  1652. memset(lad->impUse, 0x00, sizeof(lad->impUse));
  1653. adsize = sizeof(long_ad);
  1654. break;
  1655. default:
  1656. return -1;
  1657. }
  1658. if (epos->bh) {
  1659. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1660. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) {
  1661. struct allocExtDesc *aed =
  1662. (struct allocExtDesc *)epos->bh->b_data;
  1663. udf_update_tag(epos->bh->b_data,
  1664. le32_to_cpu(aed->lengthAllocDescs) +
  1665. sizeof(struct allocExtDesc));
  1666. }
  1667. mark_buffer_dirty_inode(epos->bh, inode);
  1668. } else {
  1669. mark_inode_dirty(inode);
  1670. }
  1671. if (inc)
  1672. epos->offset += adsize;
  1673. return (elen >> 30);
  1674. }
  1675. int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
  1676. kernel_lb_addr *eloc, uint32_t *elen, int inc)
  1677. {
  1678. int8_t etype;
  1679. while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
  1680. (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
  1681. int block;
  1682. epos->block = *eloc;
  1683. epos->offset = sizeof(struct allocExtDesc);
  1684. brelse(epos->bh);
  1685. block = udf_get_lb_pblock(inode->i_sb, epos->block, 0);
  1686. epos->bh = udf_tread(inode->i_sb, block);
  1687. if (!epos->bh) {
  1688. udf_debug("reading block %d failed!\n", block);
  1689. return -1;
  1690. }
  1691. }
  1692. return etype;
  1693. }
  1694. int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
  1695. kernel_lb_addr *eloc, uint32_t *elen, int inc)
  1696. {
  1697. int alen;
  1698. int8_t etype;
  1699. uint8_t *ptr;
  1700. short_ad *sad;
  1701. long_ad *lad;
  1702. if (!epos->bh) {
  1703. if (!epos->offset)
  1704. epos->offset = udf_file_entry_alloc_offset(inode);
  1705. ptr = UDF_I_DATA(inode) + epos->offset -
  1706. udf_file_entry_alloc_offset(inode) +
  1707. UDF_I_LENEATTR(inode);
  1708. alen = udf_file_entry_alloc_offset(inode) +
  1709. UDF_I_LENALLOC(inode);
  1710. } else {
  1711. if (!epos->offset)
  1712. epos->offset = sizeof(struct allocExtDesc);
  1713. ptr = epos->bh->b_data + epos->offset;
  1714. alen = sizeof(struct allocExtDesc) +
  1715. le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
  1716. lengthAllocDescs);
  1717. }
  1718. switch (UDF_I_ALLOCTYPE(inode)) {
  1719. case ICBTAG_FLAG_AD_SHORT:
  1720. sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc);
  1721. if (!sad)
  1722. return -1;
  1723. etype = le32_to_cpu(sad->extLength) >> 30;
  1724. eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
  1725. eloc->partitionReferenceNum =
  1726. UDF_I_LOCATION(inode).partitionReferenceNum;
  1727. *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
  1728. break;
  1729. case ICBTAG_FLAG_AD_LONG:
  1730. lad = udf_get_filelongad(ptr, alen, &epos->offset, inc);
  1731. if (!lad)
  1732. return -1;
  1733. etype = le32_to_cpu(lad->extLength) >> 30;
  1734. *eloc = lelb_to_cpu(lad->extLocation);
  1735. *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
  1736. break;
  1737. default:
  1738. udf_debug("alloc_type = %d unsupported\n",
  1739. UDF_I_ALLOCTYPE(inode));
  1740. return -1;
  1741. }
  1742. return etype;
  1743. }
  1744. static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
  1745. kernel_lb_addr neloc, uint32_t nelen)
  1746. {
  1747. kernel_lb_addr oeloc;
  1748. uint32_t oelen;
  1749. int8_t etype;
  1750. if (epos.bh)
  1751. get_bh(epos.bh);
  1752. while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
  1753. udf_write_aext(inode, &epos, neloc, nelen, 1);
  1754. neloc = oeloc;
  1755. nelen = (etype << 30) | oelen;
  1756. }
  1757. udf_add_aext(inode, &epos, neloc, nelen, 1);
  1758. brelse(epos.bh);
  1759. return (nelen >> 30);
  1760. }
  1761. int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
  1762. kernel_lb_addr eloc, uint32_t elen)
  1763. {
  1764. struct extent_position oepos;
  1765. int adsize;
  1766. int8_t etype;
  1767. struct allocExtDesc *aed;
  1768. if (epos.bh) {
  1769. get_bh(epos.bh);
  1770. get_bh(epos.bh);
  1771. }
  1772. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
  1773. adsize = sizeof(short_ad);
  1774. else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
  1775. adsize = sizeof(long_ad);
  1776. else
  1777. adsize = 0;
  1778. oepos = epos;
  1779. if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
  1780. return -1;
  1781. while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
  1782. udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
  1783. if (oepos.bh != epos.bh) {
  1784. oepos.block = epos.block;
  1785. brelse(oepos.bh);
  1786. get_bh(epos.bh);
  1787. oepos.bh = epos.bh;
  1788. oepos.offset = epos.offset - adsize;
  1789. }
  1790. }
  1791. memset(&eloc, 0x00, sizeof(kernel_lb_addr));
  1792. elen = 0;
  1793. if (epos.bh != oepos.bh) {
  1794. udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
  1795. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1796. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1797. if (!oepos.bh) {
  1798. UDF_I_LENALLOC(inode) -= (adsize * 2);
  1799. mark_inode_dirty(inode);
  1800. } else {
  1801. aed = (struct allocExtDesc *)oepos.bh->b_data;
  1802. aed->lengthAllocDescs =
  1803. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
  1804. (2 * adsize));
  1805. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1806. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
  1807. udf_update_tag(oepos.bh->b_data,
  1808. oepos.offset - (2 * adsize));
  1809. else
  1810. udf_update_tag(oepos.bh->b_data,
  1811. sizeof(struct allocExtDesc));
  1812. mark_buffer_dirty_inode(oepos.bh, inode);
  1813. }
  1814. } else {
  1815. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1816. if (!oepos.bh) {
  1817. UDF_I_LENALLOC(inode) -= adsize;
  1818. mark_inode_dirty(inode);
  1819. } else {
  1820. aed = (struct allocExtDesc *)oepos.bh->b_data;
  1821. aed->lengthAllocDescs =
  1822. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
  1823. adsize);
  1824. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1825. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
  1826. udf_update_tag(oepos.bh->b_data,
  1827. epos.offset - adsize);
  1828. else
  1829. udf_update_tag(oepos.bh->b_data,
  1830. sizeof(struct allocExtDesc));
  1831. mark_buffer_dirty_inode(oepos.bh, inode);
  1832. }
  1833. }
  1834. brelse(epos.bh);
  1835. brelse(oepos.bh);
  1836. return (elen >> 30);
  1837. }
  1838. int8_t inode_bmap(struct inode *inode, sector_t block,
  1839. struct extent_position *pos, kernel_lb_addr *eloc,
  1840. uint32_t *elen, sector_t *offset)
  1841. {
  1842. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  1843. loff_t lbcount = 0, bcount =
  1844. (loff_t) block << blocksize_bits;
  1845. int8_t etype;
  1846. if (block < 0) {
  1847. printk(KERN_ERR "udf: inode_bmap: block < 0\n");
  1848. return -1;
  1849. }
  1850. pos->offset = 0;
  1851. pos->block = UDF_I_LOCATION(inode);
  1852. pos->bh = NULL;
  1853. *elen = 0;
  1854. do {
  1855. etype = udf_next_aext(inode, pos, eloc, elen, 1);
  1856. if (etype == -1) {
  1857. *offset = (bcount - lbcount) >> blocksize_bits;
  1858. UDF_I_LENEXTENTS(inode) = lbcount;
  1859. return -1;
  1860. }
  1861. lbcount += *elen;
  1862. } while (lbcount <= bcount);
  1863. *offset = (bcount + *elen - lbcount) >> blocksize_bits;
  1864. return etype;
  1865. }
  1866. long udf_block_map(struct inode *inode, sector_t block)
  1867. {
  1868. kernel_lb_addr eloc;
  1869. uint32_t elen;
  1870. sector_t offset;
  1871. struct extent_position epos = {};
  1872. int ret;
  1873. lock_kernel();
  1874. if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
  1875. (EXT_RECORDED_ALLOCATED >> 30))
  1876. ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
  1877. else
  1878. ret = 0;
  1879. unlock_kernel();
  1880. brelse(epos.bh);
  1881. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV))
  1882. return udf_fixed_to_variable(ret);
  1883. else
  1884. return ret;
  1885. }