super.c 50 KB

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