super.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075
  1. /*
  2. * super.c
  3. *
  4. * PURPOSE
  5. * Super block routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * DESCRIPTION
  8. * OSTA-UDF(tm) = Optical Storage Technology Association
  9. * Universal Disk Format.
  10. *
  11. * This code is based on version 2.00 of the UDF specification,
  12. * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
  13. * http://www.osta.org/
  14. * http://www.ecma.ch/
  15. * http://www.iso.org/
  16. *
  17. * COPYRIGHT
  18. * This file is distributed under the terms of the GNU General Public
  19. * License (GPL). Copies of the GPL can be obtained from:
  20. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  21. * Each contributing author retains all rights to their own work.
  22. *
  23. * (C) 1998 Dave Boynton
  24. * (C) 1998-2004 Ben Fennema
  25. * (C) 2000 Stelias Computing Inc
  26. *
  27. * HISTORY
  28. *
  29. * 09/24/98 dgb changed to allow compiling outside of kernel, and
  30. * added some debugging.
  31. * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
  32. * 10/16/98 attempting some multi-session support
  33. * 10/17/98 added freespace count for "df"
  34. * 11/11/98 gr added novrs option
  35. * 11/26/98 dgb added fileset,anchor mount options
  36. * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced vol descs
  37. * rewrote option handling based on isofs
  38. * 12/20/98 find the free space bitmap (if it exists)
  39. */
  40. #include "udfdecl.h"
  41. #include <linux/blkdev.h>
  42. #include <linux/slab.h>
  43. #include <linux/kernel.h>
  44. #include <linux/module.h>
  45. #include <linux/parser.h>
  46. #include <linux/stat.h>
  47. #include <linux/cdrom.h>
  48. #include <linux/nls.h>
  49. #include <linux/smp_lock.h>
  50. #include <linux/buffer_head.h>
  51. #include <linux/vfs.h>
  52. #include <linux/vmalloc.h>
  53. #include <asm/byteorder.h>
  54. #include <linux/udf_fs.h>
  55. #include "udf_sb.h"
  56. #include "udf_i.h"
  57. #include <linux/init.h>
  58. #include <asm/uaccess.h>
  59. #define VDS_POS_PRIMARY_VOL_DESC 0
  60. #define VDS_POS_UNALLOC_SPACE_DESC 1
  61. #define VDS_POS_LOGICAL_VOL_DESC 2
  62. #define VDS_POS_PARTITION_DESC 3
  63. #define VDS_POS_IMP_USE_VOL_DESC 4
  64. #define VDS_POS_VOL_DESC_PTR 5
  65. #define VDS_POS_TERMINATING_DESC 6
  66. #define VDS_POS_LENGTH 7
  67. static char error_buf[1024];
  68. /* These are the "meat" - everything else is stuffing */
  69. static int udf_fill_super(struct super_block *, void *, int);
  70. static void udf_put_super(struct super_block *);
  71. static void udf_write_super(struct super_block *);
  72. static int udf_remount_fs(struct super_block *, int *, char *);
  73. static int udf_check_valid(struct super_block *, int, int);
  74. static int udf_vrs(struct super_block *sb, int silent);
  75. static int udf_load_partition(struct super_block *, kernel_lb_addr *);
  76. static int udf_load_logicalvol(struct super_block *, struct buffer_head *,
  77. kernel_lb_addr *);
  78. static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad);
  79. static void udf_find_anchor(struct super_block *);
  80. static int udf_find_fileset(struct super_block *, kernel_lb_addr *,
  81. kernel_lb_addr *);
  82. static void udf_load_pvoldesc(struct super_block *, struct buffer_head *);
  83. static void udf_load_fileset(struct super_block *, struct buffer_head *,
  84. kernel_lb_addr *);
  85. static void udf_load_partdesc(struct super_block *, struct buffer_head *);
  86. static void udf_open_lvid(struct super_block *);
  87. static void udf_close_lvid(struct super_block *);
  88. static unsigned int udf_count_free(struct super_block *);
  89. static int udf_statfs(struct dentry *, struct kstatfs *);
  90. /* UDF filesystem type */
  91. static int udf_get_sb(struct file_system_type *fs_type,
  92. int flags, const char *dev_name, void *data,
  93. struct vfsmount *mnt)
  94. {
  95. return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
  96. }
  97. static struct file_system_type udf_fstype = {
  98. .owner = THIS_MODULE,
  99. .name = "udf",
  100. .get_sb = udf_get_sb,
  101. .kill_sb = kill_block_super,
  102. .fs_flags = FS_REQUIRES_DEV,
  103. };
  104. static struct kmem_cache *udf_inode_cachep;
  105. static struct inode *udf_alloc_inode(struct super_block *sb)
  106. {
  107. struct udf_inode_info *ei;
  108. ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep,
  109. GFP_KERNEL);
  110. if (!ei)
  111. return NULL;
  112. ei->i_unique = 0;
  113. ei->i_lenExtents = 0;
  114. ei->i_next_alloc_block = 0;
  115. ei->i_next_alloc_goal = 0;
  116. ei->i_strat4096 = 0;
  117. return &ei->vfs_inode;
  118. }
  119. static void udf_destroy_inode(struct inode *inode)
  120. {
  121. kmem_cache_free(udf_inode_cachep, UDF_I(inode));
  122. }
  123. static void init_once(void *foo, struct kmem_cache *cachep, unsigned long flags)
  124. {
  125. struct udf_inode_info *ei = (struct udf_inode_info *)foo;
  126. ei->i_ext.i_data = NULL;
  127. inode_init_once(&ei->vfs_inode);
  128. }
  129. static int init_inodecache(void)
  130. {
  131. udf_inode_cachep = kmem_cache_create("udf_inode_cache",
  132. sizeof(struct udf_inode_info),
  133. 0, (SLAB_RECLAIM_ACCOUNT |
  134. SLAB_MEM_SPREAD),
  135. init_once, NULL);
  136. if (udf_inode_cachep == NULL)
  137. return -ENOMEM;
  138. return 0;
  139. }
  140. static void destroy_inodecache(void)
  141. {
  142. kmem_cache_destroy(udf_inode_cachep);
  143. }
  144. /* Superblock operations */
  145. static const struct super_operations udf_sb_ops = {
  146. .alloc_inode = udf_alloc_inode,
  147. .destroy_inode = udf_destroy_inode,
  148. .write_inode = udf_write_inode,
  149. .delete_inode = udf_delete_inode,
  150. .clear_inode = udf_clear_inode,
  151. .put_super = udf_put_super,
  152. .write_super = udf_write_super,
  153. .statfs = udf_statfs,
  154. .remount_fs = udf_remount_fs,
  155. };
  156. struct udf_options {
  157. unsigned char novrs;
  158. unsigned int blocksize;
  159. unsigned int session;
  160. unsigned int lastblock;
  161. unsigned int anchor;
  162. unsigned int volume;
  163. unsigned short partition;
  164. unsigned int fileset;
  165. unsigned int rootdir;
  166. unsigned int flags;
  167. mode_t umask;
  168. gid_t gid;
  169. uid_t uid;
  170. struct nls_table *nls_map;
  171. };
  172. static int __init init_udf_fs(void)
  173. {
  174. int err;
  175. err = init_inodecache();
  176. if (err)
  177. goto out1;
  178. err = register_filesystem(&udf_fstype);
  179. if (err)
  180. goto out;
  181. return 0;
  182. out:
  183. destroy_inodecache();
  184. out1:
  185. return err;
  186. }
  187. static void __exit exit_udf_fs(void)
  188. {
  189. unregister_filesystem(&udf_fstype);
  190. destroy_inodecache();
  191. }
  192. module_init(init_udf_fs)
  193. module_exit(exit_udf_fs)
  194. /*
  195. * udf_parse_options
  196. *
  197. * PURPOSE
  198. * Parse mount options.
  199. *
  200. * DESCRIPTION
  201. * The following mount options are supported:
  202. *
  203. * gid= Set the default group.
  204. * umask= Set the default umask.
  205. * uid= Set the default user.
  206. * bs= Set the block size.
  207. * unhide Show otherwise hidden files.
  208. * undelete Show deleted files in lists.
  209. * adinicb Embed data in the inode (default)
  210. * noadinicb Don't embed data in the inode
  211. * shortad Use short ad's
  212. * longad Use long ad's (default)
  213. * nostrict Unset strict conformance
  214. * iocharset= Set the NLS character set
  215. *
  216. * The remaining are for debugging and disaster recovery:
  217. *
  218. * novrs Skip volume sequence recognition
  219. *
  220. * The following expect a offset from 0.
  221. *
  222. * session= Set the CDROM session (default= last session)
  223. * anchor= Override standard anchor location. (default= 256)
  224. * volume= Override the VolumeDesc location. (unused)
  225. * partition= Override the PartitionDesc location. (unused)
  226. * lastblock= Set the last block of the filesystem/
  227. *
  228. * The following expect a offset from the partition root.
  229. *
  230. * fileset= Override the fileset block location. (unused)
  231. * rootdir= Override the root directory location. (unused)
  232. * WARNING: overriding the rootdir to a non-directory may
  233. * yield highly unpredictable results.
  234. *
  235. * PRE-CONDITIONS
  236. * options Pointer to mount options string.
  237. * uopts Pointer to mount options variable.
  238. *
  239. * POST-CONDITIONS
  240. * <return> 1 Mount options parsed okay.
  241. * <return> 0 Error parsing mount options.
  242. *
  243. * HISTORY
  244. * July 1, 1997 - Andrew E. Mileski
  245. * Written, tested, and released.
  246. */
  247. enum {
  248. Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
  249. Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
  250. Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
  251. Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
  252. Opt_rootdir, Opt_utf8, Opt_iocharset,
  253. Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore
  254. };
  255. static match_table_t tokens = {
  256. {Opt_novrs, "novrs"},
  257. {Opt_nostrict, "nostrict"},
  258. {Opt_bs, "bs=%u"},
  259. {Opt_unhide, "unhide"},
  260. {Opt_undelete, "undelete"},
  261. {Opt_noadinicb, "noadinicb"},
  262. {Opt_adinicb, "adinicb"},
  263. {Opt_shortad, "shortad"},
  264. {Opt_longad, "longad"},
  265. {Opt_uforget, "uid=forget"},
  266. {Opt_uignore, "uid=ignore"},
  267. {Opt_gforget, "gid=forget"},
  268. {Opt_gignore, "gid=ignore"},
  269. {Opt_gid, "gid=%u"},
  270. {Opt_uid, "uid=%u"},
  271. {Opt_umask, "umask=%o"},
  272. {Opt_session, "session=%u"},
  273. {Opt_lastblock, "lastblock=%u"},
  274. {Opt_anchor, "anchor=%u"},
  275. {Opt_volume, "volume=%u"},
  276. {Opt_partition, "partition=%u"},
  277. {Opt_fileset, "fileset=%u"},
  278. {Opt_rootdir, "rootdir=%u"},
  279. {Opt_utf8, "utf8"},
  280. {Opt_iocharset, "iocharset=%s"},
  281. {Opt_err, NULL}
  282. };
  283. static int udf_parse_options(char *options, struct udf_options *uopt)
  284. {
  285. char *p;
  286. int option;
  287. uopt->novrs = 0;
  288. uopt->blocksize = 2048;
  289. uopt->partition = 0xFFFF;
  290. uopt->session = 0xFFFFFFFF;
  291. uopt->lastblock = 0;
  292. uopt->anchor = 0;
  293. uopt->volume = 0xFFFFFFFF;
  294. uopt->rootdir = 0xFFFFFFFF;
  295. uopt->fileset = 0xFFFFFFFF;
  296. uopt->nls_map = NULL;
  297. if (!options)
  298. return 1;
  299. while ((p = strsep(&options, ",")) != NULL) {
  300. substring_t args[MAX_OPT_ARGS];
  301. int token;
  302. if (!*p)
  303. continue;
  304. token = match_token(p, tokens, args);
  305. switch (token) {
  306. case Opt_novrs:
  307. uopt->novrs = 1;
  308. case Opt_bs:
  309. if (match_int(&args[0], &option))
  310. return 0;
  311. uopt->blocksize = option;
  312. break;
  313. case Opt_unhide:
  314. uopt->flags |= (1 << UDF_FLAG_UNHIDE);
  315. break;
  316. case Opt_undelete:
  317. uopt->flags |= (1 << UDF_FLAG_UNDELETE);
  318. break;
  319. case Opt_noadinicb:
  320. uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
  321. break;
  322. case Opt_adinicb:
  323. uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
  324. break;
  325. case Opt_shortad:
  326. uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
  327. break;
  328. case Opt_longad:
  329. uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
  330. break;
  331. case Opt_gid:
  332. if (match_int(args, &option))
  333. return 0;
  334. uopt->gid = option;
  335. break;
  336. case Opt_uid:
  337. if (match_int(args, &option))
  338. return 0;
  339. uopt->uid = option;
  340. break;
  341. case Opt_umask:
  342. if (match_octal(args, &option))
  343. return 0;
  344. uopt->umask = option;
  345. break;
  346. case Opt_nostrict:
  347. uopt->flags &= ~(1 << UDF_FLAG_STRICT);
  348. break;
  349. case Opt_session:
  350. if (match_int(args, &option))
  351. return 0;
  352. uopt->session = option;
  353. break;
  354. case Opt_lastblock:
  355. if (match_int(args, &option))
  356. return 0;
  357. uopt->lastblock = option;
  358. break;
  359. case Opt_anchor:
  360. if (match_int(args, &option))
  361. return 0;
  362. uopt->anchor = option;
  363. break;
  364. case Opt_volume:
  365. if (match_int(args, &option))
  366. return 0;
  367. uopt->volume = option;
  368. break;
  369. case Opt_partition:
  370. if (match_int(args, &option))
  371. return 0;
  372. uopt->partition = option;
  373. break;
  374. case Opt_fileset:
  375. if (match_int(args, &option))
  376. return 0;
  377. uopt->fileset = option;
  378. break;
  379. case Opt_rootdir:
  380. if (match_int(args, &option))
  381. return 0;
  382. uopt->rootdir = option;
  383. break;
  384. case Opt_utf8:
  385. uopt->flags |= (1 << UDF_FLAG_UTF8);
  386. break;
  387. #ifdef CONFIG_UDF_NLS
  388. case Opt_iocharset:
  389. uopt->nls_map = load_nls(args[0].from);
  390. uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
  391. break;
  392. #endif
  393. case Opt_uignore:
  394. uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
  395. break;
  396. case Opt_uforget:
  397. uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
  398. break;
  399. case Opt_gignore:
  400. uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
  401. break;
  402. case Opt_gforget:
  403. uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
  404. break;
  405. default:
  406. printk(KERN_ERR "udf: bad mount option \"%s\" "
  407. "or missing value\n", p);
  408. return 0;
  409. }
  410. }
  411. return 1;
  412. }
  413. void udf_write_super(struct super_block *sb)
  414. {
  415. lock_kernel();
  416. if (!(sb->s_flags & MS_RDONLY))
  417. udf_open_lvid(sb);
  418. sb->s_dirt = 0;
  419. unlock_kernel();
  420. }
  421. static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
  422. {
  423. struct udf_options uopt;
  424. uopt.flags = UDF_SB(sb)->s_flags;
  425. uopt.uid = UDF_SB(sb)->s_uid;
  426. uopt.gid = UDF_SB(sb)->s_gid;
  427. uopt.umask = UDF_SB(sb)->s_umask;
  428. if (!udf_parse_options(options, &uopt))
  429. return -EINVAL;
  430. UDF_SB(sb)->s_flags = uopt.flags;
  431. UDF_SB(sb)->s_uid = uopt.uid;
  432. UDF_SB(sb)->s_gid = uopt.gid;
  433. UDF_SB(sb)->s_umask = uopt.umask;
  434. if (UDF_SB_LVIDBH(sb)) {
  435. int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
  436. if (write_rev > UDF_MAX_WRITE_VERSION)
  437. *flags |= MS_RDONLY;
  438. }
  439. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  440. return 0;
  441. if (*flags & MS_RDONLY)
  442. udf_close_lvid(sb);
  443. else
  444. udf_open_lvid(sb);
  445. return 0;
  446. }
  447. /*
  448. * udf_set_blocksize
  449. *
  450. * PURPOSE
  451. * Set the block size to be used in all transfers.
  452. *
  453. * DESCRIPTION
  454. * To allow room for a DMA transfer, it is best to guess big when unsure.
  455. * This routine picks 2048 bytes as the blocksize when guessing. This
  456. * should be adequate until devices with larger block sizes become common.
  457. *
  458. * Note that the Linux kernel can currently only deal with blocksizes of
  459. * 512, 1024, 2048, 4096, and 8192 bytes.
  460. *
  461. * PRE-CONDITIONS
  462. * sb Pointer to _locked_ superblock.
  463. *
  464. * POST-CONDITIONS
  465. * sb->s_blocksize Blocksize.
  466. * sb->s_blocksize_bits log2 of blocksize.
  467. * <return> 0 Blocksize is valid.
  468. * <return> 1 Blocksize is invalid.
  469. *
  470. * HISTORY
  471. * July 1, 1997 - Andrew E. Mileski
  472. * Written, tested, and released.
  473. */
  474. static int udf_set_blocksize(struct super_block *sb, int bsize)
  475. {
  476. if (!sb_min_blocksize(sb, bsize)) {
  477. udf_debug("Bad block size (%d)\n", bsize);
  478. printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
  479. return 0;
  480. }
  481. return sb->s_blocksize;
  482. }
  483. static int udf_vrs(struct super_block *sb, int silent)
  484. {
  485. struct volStructDesc *vsd = NULL;
  486. int sector = 32768;
  487. int sectorsize;
  488. struct buffer_head *bh = NULL;
  489. int iso9660 = 0;
  490. int nsr02 = 0;
  491. int nsr03 = 0;
  492. /* Block size must be a multiple of 512 */
  493. if (sb->s_blocksize & 511)
  494. return 0;
  495. if (sb->s_blocksize < sizeof(struct volStructDesc))
  496. sectorsize = sizeof(struct volStructDesc);
  497. else
  498. sectorsize = sb->s_blocksize;
  499. sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
  500. udf_debug("Starting at sector %u (%ld byte sectors)\n",
  501. (sector >> sb->s_blocksize_bits), sb->s_blocksize);
  502. /* Process the sequence (if applicable) */
  503. for (; !nsr02 && !nsr03; sector += sectorsize) {
  504. /* Read a block */
  505. bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
  506. if (!bh)
  507. break;
  508. /* Look for ISO descriptors */
  509. vsd = (struct volStructDesc *)(bh->b_data +
  510. (sector &
  511. (sb->s_blocksize - 1)));
  512. if (vsd->stdIdent[0] == 0) {
  513. brelse(bh);
  514. break;
  515. } else
  516. if (!strncmp
  517. (vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) {
  518. iso9660 = sector;
  519. switch (vsd->structType) {
  520. case 0:
  521. udf_debug("ISO9660 Boot Record found\n");
  522. break;
  523. case 1:
  524. udf_debug
  525. ("ISO9660 Primary Volume Descriptor found\n");
  526. break;
  527. case 2:
  528. udf_debug
  529. ("ISO9660 Supplementary Volume Descriptor found\n");
  530. break;
  531. case 3:
  532. udf_debug
  533. ("ISO9660 Volume Partition Descriptor found\n");
  534. break;
  535. case 255:
  536. udf_debug
  537. ("ISO9660 Volume Descriptor Set Terminator found\n");
  538. break;
  539. default:
  540. udf_debug("ISO9660 VRS (%u) found\n",
  541. vsd->structType);
  542. break;
  543. }
  544. } else
  545. if (!strncmp
  546. (vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) {
  547. } else
  548. if (!strncmp
  549. (vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN)) {
  550. brelse(bh);
  551. break;
  552. } else
  553. if (!strncmp
  554. (vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) {
  555. nsr02 = sector;
  556. } else
  557. if (!strncmp
  558. (vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) {
  559. nsr03 = sector;
  560. }
  561. brelse(bh);
  562. }
  563. if (nsr03)
  564. return nsr03;
  565. else if (nsr02)
  566. return nsr02;
  567. else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768)
  568. return -1;
  569. else
  570. return 0;
  571. }
  572. /*
  573. * udf_find_anchor
  574. *
  575. * PURPOSE
  576. * Find an anchor volume descriptor.
  577. *
  578. * PRE-CONDITIONS
  579. * sb Pointer to _locked_ superblock.
  580. * lastblock Last block on media.
  581. *
  582. * POST-CONDITIONS
  583. * <return> 1 if not found, 0 if ok
  584. *
  585. * HISTORY
  586. * July 1, 1997 - Andrew E. Mileski
  587. * Written, tested, and released.
  588. */
  589. static void udf_find_anchor(struct super_block *sb)
  590. {
  591. int lastblock = UDF_SB_LASTBLOCK(sb);
  592. struct buffer_head *bh = NULL;
  593. uint16_t ident;
  594. uint32_t location;
  595. int i;
  596. if (lastblock) {
  597. int varlastblock = udf_variable_to_fixed(lastblock);
  598. int last[] = { lastblock, lastblock - 2,
  599. lastblock - 150, lastblock - 152,
  600. varlastblock, varlastblock - 2,
  601. varlastblock - 150, varlastblock - 152
  602. };
  603. lastblock = 0;
  604. /* Search for an anchor volume descriptor pointer */
  605. /* according to spec, anchor is in either:
  606. * block 256
  607. * lastblock-256
  608. * lastblock
  609. * however, if the disc isn't closed, it could be 512 */
  610. for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
  611. if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) {
  612. ident = location = 0;
  613. } else {
  614. ident =
  615. le16_to_cpu(((tag *) bh->b_data)->tagIdent);
  616. location =
  617. le32_to_cpu(((tag *) bh->b_data)->
  618. tagLocation);
  619. brelse(bh);
  620. }
  621. if (ident == TAG_IDENT_AVDP) {
  622. if (location == last[i] - UDF_SB_SESSION(sb)) {
  623. lastblock = UDF_SB_ANCHOR(sb)[0] =
  624. last[i] - UDF_SB_SESSION(sb);
  625. UDF_SB_ANCHOR(sb)[1] =
  626. last[i] - 256 - UDF_SB_SESSION(sb);
  627. } else if (location ==
  628. udf_variable_to_fixed(last[i]) -
  629. UDF_SB_SESSION(sb)) {
  630. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  631. lastblock = UDF_SB_ANCHOR(sb)[0] =
  632. udf_variable_to_fixed(last[i]) -
  633. UDF_SB_SESSION(sb);
  634. UDF_SB_ANCHOR(sb)[1] =
  635. lastblock - 256 -
  636. UDF_SB_SESSION(sb);
  637. } else
  638. udf_debug
  639. ("Anchor found at block %d, location mismatch %d.\n",
  640. last[i], location);
  641. } else if (ident == TAG_IDENT_FE
  642. || ident == TAG_IDENT_EFE) {
  643. lastblock = last[i];
  644. UDF_SB_ANCHOR(sb)[3] = 512;
  645. } else {
  646. if (last[i] < 256
  647. || !(bh = sb_bread(sb, last[i] - 256))) {
  648. ident = location = 0;
  649. } else {
  650. ident =
  651. le16_to_cpu(((tag *) bh->b_data)->
  652. tagIdent);
  653. location =
  654. le32_to_cpu(((tag *) bh->b_data)->
  655. tagLocation);
  656. brelse(bh);
  657. }
  658. if (ident == TAG_IDENT_AVDP &&
  659. location ==
  660. last[i] - 256 - UDF_SB_SESSION(sb)) {
  661. lastblock = last[i];
  662. UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
  663. } else {
  664. if (last[i] < 312 + UDF_SB_SESSION(sb)
  665. || !(bh =
  666. sb_bread(sb,
  667. last[i] - 312 -
  668. UDF_SB_SESSION(sb))))
  669. {
  670. ident = location = 0;
  671. } else {
  672. ident =
  673. le16_to_cpu(((tag *) bh->
  674. b_data)->
  675. tagIdent);
  676. location =
  677. le32_to_cpu(((tag *) bh->
  678. b_data)->
  679. tagLocation);
  680. brelse(bh);
  681. }
  682. if (ident == TAG_IDENT_AVDP &&
  683. location ==
  684. udf_variable_to_fixed(last[i]) -
  685. 256) {
  686. UDF_SET_FLAG(sb,
  687. UDF_FLAG_VARCONV);
  688. lastblock =
  689. udf_variable_to_fixed(last
  690. [i]);
  691. UDF_SB_ANCHOR(sb)[1] =
  692. lastblock - 256;
  693. }
  694. }
  695. }
  696. }
  697. }
  698. if (!lastblock) {
  699. /* We havn't found the lastblock. check 312 */
  700. if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) {
  701. ident = le16_to_cpu(((tag *) bh->b_data)->tagIdent);
  702. location =
  703. le32_to_cpu(((tag *) bh->b_data)->tagLocation);
  704. brelse(bh);
  705. if (ident == TAG_IDENT_AVDP && location == 256)
  706. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  707. }
  708. }
  709. for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
  710. if (UDF_SB_ANCHOR(sb)[i]) {
  711. if (!(bh = udf_read_tagged(sb,
  712. UDF_SB_ANCHOR(sb)[i],
  713. UDF_SB_ANCHOR(sb)[i],
  714. &ident))) {
  715. UDF_SB_ANCHOR(sb)[i] = 0;
  716. } else {
  717. brelse(bh);
  718. if ((ident != TAG_IDENT_AVDP) && (i ||
  719. (ident !=
  720. TAG_IDENT_FE
  721. && ident !=
  722. TAG_IDENT_EFE)))
  723. {
  724. UDF_SB_ANCHOR(sb)[i] = 0;
  725. }
  726. }
  727. }
  728. }
  729. UDF_SB_LASTBLOCK(sb) = lastblock;
  730. }
  731. static int
  732. udf_find_fileset(struct super_block *sb, kernel_lb_addr * fileset,
  733. kernel_lb_addr * root)
  734. {
  735. struct buffer_head *bh = NULL;
  736. long lastblock;
  737. uint16_t ident;
  738. if (fileset->logicalBlockNum != 0xFFFFFFFF ||
  739. fileset->partitionReferenceNum != 0xFFFF) {
  740. bh = udf_read_ptagged(sb, *fileset, 0, &ident);
  741. if (!bh)
  742. return 1;
  743. else if (ident != TAG_IDENT_FSD) {
  744. brelse(bh);
  745. return 1;
  746. }
  747. }
  748. if (!bh) { /* Search backwards through the partitions */
  749. kernel_lb_addr newfileset;
  750. return 1;
  751. for (newfileset.partitionReferenceNum = UDF_SB_NUMPARTS(sb) - 1;
  752. (newfileset.partitionReferenceNum != 0xFFFF &&
  753. fileset->logicalBlockNum == 0xFFFFFFFF &&
  754. fileset->partitionReferenceNum == 0xFFFF);
  755. newfileset.partitionReferenceNum--) {
  756. lastblock =
  757. UDF_SB_PARTLEN(sb,
  758. newfileset.partitionReferenceNum);
  759. newfileset.logicalBlockNum = 0;
  760. do {
  761. bh = udf_read_ptagged(sb, newfileset, 0,
  762. &ident);
  763. if (!bh) {
  764. newfileset.logicalBlockNum++;
  765. continue;
  766. }
  767. switch (ident) {
  768. case TAG_IDENT_SBD:
  769. {
  770. struct spaceBitmapDesc *sp;
  771. sp = (struct spaceBitmapDesc *)
  772. bh->b_data;
  773. newfileset.logicalBlockNum +=
  774. 1 +
  775. ((le32_to_cpu
  776. (sp->numOfBytes) +
  777. sizeof(struct
  778. spaceBitmapDesc) -
  779. 1)
  780. >> sb->s_blocksize_bits);
  781. brelse(bh);
  782. break;
  783. }
  784. case TAG_IDENT_FSD:
  785. {
  786. *fileset = newfileset;
  787. break;
  788. }
  789. default:
  790. {
  791. newfileset.logicalBlockNum++;
  792. brelse(bh);
  793. bh = NULL;
  794. break;
  795. }
  796. }
  797. }
  798. while (newfileset.logicalBlockNum < lastblock &&
  799. fileset->logicalBlockNum == 0xFFFFFFFF &&
  800. fileset->partitionReferenceNum == 0xFFFF);
  801. }
  802. }
  803. if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
  804. fileset->partitionReferenceNum != 0xFFFF) && bh) {
  805. udf_debug("Fileset at block=%d, partition=%d\n",
  806. fileset->logicalBlockNum,
  807. fileset->partitionReferenceNum);
  808. UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
  809. udf_load_fileset(sb, bh, root);
  810. brelse(bh);
  811. return 0;
  812. }
  813. return 1;
  814. }
  815. static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
  816. {
  817. struct primaryVolDesc *pvoldesc;
  818. time_t recording;
  819. long recording_usec;
  820. struct ustr instr;
  821. struct ustr outstr;
  822. pvoldesc = (struct primaryVolDesc *)bh->b_data;
  823. if (udf_stamp_to_time(&recording, &recording_usec,
  824. lets_to_cpu(pvoldesc->recordingDateAndTime))) {
  825. kernel_timestamp ts;
  826. ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
  827. udf_debug
  828. ("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
  829. recording, recording_usec, ts.year, ts.month, ts.day,
  830. ts.hour, ts.minute, ts.typeAndTimezone);
  831. UDF_SB_RECORDTIME(sb).tv_sec = recording;
  832. UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
  833. }
  834. if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) {
  835. if (udf_CS0toUTF8(&outstr, &instr)) {
  836. strncpy(UDF_SB_VOLIDENT(sb), outstr.u_name,
  837. outstr.u_len > 31 ? 31 : outstr.u_len);
  838. udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
  839. }
  840. }
  841. if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) {
  842. if (udf_CS0toUTF8(&outstr, &instr))
  843. udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
  844. }
  845. }
  846. static void
  847. udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
  848. kernel_lb_addr * root)
  849. {
  850. struct fileSetDesc *fset;
  851. fset = (struct fileSetDesc *)bh->b_data;
  852. *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
  853. UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
  854. udf_debug("Rootdir at block=%d, partition=%d\n",
  855. root->logicalBlockNum, root->partitionReferenceNum);
  856. }
  857. static void udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
  858. {
  859. struct partitionDesc *p;
  860. int i;
  861. p = (struct partitionDesc *)bh->b_data;
  862. for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
  863. udf_debug("Searching map: (%d == %d)\n",
  864. UDF_SB_PARTMAPS(sb)[i].s_partition_num,
  865. le16_to_cpu(p->partitionNumber));
  866. if (UDF_SB_PARTMAPS(sb)[i].s_partition_num ==
  867. le16_to_cpu(p->partitionNumber)) {
  868. UDF_SB_PARTLEN(sb, i) = le32_to_cpu(p->partitionLength); /* blocks */
  869. UDF_SB_PARTROOT(sb, i) =
  870. le32_to_cpu(p->partitionStartingLocation);
  871. if (le32_to_cpu(p->accessType) ==
  872. PD_ACCESS_TYPE_READ_ONLY)
  873. UDF_SB_PARTFLAGS(sb, i) |=
  874. UDF_PART_FLAG_READ_ONLY;
  875. if (le32_to_cpu(p->accessType) ==
  876. PD_ACCESS_TYPE_WRITE_ONCE)
  877. UDF_SB_PARTFLAGS(sb, i) |=
  878. UDF_PART_FLAG_WRITE_ONCE;
  879. if (le32_to_cpu(p->accessType) ==
  880. PD_ACCESS_TYPE_REWRITABLE)
  881. UDF_SB_PARTFLAGS(sb, i) |=
  882. UDF_PART_FLAG_REWRITABLE;
  883. if (le32_to_cpu(p->accessType) ==
  884. PD_ACCESS_TYPE_OVERWRITABLE)
  885. UDF_SB_PARTFLAGS(sb, i) |=
  886. UDF_PART_FLAG_OVERWRITABLE;
  887. if (!strcmp
  888. (p->partitionContents.ident,
  889. PD_PARTITION_CONTENTS_NSR02)
  890. || !strcmp(p->partitionContents.ident,
  891. PD_PARTITION_CONTENTS_NSR03)) {
  892. struct partitionHeaderDesc *phd;
  893. phd =
  894. (struct partitionHeaderDesc *)(p->
  895. partitionContentsUse);
  896. if (phd->unallocSpaceTable.extLength) {
  897. kernel_lb_addr loc =
  898. { le32_to_cpu(phd->
  899. unallocSpaceTable.
  900. extPosition), i };
  901. UDF_SB_PARTMAPS(sb)[i].s_uspace.
  902. s_table = udf_iget(sb, loc);
  903. UDF_SB_PARTFLAGS(sb, i) |=
  904. UDF_PART_FLAG_UNALLOC_TABLE;
  905. udf_debug
  906. ("unallocSpaceTable (part %d) @ %ld\n",
  907. i,
  908. UDF_SB_PARTMAPS(sb)[i].s_uspace.
  909. s_table->i_ino);
  910. }
  911. if (phd->unallocSpaceBitmap.extLength) {
  912. UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
  913. if (UDF_SB_PARTMAPS(sb)[i].s_uspace.
  914. s_bitmap != NULL) {
  915. UDF_SB_PARTMAPS(sb)[i].s_uspace.
  916. s_bitmap->s_extLength =
  917. le32_to_cpu(phd->
  918. unallocSpaceBitmap.
  919. extLength);
  920. UDF_SB_PARTMAPS(sb)[i].s_uspace.
  921. s_bitmap->s_extPosition =
  922. le32_to_cpu(phd->
  923. unallocSpaceBitmap.
  924. extPosition);
  925. UDF_SB_PARTFLAGS(sb, i) |=
  926. UDF_PART_FLAG_UNALLOC_BITMAP;
  927. udf_debug
  928. ("unallocSpaceBitmap (part %d) @ %d\n",
  929. i,
  930. UDF_SB_PARTMAPS(sb)[i].
  931. s_uspace.s_bitmap->
  932. s_extPosition);
  933. }
  934. }
  935. if (phd->partitionIntegrityTable.extLength)
  936. udf_debug
  937. ("partitionIntegrityTable (part %d)\n",
  938. i);
  939. if (phd->freedSpaceTable.extLength) {
  940. kernel_lb_addr loc =
  941. { le32_to_cpu(phd->freedSpaceTable.
  942. extPosition), i };
  943. UDF_SB_PARTMAPS(sb)[i].s_fspace.
  944. s_table = udf_iget(sb, loc);
  945. UDF_SB_PARTFLAGS(sb, i) |=
  946. UDF_PART_FLAG_FREED_TABLE;
  947. udf_debug
  948. ("freedSpaceTable (part %d) @ %ld\n",
  949. i,
  950. UDF_SB_PARTMAPS(sb)[i].s_fspace.
  951. s_table->i_ino);
  952. }
  953. if (phd->freedSpaceBitmap.extLength) {
  954. UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
  955. if (UDF_SB_PARTMAPS(sb)[i].s_fspace.
  956. s_bitmap != NULL) {
  957. UDF_SB_PARTMAPS(sb)[i].s_fspace.
  958. s_bitmap->s_extLength =
  959. le32_to_cpu(phd->
  960. freedSpaceBitmap.
  961. extLength);
  962. UDF_SB_PARTMAPS(sb)[i].s_fspace.
  963. s_bitmap->s_extPosition =
  964. le32_to_cpu(phd->
  965. freedSpaceBitmap.
  966. extPosition);
  967. UDF_SB_PARTFLAGS(sb, i) |=
  968. UDF_PART_FLAG_FREED_BITMAP;
  969. udf_debug
  970. ("freedSpaceBitmap (part %d) @ %d\n",
  971. i,
  972. UDF_SB_PARTMAPS(sb)[i].
  973. s_fspace.s_bitmap->
  974. s_extPosition);
  975. }
  976. }
  977. }
  978. break;
  979. }
  980. }
  981. if (i == UDF_SB_NUMPARTS(sb)) {
  982. udf_debug("Partition (%d) not found in partition map\n",
  983. le16_to_cpu(p->partitionNumber));
  984. } else {
  985. udf_debug
  986. ("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
  987. le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb, i),
  988. UDF_SB_PARTROOT(sb, i), UDF_SB_PARTLEN(sb, i));
  989. }
  990. }
  991. static int
  992. udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
  993. kernel_lb_addr * fileset)
  994. {
  995. struct logicalVolDesc *lvd;
  996. int i, j, offset;
  997. uint8_t type;
  998. lvd = (struct logicalVolDesc *)bh->b_data;
  999. UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
  1000. for (i = 0, offset = 0;
  1001. i < UDF_SB_NUMPARTS(sb)
  1002. && offset < le32_to_cpu(lvd->mapTableLength);
  1003. i++, offset +=
  1004. ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->
  1005. partitionMapLength) {
  1006. type =
  1007. ((struct genericPartitionMap *)
  1008. &(lvd->partitionMaps[offset]))->partitionMapType;
  1009. if (type == 1) {
  1010. struct genericPartitionMap1 *gpm1 =
  1011. (struct genericPartitionMap1 *)&(lvd->
  1012. partitionMaps
  1013. [offset]);
  1014. UDF_SB_PARTTYPE(sb, i) = UDF_TYPE1_MAP15;
  1015. UDF_SB_PARTVSN(sb, i) = le16_to_cpu(gpm1->volSeqNum);
  1016. UDF_SB_PARTNUM(sb, i) = le16_to_cpu(gpm1->partitionNum);
  1017. UDF_SB_PARTFUNC(sb, i) = NULL;
  1018. } else if (type == 2) {
  1019. struct udfPartitionMap2 *upm2 =
  1020. (struct udfPartitionMap2 *)&(lvd->
  1021. partitionMaps[offset]);
  1022. if (!strncmp
  1023. (upm2->partIdent.ident, UDF_ID_VIRTUAL,
  1024. strlen(UDF_ID_VIRTUAL))) {
  1025. if (le16_to_cpu
  1026. (((__le16 *) upm2->partIdent.
  1027. identSuffix)[0]) == 0x0150) {
  1028. UDF_SB_PARTTYPE(sb, i) =
  1029. UDF_VIRTUAL_MAP15;
  1030. UDF_SB_PARTFUNC(sb, i) =
  1031. udf_get_pblock_virt15;
  1032. } else
  1033. if (le16_to_cpu
  1034. (((__le16 *) upm2->partIdent.
  1035. identSuffix)[0]) == 0x0200) {
  1036. UDF_SB_PARTTYPE(sb, i) =
  1037. UDF_VIRTUAL_MAP20;
  1038. UDF_SB_PARTFUNC(sb, i) =
  1039. udf_get_pblock_virt20;
  1040. }
  1041. } else
  1042. if (!strncmp
  1043. (upm2->partIdent.ident, UDF_ID_SPARABLE,
  1044. strlen(UDF_ID_SPARABLE))) {
  1045. uint32_t loc;
  1046. uint16_t ident;
  1047. struct sparingTable *st;
  1048. struct sparablePartitionMap *spm =
  1049. (struct sparablePartitionMap *)&(lvd->
  1050. partitionMaps
  1051. [offset]);
  1052. UDF_SB_PARTTYPE(sb, i) = UDF_SPARABLE_MAP15;
  1053. UDF_SB_TYPESPAR(sb, i).s_packet_len =
  1054. le16_to_cpu(spm->packetLength);
  1055. for (j = 0; j < spm->numSparingTables; j++) {
  1056. loc =
  1057. le32_to_cpu(spm->
  1058. locSparingTable[j]);
  1059. UDF_SB_TYPESPAR(sb, i).s_spar_map[j] =
  1060. udf_read_tagged(sb, loc, loc,
  1061. &ident);
  1062. if (UDF_SB_TYPESPAR(sb, i).
  1063. s_spar_map[j] != NULL) {
  1064. st = (struct sparingTable *)
  1065. UDF_SB_TYPESPAR(sb,
  1066. i).
  1067. s_spar_map[j]->b_data;
  1068. if (ident != 0
  1069. || strncmp(st->sparingIdent.
  1070. ident,
  1071. UDF_ID_SPARING,
  1072. strlen
  1073. (UDF_ID_SPARING)))
  1074. {
  1075. brelse(UDF_SB_TYPESPAR
  1076. (sb,
  1077. i).
  1078. s_spar_map[j]);
  1079. UDF_SB_TYPESPAR(sb,
  1080. i).
  1081. s_spar_map[j] =
  1082. NULL;
  1083. }
  1084. }
  1085. }
  1086. UDF_SB_PARTFUNC(sb, i) = udf_get_pblock_spar15;
  1087. } else {
  1088. udf_debug("Unknown ident: %s\n",
  1089. upm2->partIdent.ident);
  1090. continue;
  1091. }
  1092. UDF_SB_PARTVSN(sb, i) = le16_to_cpu(upm2->volSeqNum);
  1093. UDF_SB_PARTNUM(sb, i) = le16_to_cpu(upm2->partitionNum);
  1094. }
  1095. udf_debug("Partition (%d:%d) type %d on volume %d\n",
  1096. i, UDF_SB_PARTNUM(sb, i), type, UDF_SB_PARTVSN(sb,
  1097. i));
  1098. }
  1099. if (fileset) {
  1100. long_ad *la = (long_ad *) & (lvd->logicalVolContentsUse[0]);
  1101. *fileset = lelb_to_cpu(la->extLocation);
  1102. udf_debug
  1103. ("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
  1104. fileset->logicalBlockNum, fileset->partitionReferenceNum);
  1105. }
  1106. if (lvd->integritySeqExt.extLength)
  1107. udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
  1108. return 0;
  1109. }
  1110. /*
  1111. * udf_load_logicalvolint
  1112. *
  1113. */
  1114. static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
  1115. {
  1116. struct buffer_head *bh = NULL;
  1117. uint16_t ident;
  1118. while (loc.extLength > 0 &&
  1119. (bh = udf_read_tagged(sb, loc.extLocation,
  1120. loc.extLocation, &ident)) &&
  1121. ident == TAG_IDENT_LVID) {
  1122. UDF_SB_LVIDBH(sb) = bh;
  1123. if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
  1124. udf_load_logicalvolint(sb,
  1125. leea_to_cpu(UDF_SB_LVID(sb)->
  1126. nextIntegrityExt));
  1127. if (UDF_SB_LVIDBH(sb) != bh)
  1128. brelse(bh);
  1129. loc.extLength -= sb->s_blocksize;
  1130. loc.extLocation++;
  1131. }
  1132. if (UDF_SB_LVIDBH(sb) != bh)
  1133. brelse(bh);
  1134. }
  1135. /*
  1136. * udf_process_sequence
  1137. *
  1138. * PURPOSE
  1139. * Process a main/reserve volume descriptor sequence.
  1140. *
  1141. * PRE-CONDITIONS
  1142. * sb Pointer to _locked_ superblock.
  1143. * block First block of first extent of the sequence.
  1144. * lastblock Lastblock of first extent of the sequence.
  1145. *
  1146. * HISTORY
  1147. * July 1, 1997 - Andrew E. Mileski
  1148. * Written, tested, and released.
  1149. */
  1150. static int
  1151. udf_process_sequence(struct super_block *sb, long block, long lastblock,
  1152. kernel_lb_addr * fileset)
  1153. {
  1154. struct buffer_head *bh = NULL;
  1155. struct udf_vds_record vds[VDS_POS_LENGTH];
  1156. struct generic_desc *gd;
  1157. struct volDescPtr *vdp;
  1158. int done = 0;
  1159. int i, j;
  1160. uint32_t vdsn;
  1161. uint16_t ident;
  1162. long next_s = 0, next_e = 0;
  1163. memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
  1164. /* Read the main descriptor sequence */
  1165. for (; (!done && block <= lastblock); block++) {
  1166. bh = udf_read_tagged(sb, block, block, &ident);
  1167. if (!bh)
  1168. break;
  1169. /* Process each descriptor (ISO 13346 3/8.3-8.4) */
  1170. gd = (struct generic_desc *)bh->b_data;
  1171. vdsn = le32_to_cpu(gd->volDescSeqNum);
  1172. switch (ident) {
  1173. case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
  1174. if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) {
  1175. vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum =
  1176. vdsn;
  1177. vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
  1178. }
  1179. break;
  1180. case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
  1181. if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) {
  1182. vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
  1183. vds[VDS_POS_VOL_DESC_PTR].block = block;
  1184. vdp = (struct volDescPtr *)bh->b_data;
  1185. next_s =
  1186. le32_to_cpu(vdp->nextVolDescSeqExt.
  1187. extLocation);
  1188. next_e =
  1189. le32_to_cpu(vdp->nextVolDescSeqExt.
  1190. extLength);
  1191. next_e = next_e >> sb->s_blocksize_bits;
  1192. next_e += next_s;
  1193. }
  1194. break;
  1195. case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
  1196. if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) {
  1197. vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum =
  1198. vdsn;
  1199. vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
  1200. }
  1201. break;
  1202. case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
  1203. if (!vds[VDS_POS_PARTITION_DESC].block)
  1204. vds[VDS_POS_PARTITION_DESC].block = block;
  1205. break;
  1206. case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
  1207. if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) {
  1208. vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum =
  1209. vdsn;
  1210. vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
  1211. }
  1212. break;
  1213. case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
  1214. if (vdsn >=
  1215. vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) {
  1216. vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum =
  1217. vdsn;
  1218. vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
  1219. }
  1220. break;
  1221. case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
  1222. vds[VDS_POS_TERMINATING_DESC].block = block;
  1223. if (next_e) {
  1224. block = next_s;
  1225. lastblock = next_e;
  1226. next_s = next_e = 0;
  1227. } else
  1228. done = 1;
  1229. break;
  1230. }
  1231. brelse(bh);
  1232. }
  1233. for (i = 0; i < VDS_POS_LENGTH; i++) {
  1234. if (vds[i].block) {
  1235. bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
  1236. &ident);
  1237. if (i == VDS_POS_PRIMARY_VOL_DESC)
  1238. udf_load_pvoldesc(sb, bh);
  1239. else if (i == VDS_POS_LOGICAL_VOL_DESC)
  1240. udf_load_logicalvol(sb, bh, fileset);
  1241. else if (i == VDS_POS_PARTITION_DESC) {
  1242. struct buffer_head *bh2 = NULL;
  1243. udf_load_partdesc(sb, bh);
  1244. for (j = vds[i].block + 1;
  1245. j < vds[VDS_POS_TERMINATING_DESC].block;
  1246. j++) {
  1247. bh2 = udf_read_tagged(sb, j, j, &ident);
  1248. gd = (struct generic_desc *)bh2->b_data;
  1249. if (ident == TAG_IDENT_PD)
  1250. udf_load_partdesc(sb, bh2);
  1251. brelse(bh2);
  1252. }
  1253. }
  1254. brelse(bh);
  1255. }
  1256. }
  1257. return 0;
  1258. }
  1259. /*
  1260. * udf_check_valid()
  1261. */
  1262. static int udf_check_valid(struct super_block *sb, int novrs, int silent)
  1263. {
  1264. long block;
  1265. if (novrs) {
  1266. udf_debug("Validity check skipped because of novrs option\n");
  1267. return 0;
  1268. }
  1269. /* Check that it is NSR02 compliant */
  1270. /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
  1271. else if ((block = udf_vrs(sb, silent)) == -1) {
  1272. udf_debug
  1273. ("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
  1274. if (!UDF_SB_LASTBLOCK(sb))
  1275. UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
  1276. return 0;
  1277. } else
  1278. return !block;
  1279. }
  1280. static int udf_load_partition(struct super_block *sb, kernel_lb_addr * fileset)
  1281. {
  1282. struct anchorVolDescPtr *anchor;
  1283. uint16_t ident;
  1284. struct buffer_head *bh;
  1285. long main_s, main_e, reserve_s, reserve_e;
  1286. int i, j;
  1287. if (!sb)
  1288. return 1;
  1289. for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
  1290. if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb,
  1291. UDF_SB_ANCHOR
  1292. (sb)[i],
  1293. UDF_SB_ANCHOR
  1294. (sb)[i],
  1295. &ident))) {
  1296. anchor = (struct anchorVolDescPtr *)bh->b_data;
  1297. /* Locate the main sequence */
  1298. main_s =
  1299. le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
  1300. main_e =
  1301. le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
  1302. main_e = main_e >> sb->s_blocksize_bits;
  1303. main_e += main_s;
  1304. /* Locate the reserve sequence */
  1305. reserve_s =
  1306. le32_to_cpu(anchor->reserveVolDescSeqExt.
  1307. extLocation);
  1308. reserve_e =
  1309. le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
  1310. reserve_e = reserve_e >> sb->s_blocksize_bits;
  1311. reserve_e += reserve_s;
  1312. brelse(bh);
  1313. /* Process the main & reserve sequences */
  1314. /* responsible for finding the PartitionDesc(s) */
  1315. if (!
  1316. (udf_process_sequence(sb, main_s, main_e, fileset)
  1317. && udf_process_sequence(sb, reserve_s, reserve_e,
  1318. fileset))) {
  1319. break;
  1320. }
  1321. }
  1322. }
  1323. if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) {
  1324. udf_debug("No Anchor block found\n");
  1325. return 1;
  1326. } else
  1327. udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
  1328. for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
  1329. switch (UDF_SB_PARTTYPE(sb, i)) {
  1330. case UDF_VIRTUAL_MAP15:
  1331. case UDF_VIRTUAL_MAP20:
  1332. {
  1333. kernel_lb_addr uninitialized_var(ino);
  1334. if (!UDF_SB_LASTBLOCK(sb)) {
  1335. UDF_SB_LASTBLOCK(sb) =
  1336. udf_get_last_block(sb);
  1337. udf_find_anchor(sb);
  1338. }
  1339. if (!UDF_SB_LASTBLOCK(sb)) {
  1340. udf_debug
  1341. ("Unable to determine Lastblock (For Virtual Partition)\n");
  1342. return 1;
  1343. }
  1344. for (j = 0; j < UDF_SB_NUMPARTS(sb); j++) {
  1345. if (j != i &&
  1346. UDF_SB_PARTVSN(sb,
  1347. i) ==
  1348. UDF_SB_PARTVSN(sb, j)
  1349. && UDF_SB_PARTNUM(sb,
  1350. i) ==
  1351. UDF_SB_PARTNUM(sb, j)) {
  1352. ino.partitionReferenceNum = j;
  1353. ino.logicalBlockNum =
  1354. UDF_SB_LASTBLOCK(sb) -
  1355. UDF_SB_PARTROOT(sb, j);
  1356. break;
  1357. }
  1358. }
  1359. if (j == UDF_SB_NUMPARTS(sb))
  1360. return 1;
  1361. if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
  1362. return 1;
  1363. if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP15) {
  1364. UDF_SB_TYPEVIRT(sb, i).s_start_offset =
  1365. udf_ext0_offset(UDF_SB_VAT(sb));
  1366. UDF_SB_TYPEVIRT(sb, i).s_num_entries =
  1367. (UDF_SB_VAT(sb)->i_size - 36) >> 2;
  1368. } else if (UDF_SB_PARTTYPE(sb, i) ==
  1369. UDF_VIRTUAL_MAP20) {
  1370. struct buffer_head *bh = NULL;
  1371. uint32_t pos;
  1372. pos = udf_block_map(UDF_SB_VAT(sb), 0);
  1373. bh = sb_bread(sb, pos);
  1374. if (!bh)
  1375. return 1;
  1376. UDF_SB_TYPEVIRT(sb, i).s_start_offset =
  1377. le16_to_cpu(((struct
  1378. virtualAllocationTable20
  1379. *)bh->b_data +
  1380. udf_ext0_offset
  1381. (UDF_SB_VAT(sb)))->
  1382. lengthHeader) +
  1383. udf_ext0_offset(UDF_SB_VAT(sb));
  1384. UDF_SB_TYPEVIRT(sb, i).s_num_entries =
  1385. (UDF_SB_VAT(sb)->i_size -
  1386. UDF_SB_TYPEVIRT(sb,
  1387. i).
  1388. s_start_offset) >> 2;
  1389. brelse(bh);
  1390. }
  1391. UDF_SB_PARTROOT(sb, i) =
  1392. udf_get_pblock(sb, 0, i, 0);
  1393. UDF_SB_PARTLEN(sb, i) =
  1394. UDF_SB_PARTLEN(sb,
  1395. ino.partitionReferenceNum);
  1396. }
  1397. }
  1398. }
  1399. return 0;
  1400. }
  1401. static void udf_open_lvid(struct super_block *sb)
  1402. {
  1403. if (UDF_SB_LVIDBH(sb)) {
  1404. int i;
  1405. kernel_timestamp cpu_time;
  1406. UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1407. UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1408. if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
  1409. UDF_SB_LVID(sb)->recordingDateAndTime =
  1410. cpu_to_lets(cpu_time);
  1411. UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
  1412. UDF_SB_LVID(sb)->descTag.descCRC =
  1413. cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
  1414. le16_to_cpu(UDF_SB_LVID(sb)->descTag.
  1415. descCRCLength), 0));
  1416. UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
  1417. for (i = 0; i < 16; i++)
  1418. if (i != 4)
  1419. UDF_SB_LVID(sb)->descTag.tagChecksum +=
  1420. ((uint8_t *) &
  1421. (UDF_SB_LVID(sb)->descTag))[i];
  1422. mark_buffer_dirty(UDF_SB_LVIDBH(sb));
  1423. }
  1424. }
  1425. static void udf_close_lvid(struct super_block *sb)
  1426. {
  1427. if (UDF_SB_LVIDBH(sb) &&
  1428. UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
  1429. int i;
  1430. kernel_timestamp cpu_time;
  1431. UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1432. UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1433. if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
  1434. UDF_SB_LVID(sb)->recordingDateAndTime =
  1435. cpu_to_lets(cpu_time);
  1436. if (UDF_MAX_WRITE_VERSION >
  1437. le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
  1438. UDF_SB_LVIDIU(sb)->maxUDFWriteRev =
  1439. cpu_to_le16(UDF_MAX_WRITE_VERSION);
  1440. if (UDF_SB_UDFREV(sb) >
  1441. le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
  1442. UDF_SB_LVIDIU(sb)->minUDFReadRev =
  1443. cpu_to_le16(UDF_SB_UDFREV(sb));
  1444. if (UDF_SB_UDFREV(sb) >
  1445. le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
  1446. UDF_SB_LVIDIU(sb)->minUDFWriteRev =
  1447. cpu_to_le16(UDF_SB_UDFREV(sb));
  1448. UDF_SB_LVID(sb)->integrityType =
  1449. cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
  1450. UDF_SB_LVID(sb)->descTag.descCRC =
  1451. cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
  1452. le16_to_cpu(UDF_SB_LVID(sb)->descTag.
  1453. descCRCLength), 0));
  1454. UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
  1455. for (i = 0; i < 16; i++)
  1456. if (i != 4)
  1457. UDF_SB_LVID(sb)->descTag.tagChecksum +=
  1458. ((uint8_t *) &
  1459. (UDF_SB_LVID(sb)->descTag))[i];
  1460. mark_buffer_dirty(UDF_SB_LVIDBH(sb));
  1461. }
  1462. }
  1463. /*
  1464. * udf_read_super
  1465. *
  1466. * PURPOSE
  1467. * Complete the specified super block.
  1468. *
  1469. * PRE-CONDITIONS
  1470. * sb Pointer to superblock to complete - never NULL.
  1471. * sb->s_dev Device to read suberblock from.
  1472. * options Pointer to mount options.
  1473. * silent Silent flag.
  1474. *
  1475. * HISTORY
  1476. * July 1, 1997 - Andrew E. Mileski
  1477. * Written, tested, and released.
  1478. */
  1479. static int udf_fill_super(struct super_block *sb, void *options, int silent)
  1480. {
  1481. int i;
  1482. struct inode *inode = NULL;
  1483. struct udf_options uopt;
  1484. kernel_lb_addr rootdir, fileset;
  1485. struct udf_sb_info *sbi;
  1486. uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
  1487. uopt.uid = -1;
  1488. uopt.gid = -1;
  1489. uopt.umask = 0;
  1490. sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
  1491. if (!sbi)
  1492. return -ENOMEM;
  1493. sb->s_fs_info = sbi;
  1494. memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
  1495. mutex_init(&sbi->s_alloc_mutex);
  1496. if (!udf_parse_options((char *)options, &uopt))
  1497. goto error_out;
  1498. if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
  1499. uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
  1500. udf_error(sb, "udf_read_super",
  1501. "utf8 cannot be combined with iocharset\n");
  1502. goto error_out;
  1503. }
  1504. #ifdef CONFIG_UDF_NLS
  1505. if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
  1506. uopt.nls_map = load_nls_default();
  1507. if (!uopt.nls_map)
  1508. uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
  1509. else
  1510. udf_debug("Using default NLS map\n");
  1511. }
  1512. #endif
  1513. if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
  1514. uopt.flags |= (1 << UDF_FLAG_UTF8);
  1515. fileset.logicalBlockNum = 0xFFFFFFFF;
  1516. fileset.partitionReferenceNum = 0xFFFF;
  1517. UDF_SB(sb)->s_flags = uopt.flags;
  1518. UDF_SB(sb)->s_uid = uopt.uid;
  1519. UDF_SB(sb)->s_gid = uopt.gid;
  1520. UDF_SB(sb)->s_umask = uopt.umask;
  1521. UDF_SB(sb)->s_nls_map = uopt.nls_map;
  1522. /* Set the block size for all transfers */
  1523. if (!udf_set_blocksize(sb, uopt.blocksize))
  1524. goto error_out;
  1525. if (uopt.session == 0xFFFFFFFF)
  1526. UDF_SB_SESSION(sb) = udf_get_last_session(sb);
  1527. else
  1528. UDF_SB_SESSION(sb) = uopt.session;
  1529. udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb));
  1530. UDF_SB_LASTBLOCK(sb) = uopt.lastblock;
  1531. UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0;
  1532. UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
  1533. UDF_SB_ANCHOR(sb)[3] = 256;
  1534. if (udf_check_valid(sb, uopt.novrs, silent)) { /* read volume recognition sequences */
  1535. printk("UDF-fs: No VRS found\n");
  1536. goto error_out;
  1537. }
  1538. udf_find_anchor(sb);
  1539. /* Fill in the rest of the superblock */
  1540. sb->s_op = &udf_sb_ops;
  1541. sb->dq_op = NULL;
  1542. sb->s_dirt = 0;
  1543. sb->s_magic = UDF_SUPER_MAGIC;
  1544. sb->s_time_gran = 1000;
  1545. if (udf_load_partition(sb, &fileset)) {
  1546. printk("UDF-fs: No partition found (1)\n");
  1547. goto error_out;
  1548. }
  1549. udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
  1550. if (UDF_SB_LVIDBH(sb)) {
  1551. uint16_t minUDFReadRev =
  1552. le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
  1553. uint16_t minUDFWriteRev =
  1554. le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
  1555. /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
  1556. if (minUDFReadRev > UDF_MAX_READ_VERSION) {
  1557. printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
  1558. le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
  1559. UDF_MAX_READ_VERSION);
  1560. goto error_out;
  1561. } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) {
  1562. sb->s_flags |= MS_RDONLY;
  1563. }
  1564. UDF_SB_UDFREV(sb) = minUDFWriteRev;
  1565. if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
  1566. UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
  1567. if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
  1568. UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
  1569. }
  1570. if (!UDF_SB_NUMPARTS(sb)) {
  1571. printk("UDF-fs: No partition found (2)\n");
  1572. goto error_out;
  1573. }
  1574. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1575. UDF_PART_FLAG_READ_ONLY) {
  1576. printk
  1577. ("UDF-fs: Partition marked readonly; forcing readonly mount\n");
  1578. sb->s_flags |= MS_RDONLY;
  1579. }
  1580. if (udf_find_fileset(sb, &fileset, &rootdir)) {
  1581. printk("UDF-fs: No fileset found\n");
  1582. goto error_out;
  1583. }
  1584. if (!silent) {
  1585. kernel_timestamp ts;
  1586. udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb));
  1587. udf_info
  1588. ("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
  1589. UDFFS_VERSION, UDFFS_DATE, UDF_SB_VOLIDENT(sb), ts.year,
  1590. ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone);
  1591. }
  1592. if (!(sb->s_flags & MS_RDONLY))
  1593. udf_open_lvid(sb);
  1594. /* Assign the root inode */
  1595. /* assign inodes by physical block number */
  1596. /* perhaps it's not extensible enough, but for now ... */
  1597. inode = udf_iget(sb, rootdir);
  1598. if (!inode) {
  1599. printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
  1600. rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
  1601. goto error_out;
  1602. }
  1603. /* Allocate a dentry for the root inode */
  1604. sb->s_root = d_alloc_root(inode);
  1605. if (!sb->s_root) {
  1606. printk("UDF-fs: Couldn't allocate root dentry\n");
  1607. iput(inode);
  1608. goto error_out;
  1609. }
  1610. sb->s_maxbytes = MAX_LFS_FILESIZE;
  1611. return 0;
  1612. error_out:
  1613. if (UDF_SB_VAT(sb))
  1614. iput(UDF_SB_VAT(sb));
  1615. if (UDF_SB_NUMPARTS(sb)) {
  1616. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1617. UDF_PART_FLAG_UNALLOC_TABLE)
  1618. iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.
  1619. s_table);
  1620. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1621. UDF_PART_FLAG_FREED_TABLE)
  1622. iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.
  1623. s_table);
  1624. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1625. UDF_PART_FLAG_UNALLOC_BITMAP)
  1626. UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_uspace);
  1627. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1628. UDF_PART_FLAG_FREED_BITMAP)
  1629. UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_fspace);
  1630. if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) ==
  1631. UDF_SPARABLE_MAP15) {
  1632. for (i = 0; i < 4; i++)
  1633. brelse(UDF_SB_TYPESPAR
  1634. (sb,
  1635. UDF_SB_PARTITION(sb)).s_spar_map[i]);
  1636. }
  1637. }
  1638. #ifdef CONFIG_UDF_NLS
  1639. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1640. unload_nls(UDF_SB(sb)->s_nls_map);
  1641. #endif
  1642. if (!(sb->s_flags & MS_RDONLY))
  1643. udf_close_lvid(sb);
  1644. brelse(UDF_SB_LVIDBH(sb));
  1645. UDF_SB_FREE(sb);
  1646. kfree(sbi);
  1647. sb->s_fs_info = NULL;
  1648. return -EINVAL;
  1649. }
  1650. void udf_error(struct super_block *sb, const char *function,
  1651. const char *fmt, ...)
  1652. {
  1653. va_list args;
  1654. if (!(sb->s_flags & MS_RDONLY)) {
  1655. /* mark sb error */
  1656. sb->s_dirt = 1;
  1657. }
  1658. va_start(args, fmt);
  1659. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1660. va_end(args);
  1661. printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
  1662. sb->s_id, function, error_buf);
  1663. }
  1664. void udf_warning(struct super_block *sb, const char *function,
  1665. const char *fmt, ...)
  1666. {
  1667. va_list args;
  1668. va_start(args, fmt);
  1669. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1670. va_end(args);
  1671. printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
  1672. sb->s_id, function, error_buf);
  1673. }
  1674. /*
  1675. * udf_put_super
  1676. *
  1677. * PURPOSE
  1678. * Prepare for destruction of the superblock.
  1679. *
  1680. * DESCRIPTION
  1681. * Called before the filesystem is unmounted.
  1682. *
  1683. * HISTORY
  1684. * July 1, 1997 - Andrew E. Mileski
  1685. * Written, tested, and released.
  1686. */
  1687. static void udf_put_super(struct super_block *sb)
  1688. {
  1689. int i;
  1690. if (UDF_SB_VAT(sb))
  1691. iput(UDF_SB_VAT(sb));
  1692. if (UDF_SB_NUMPARTS(sb)) {
  1693. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1694. UDF_PART_FLAG_UNALLOC_TABLE)
  1695. iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.
  1696. s_table);
  1697. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1698. UDF_PART_FLAG_FREED_TABLE)
  1699. iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.
  1700. s_table);
  1701. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1702. UDF_PART_FLAG_UNALLOC_BITMAP)
  1703. UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_uspace);
  1704. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1705. UDF_PART_FLAG_FREED_BITMAP)
  1706. UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_fspace);
  1707. if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) ==
  1708. UDF_SPARABLE_MAP15) {
  1709. for (i = 0; i < 4; i++)
  1710. brelse(UDF_SB_TYPESPAR
  1711. (sb,
  1712. UDF_SB_PARTITION(sb)).s_spar_map[i]);
  1713. }
  1714. }
  1715. #ifdef CONFIG_UDF_NLS
  1716. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1717. unload_nls(UDF_SB(sb)->s_nls_map);
  1718. #endif
  1719. if (!(sb->s_flags & MS_RDONLY))
  1720. udf_close_lvid(sb);
  1721. brelse(UDF_SB_LVIDBH(sb));
  1722. UDF_SB_FREE(sb);
  1723. kfree(sb->s_fs_info);
  1724. sb->s_fs_info = NULL;
  1725. }
  1726. /*
  1727. * udf_stat_fs
  1728. *
  1729. * PURPOSE
  1730. * Return info about the filesystem.
  1731. *
  1732. * DESCRIPTION
  1733. * Called by sys_statfs()
  1734. *
  1735. * HISTORY
  1736. * July 1, 1997 - Andrew E. Mileski
  1737. * Written, tested, and released.
  1738. */
  1739. static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
  1740. {
  1741. struct super_block *sb = dentry->d_sb;
  1742. buf->f_type = UDF_SUPER_MAGIC;
  1743. buf->f_bsize = sb->s_blocksize;
  1744. buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb));
  1745. buf->f_bfree = udf_count_free(sb);
  1746. buf->f_bavail = buf->f_bfree;
  1747. buf->f_files = (UDF_SB_LVIDBH(sb) ?
  1748. (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
  1749. le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) +
  1750. buf->f_bfree;
  1751. buf->f_ffree = buf->f_bfree;
  1752. /* __kernel_fsid_t f_fsid */
  1753. buf->f_namelen = UDF_NAME_LEN - 2;
  1754. return 0;
  1755. }
  1756. static unsigned char udf_bitmap_lookup[16] = {
  1757. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  1758. };
  1759. static unsigned int
  1760. udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
  1761. {
  1762. struct buffer_head *bh = NULL;
  1763. unsigned int accum = 0;
  1764. int index;
  1765. int block = 0, newblock;
  1766. kernel_lb_addr loc;
  1767. uint32_t bytes;
  1768. uint8_t value;
  1769. uint8_t *ptr;
  1770. uint16_t ident;
  1771. struct spaceBitmapDesc *bm;
  1772. lock_kernel();
  1773. loc.logicalBlockNum = bitmap->s_extPosition;
  1774. loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
  1775. bh = udf_read_ptagged(sb, loc, 0, &ident);
  1776. if (!bh) {
  1777. printk(KERN_ERR "udf: udf_count_free failed\n");
  1778. goto out;
  1779. } else if (ident != TAG_IDENT_SBD) {
  1780. brelse(bh);
  1781. printk(KERN_ERR "udf: udf_count_free failed\n");
  1782. goto out;
  1783. }
  1784. bm = (struct spaceBitmapDesc *)bh->b_data;
  1785. bytes = le32_to_cpu(bm->numOfBytes);
  1786. index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
  1787. ptr = (uint8_t *) bh->b_data;
  1788. while (bytes > 0) {
  1789. while ((bytes > 0) && (index < sb->s_blocksize)) {
  1790. value = ptr[index];
  1791. accum += udf_bitmap_lookup[value & 0x0f];
  1792. accum += udf_bitmap_lookup[value >> 4];
  1793. index++;
  1794. bytes--;
  1795. }
  1796. if (bytes) {
  1797. brelse(bh);
  1798. newblock = udf_get_lb_pblock(sb, loc, ++block);
  1799. bh = udf_tread(sb, newblock);
  1800. if (!bh) {
  1801. udf_debug("read failed\n");
  1802. goto out;
  1803. }
  1804. index = 0;
  1805. ptr = (uint8_t *) bh->b_data;
  1806. }
  1807. }
  1808. brelse(bh);
  1809. out:
  1810. unlock_kernel();
  1811. return accum;
  1812. }
  1813. static unsigned int
  1814. udf_count_free_table(struct super_block *sb, struct inode *table)
  1815. {
  1816. unsigned int accum = 0;
  1817. uint32_t elen;
  1818. kernel_lb_addr eloc;
  1819. int8_t etype;
  1820. struct extent_position epos;
  1821. lock_kernel();
  1822. epos.block = UDF_I_LOCATION(table);
  1823. epos.offset = sizeof(struct unallocSpaceEntry);
  1824. epos.bh = NULL;
  1825. while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
  1826. accum += (elen >> table->i_sb->s_blocksize_bits);
  1827. brelse(epos.bh);
  1828. unlock_kernel();
  1829. return accum;
  1830. }
  1831. static unsigned int udf_count_free(struct super_block *sb)
  1832. {
  1833. unsigned int accum = 0;
  1834. if (UDF_SB_LVIDBH(sb)) {
  1835. if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) >
  1836. UDF_SB_PARTITION(sb)) {
  1837. accum =
  1838. le32_to_cpu(UDF_SB_LVID(sb)->
  1839. freeSpaceTable[UDF_SB_PARTITION(sb)]);
  1840. if (accum == 0xFFFFFFFF)
  1841. accum = 0;
  1842. }
  1843. }
  1844. if (accum)
  1845. return accum;
  1846. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1847. UDF_PART_FLAG_UNALLOC_BITMAP) {
  1848. accum +=
  1849. udf_count_free_bitmap(sb,
  1850. UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
  1851. (sb)].s_uspace.
  1852. s_bitmap);
  1853. }
  1854. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1855. UDF_PART_FLAG_FREED_BITMAP) {
  1856. accum +=
  1857. udf_count_free_bitmap(sb,
  1858. UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
  1859. (sb)].s_fspace.
  1860. s_bitmap);
  1861. }
  1862. if (accum)
  1863. return accum;
  1864. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1865. UDF_PART_FLAG_UNALLOC_TABLE) {
  1866. accum +=
  1867. udf_count_free_table(sb,
  1868. UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
  1869. (sb)].s_uspace.
  1870. s_table);
  1871. }
  1872. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
  1873. UDF_PART_FLAG_FREED_TABLE) {
  1874. accum +=
  1875. udf_count_free_table(sb,
  1876. UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
  1877. (sb)].s_fspace.
  1878. s_table);
  1879. }
  1880. return accum;
  1881. }