filesystem: Vmufat filesystem, version 4
RFC PATCH 1/1 filesystem: Vmufat filesystem, version 4
I know this still has issues that others have raised but I wanted to post a version before the end of the long weekend...
As before - some documentation about the filesystem:
http://mc.pp.se/dc/vms/flashmem.html
A shell filesystem (eg for mount over loopback) available here:
http://newgolddream.dyndns.info/pristine
A few people commented that this is a bit long for a single file - but it is comparable to other files in the filesystem hierarchy - comments welcome.
The filesystem is hardware independent but is also written on the basis that this is most likely to be used with a Dreamcast VMU - though it may be of more use to emulator writers in the end.
fs/Kconfig | 1 + fs/Makefile | 1 + fs/vmufat/Kconfig | 14 + fs/vmufat/Makefile | 7 + fs/vmufat/inode.c | 1362 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1385 insertions(+), 0 deletions(-)
---
fs/Kconfig +1 -0
@@ -176,6 +176,7 @@ source "fs/romfs/Kconfig" source "fs/sysv/Kconfig" source "fs/ufs/Kconfig" source "fs/exofs/Kconfig" +source "fs/vmufat/Kconfig" config NILFS2_FS tristate "NILFS2 file system support (EXPERIMENTAL)"
fs/Makefile +1 -0
@@ -124,3 +124,4 @@ obj-$(CONFIG_OCFS2_FS) += ocfs2/ obj-$(CONFIG_BTRFS_FS) += btrfs/ obj-$(CONFIG_GFS2_FS) += gfs2/ obj-$(CONFIG_EXOFS_FS) += exofs/ +obj-$(CONFIG_VMUFAT_FS) += vmufat/
fs/vmufat/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +config VMUFAT_FS + tristate "Dreamcast VMU FAT filesystem" + depends on BLOCK + help + This implements the simple FAT type filesystem found on SEGA + Dreamcast visual memory units. + + Dreamcast users who want to mount their VMUs to view the native + filesystem will say 'Y' here. The filesystem is hardware independent + but is not recommended for any serious use in other circumstances, so + just about everyone else should say 'N'. + + To compile this as a module say 'M' here. The module will be called + vmufat
fs/vmufat/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for VMUFAT filesystem +# + +obj-$(CONFIG_VMUFAT_FS) += vmufat.o + +vmufat-y := inode.o
fs/vmufat/inode.c new file +1362 -0
1,362 lines not on this page · raw message
Quoted 3 lines · Adrian McMenamin
I know this still has issues that others have raised but I wanted to post a version before the end of the long weekend...
Make sure all of the folks that had comments are included in the Cc on future versions. If they haven't seen the updated version and are therefore unable to comment on it, that is not an indicator that the issues have been addressed.
Reviewing code is tedious work at best, making people that have taken the time to participate in review do even more work to find updated versions that may or may not have addressed their issues is remarkably poor etiquette at best, especially when they haven't completed their review.
Timing is also not so important. This code has been in development off and on for the last 7 years, another weekend isn't going to make any difference. Additionally, rushing through versions when you know they haven't taken all of the concerns under advisement is only going to discourage people from taking the time out to review anyways.
Unless you plan on hacking on this for another 7 years, you may wish to heed some of these points, especially now that things are finally starting to take better shape. It would be a shame to see this bitrot now given that all of the heavy lifting is effectively done.
Quoted 4 lines
A few people commented that this is a bit long for a single file - but it is comparable to other files in the filesystem hierarchy - comments welcome.
Ultimately you have to think about whether splitting it up makes sense or not. Given that there are a lot of VMU related bits here that are separate from the file system itself, it wouldn't hurt to break things out a bit more logically. It's a lot to take in at once, especially for folks that aren't familiar with all of the different aspects that the fs touches upon.
Furthermore, the fact other file systems haven't done so is not an excuse for you not to, especially as their reasons for doing so might be valid (you of course haven't bothered citing what other file systems you are referring to, so one can only vaguely postulate, though at least the arguments for things like cramfs do not apply to vmufat).
You should also think about whether you really want to go down the road of decoupling this from the VMU device dependencies. vmufat is not and never will be a general purpose file system, the on-disk format, limitation in block numbering, etc. are all directly tied to the VMU itself. Since you cited emulators as a potential user, these should be emulating the VMU itself anyways before you worry about layering vmufat on top of it. Trying to position this as a general purpose file system will bring you a world of pain you really don't want.
Quoted 8 lines · Paul Mundt
Quoted 3 lines · Adrian McMenamin
I know this still has issues that others have raised but I wanted to post a version before the end of the long weekend...
Make sure all of the folks that had comments are included in the Cc on future versions. If they haven't seen the updated version and are therefore unable to comment on it, that is not an indicator that the issues have been addressed.
Fair point. Did think about this but wasn't sure what the correct etiquette is, as sometimes people don't want more email, but will do so in future.
Quoted 6 lines
Reviewing code is tedious work at best, making people that have taken the time to participate in review do even more work to find updated versions that may or may not have addressed their issues is remarkably poor etiquette at best, especially when they haven't completed their review.
As far as I can see the three issues I haven't addressed were posting a further patch to magic.h and a couple of *suggestions* about code style. I will fix these points in due course, for sure. I have taken on board, afaics, all the substantive points for which thanks
...
Quoted 5 lines
Quoted 5 lines
A few people commented that this is a bit long for a single file - but it is comparable to other files in the filesystem hierarchy - comments welcome.
...
Quoted 7 lines
Furthermore, the fact other file systems haven't done so is not an excuse for you not to, especially as their reasons for doing so might be valid (you of course haven't bothered citing what other file systems you are referring to, so one can only vaguely postulate, though at least the arguments for things like cramfs do not apply to vmufat).
I didn't say that it was - I was offering my explanation for having taken the decision to make it all one file and then seeing what the bounce back was... there are in fact a very large number of filesystems like this, not least of which of course is ext2 which has longer inode.c and super.c files than this inode.c
Quoted 8 lines
You should also think about whether you really want to go down the road of decoupling this from the VMU device dependencies. vmufat is not and never will be a general purpose file system, the on-disk format, limitation in block numbering, etc. are all directly tied to the VMU itself. Since you cited emulators as a potential user, these should be emulating the VMU itself anyways before you worry about layering vmufat on top of it. Trying to position this as a general purpose file system will bring you a world of pain you really don't want.
The two compromises are that on a failed read of a block it tries again (as experience suggest that fixes most issues with the flaky VMU hardware - though I doubt emulator builders will replicate that) and that it does not write out a new date for the "superblock" on a change of the filesystem - to avoid wear on the flash on the VMU, but again not an issue for most emulator writers - I think the Kconfig makes it pretty clear this isn't a general purpose filesystem.
Should any earlier reviewer want to see what changes I've made please have a look here:
http://newgolddream.dyndns.info/cgi-bin/gitweb.cgi
Hopefully that will make the changes from earlier versions a bit clearer.
Quoted 7 lines · On Monday 13 April 2009 17:40:43 Adrian McMenamin wrote:
Should any earlier reviewer want to see what changes I've made please have a look here:
http://newgolddream.dyndns.info/cgi-bin/gitweb.cgi
Hopefully that will make the changes from earlier versions a bit clearer.
if the changelog history is clean, then you could always ask for people to pull the whole history rather than the final diff between mainline. that's actually kind of preferred as it implicitly retains some of the logic behind decisions made and other ideas tried.
-mike
Quoted 7 lines · Adrian McMenamin
Quoted 5 lines · Paul Mundt
Reviewing code is tedious work at best, making people that have taken the time to participate in review do even more work to find updated versions that may or may not have addressed their issues is remarkably poor etiquette at best, especially when they haven't completed their review.
Quoted 5 lines
As far as I can see the three issues I haven't addressed were posting a further patch to
magic.hand a couple of *suggestions* about code style. I will fix these points in due course, for sure. I have taken on board, afaics, all the substantive points for which thanks
This got cut off, but the point remains that you have provided no incremental comments in your changelog to note what has changed across versions, so it's not obvious at first glance what issues have been addressed and which ones have not.
Likewise, folks that have started looking at the code have cut their review short pending an updated version with the aforementioned issues corrected. This is the primary reason why you want to make sure all of those nits are addressed and the Cc list maintained, especially if you are still in 'RFC' mode.
Quoted 7 lines
Quoted 6 lines
Furthermore, the fact other file systems haven't done so is not an excuse for you not to, especially as their reasons for doing so might be valid (you of course haven't bothered citing what other file systems you are referring to, so one can only vaguely postulate, though at least the arguments for things like cramfs do not apply to vmufat).
Quoted 6 lines
I didn't say that it was - I was offering my explanation for having taken the decision to make it all one file and then seeing what the bounce back was... there are in fact a very large number of filesystems like this, not least of which of course is ext2 which has longer
inode.candsuper.cfiles than thisinode.c
Lines of code is a terrible metric. There are a lot of things you can split out here that do not apply to other generic file systems. The inode.c/super.c is the typical split for the fs, but a lot of the code you are carrying around is for managing the on-disk format and other VMU-specific oddities. It is useful to split this out logically and compartmentalize where it makes sense, especially as there are far more people who can review the file system part than the VMU part.
Quoted 9 lines
Quoted 8 lines
You should also think about whether you really want to go down the road of decoupling this from the VMU device dependencies. vmufat is not and never will be a general purpose file system, the on-disk format, limitation in block numbering, etc. are all directly tied to the VMU itself. Since you cited emulators as a potential user, these should be emulating the VMU itself anyways before you worry about layering vmufat on top of it. Trying to position this as a general purpose file system will bring you a world of pain you really don't want.
Quoted 8 lines
The two compromises are that on a failed read of a block it tries again (as experience suggest that fixes most issues with the flaky VMU hardware - though I doubt emulator builders will replicate that) and that it does not write out a new date for the "superblock" on a change of the filesystem - to avoid wear on the flash on the VMU, but again not an issue for most emulator writers - I think the
Kconfigmakes it pretty clear this isn't a general purpose filesystem.
Whether these hacks belong in the fs at all or not is another issue entirely, but none of that addresses any of the things I noted.
This file system is tied directly to the VMU. Assumptions about the on-disk format, block numbering limitations, etc. are all VMU constraints, and papering over that in the Kconfig text is not sufficient. This file system is and always will be tied to the VMU, and you really do not want to decouple the two. What you do in loopback mode for testing is your own business, but this will not work in the way people expect on a fixed disk. You are only making things harder on yourself by insisting that this is somehow generic.
The file system at least wants a dependency on the VMU (and I suppose mtdblock) itself.
Quoted 11 lines · Paul Mundt
This file system is tied directly to the VMU. Assumptions about the on-disk format, block numbering limitations, etc. are all VMU constraints, and papering over that in the
Kconfigtext is not sufficient. This file system is and always will be tied to the VMU, and you really do not want to decouple the two. What you do in loopback mode for testing is your own business, but this will not work in the way people expect on a fixed disk. You are only making things harder on yourself by insisting that this is somehow generic.The file system at least wants a dependency on the VMU (and I suppose mtdblock) itself.
Why won't it work on a fixed disk "in the way people expect"? Granted they'd be eccentric to format a disk in this way but there is no inherent reason why this file system *has* to be tied to a VMU.
Quoted 11 lines · Adrian McMenamin
Quoted 9 lines · Paul Mundt
This file system is tied directly to the VMU. Assumptions about the on-disk format, block numbering limitations, etc. are all VMU constraints, and papering over that in the
Kconfigtext is not sufficient. This file system is and always will be tied to the VMU, and you really do not want to decouple the two. What you do in loopback mode for testing is your own business, but this will not work in the way people expect on a fixed disk. You are only making things harder on yourself by insisting that this is somehow generic.
Quoted 7 lines
Quoted 2 lines
The file system at least wants a dependency on the VMU (and I suppose mtdblock) itself.
Why won't it work on a fixed disk "in the way people expect"? Granted they'd be eccentric to format a disk in this way but there is no inherent reason why this file system *has* to be tied to a VMU.
Everything about the on-disk format is tied to the VMU. Until that sinks in, don't bother sending me email, thanks.
Quoted 3 lines · Paul Mundt
Quoted 1 line
Everything about the on-disk format is tied to the VMU. Until that sinks in, don't bother sending me email, thanks.
No, everything in the file system is dependent on the specification. The specification is not dependent on the hardware. Those are the facts.
Quoted 6 lines · On Tuesday 14 April 2009 03:16:15 Adrian McMenamin wrote:
Quoted 2 lines · Paul Mundt
Everything about the on-disk format is tied to the VMU. Until that sinks in, don't bother sending me email, thanks.
No, everything in the file system is dependent on the specification. The specification is not dependent on the hardware. Those are the facts.
i must be slow because i tend to agree with Adrian here. if the VMU is a simple block device, then while the filesystem format may have been tailored to the exact hardware layout of the VMU, it doesnt mean that the resulting filesystem spec will only work on that hardware. then again, i didnt read the entire source code from top to bottom ...
-mike
Hi Adrian.
I see that most of the point raised in last round has been addressed. An incremental changelog would be nice during this RFC phase so we know what has been changed from one version to the next.
Quoted 37 lines
fs/vmufat/inode.c new file +37
-0+/* +* write out the date in bcd format +* in the appropriate part of the +* directory entry +*/ +static unsigned long vmufat_save_bcd (char *bh,int z) +{ +unsigned char day, year, century, nl_day, month; +unsigned char u8year; +unsigned long unix_date =CURRENT_TIME .tv_sec; + + day = unix_date /86400 -3652 ; + year = day /365 ; + +if ((year +3 ) /4 +365 * year > day) + year--; + + day -= (year +3 ) /4 +365 * year; +if (day ==59 && !(year &3 )) { + nl_day = day; + month =2 ; + }else { + nl_day = (year &3 ) || day <=59 ? day : day -1 ; +for (month =0 ; month <12 ; month++) +if (day_n[month] > nl_day) +break ; + } + + century =19 ; +if (year >19 ) + century =20 ; + + bh[z +0x10 ] =bin2bcd (century); + u8year = year +80 ; +if (u8year >99 ) + u8year = u8year -100 ; +
fs/vmufat/inode.c line 325
Quoted 10 lines
fs/vmufat/inode.c new file +10
-0+ bh[z +0x11 ] =bin2bcd (u8year); + bh[z +0x12 ] =bin2bcd (month); + bh[z +0x13 ] = +bin2bcd (day - day_n[month -1 ] +1 ); + bh[z +0x14 ] = +bin2bcd ((unix_date /3600 ) %24 ); + bh[z +0x15 ] =bin2bcd ((unix_date /60 ) %60 ); + bh[z +0x16 ] =bin2bcd (unix_date %60 ); +return unix_date; +}
Can we get all these numbers replaced by a set of descriptive constants? You can then use the definition of the constants to more-or-less document the on-disk format.
You have it in several places - the above is just one of them.
I did not look into the rest of the filesystem this time, I may do so later.
Please ntoe that this part of the excercise is to make the filesystem ready to be reviewed by someone who knows how to write a filesystem. What I provide to you is only the janitorial level..
Sam
Al Viro
maintainerfs/vmufat/inode.c line 51
Quoted 8 lines · Adrian McMenamin
fs/vmufat/inode.c new file +8
-0+struct memcard { +long sb_bnum; +long fat_bnum; +long fat_len; +long dir_bnum; +long dir_len; +long numblocks; +};
Eh...
a) are any of those really signed?
b) can any of those be more than 32 bits?
fs/vmufat/inode.c line 56
Quoted 4 lines
fs/vmufat/inode.c new file +4
-0+struct vmufat_block_list { +struct list_head b_list; +int bno; +};
You've got to be kidding. So you want to keep a list of ints and do it that way? With separate allocation for every sodding one and a cyclic list going through the entire bunch?
Besides, 'int' is almost certainly a wrong type. I can buy 'u32', but...
Quoted 1 line
(quoted diff) +1
-0+ do {
...
Review
Quoted 1 line
(quoted diff) +1
-0+ } while (1);
er... that's highly unidiomatic (and fairly common in your code below). Any reasons for that?
Quoted 13 lines
fs/vmufat/inode.c new file +13
-0+ bh_fat > +vmufat_sb_bread (sb, nextblock); +if (!bh_fat) { + error = -EIO ; + goto fail; + } + + do { + fatdata = ((u16 *) bh_fat->b_data)[x]; + if (fatdata = FAT_UNALLOCATED) + break; /*empty block */ + if (--x < 0) { + put_bh(bh_fat); + if (--nextblock >= vmudetails->fat_bnum) {
fs/vmufat/inode.c line 220
Quoted 10 lines
fs/vmufat/inode.c new file +10
-0+ x =VMU_BLK_SZ ; + bh_fat =vmufat_sb_bread (sb, nextblock); +if (!bh_fat) { + error = -EIO ; + goto fail; + } + }else +break ; + } + }while (1 );
Off-by-twice and that should've been a couple of nested loops.
Quoted 10 lines
fs/vmufat/inode.c new file +10
-0+static u16 vmufat_get_fat (struct super_block *sb,long block) +{ +struct memcard *vmudetails = sb->s_fs_info; +struct buffer_head *bh; +int offset; +u16 block_content; +/* which block in the FAT */ + offset = block / (VMU_BLK_SZ /2 ); +if (offset >= vmudetails->fat_len) +return FAT_ERROR ;
fs/vmufat/inode.c line 255
Quoted 10 lines
fs/vmufat/inode.c new file +10
-0+ + bh =vmufat_sb_bread (sb, offset +1 + + vmudetails->fat_bnum - vmudetails->fat_len); +if (!bh) +return FAT_ERROR ; +/* look inside the block */ + block_content = ((u16 *)bh->b_data)[block % (VMU_BLK_SZ /2 )]; +put_bh (bh); +return block_content; +}
What's the endianness of that puppy?
fs/vmufat/inode.c line 353
Quoted 4 lines
fs/vmufat/inode.c new file +4
-0+ +/* Walk through blocks looking for place to write +* Is this an executible file? */ +if (imode &73 ) {
No comments. Really. There must be some limits on the language one is willing to use on public maillist, after all.
Quoted 67 lines
fs/vmufat/inode.c new file +67
-0+static int vmufat_readdir (struct file *filp,void *dirent,filldir_t filldir) +{ +int filenamelen, i, error =0 ; +struct vmufat_file_info *saved_file =NULL ; +struct dentry *dentry = filp->f_dentry; +struct inode *inode = dentry->d_inode; +struct super_block *sb = inode->i_sb; +struct memcard *vmudetails = sb->s_fs_info; +struct buffer_head *bh; + +int blck_read = vmudetails->dir_bnum; + bh =vmufat_sb_bread (sb, blck_read); +if (!bh) { + error = -EIO ; + goto out; + } + + i = filp->f_pos; + +/* handle . for this directory and .. for parent */ +switch ((unsigned int ) filp->f_pos) { +case 0 : +if (filldir (dirent,"." ,1 , i++, inode->i_ino,DT_DIR ) <0 ) + goto finish; + + filp->f_pos++; +case 1 : +if (filldir (dirent,".." ,2 , i++, + dentry->d_parent->d_inode->i_ino,DT_DIR ) <0 ) + goto finish; + + filp->f_pos++; +default : +break ; + } + +/* trap reading beyond the end of the directory */ +if ((i -2 ) > (vmudetails->dir_len *DIR_ENT_PER_BLK )) { + error = -EINVAL ; + goto release_bh; + } + + saved_file > +kmalloc (sizeof (struct vmufat_file_info ),GFP_KERNEL ); +if (!saved_file) { + error = -ENOMEM ; + goto release_bh; + } + + do { + if ((i - 2) / DIR_ENT_PER_BLK > + (vmudetails->dir_bnum - blck_read)) { + /* move to next block in directory */ + blck_read--; + if (vmudetails->dir_bnum - vmudetails->dir_len <> + blck_read) + break; + brelse(bh); + bh = vmufat_sb_bread(sb, blck_read); + if (!bh) { + kfree(saved_file); + error = -EIO; + goto out; + } + } + + saved_file->ftype = bh->b_data[vmufat_index(i - 2)]; + + if (saved_file->ftype = 0)
fs/vmufat/inode.c line 544
Quoted 10 lines
fs/vmufat/inode.c new file +10
-0+break ; + + saved_file->fblk > +le16_to_cpu (((u16 *) bh->b_data)[1 + +vmufat_index_16 (i -2 )]); +if (saved_file->fblk =0 ) + saved_file->fblk =VMUFAT_ZEROBLOCK ; + +memcpy (saved_file->fname, + bh->b_data +4 +vmufat_index (i -2 ),VMUFAT_NAMELEN ); + filenamelen =strlen (saved_file->fname);
Who said there will be NUL anywhere at all?
fs/vmufat/inode.c line 546
Quoted 2 lines
fs/vmufat/inode.c new file +2
-0+if (filenamelen >VMUFAT_NAMELEN ) + filenamelen =VMUFAT_NAMELEN ;
See above.
fs/vmufat/inode.c line 551
Quoted 5 lines
fs/vmufat/inode.c new file +5
-0+if (filldir + (dirent, saved_file->fname, filenamelen, i++, + saved_file->fblk,DT_REG ) <0 ) { + goto finish; + }
WTF do we bother with that copying, anyway?
Quoted 48 lines
fs/vmufat/inode.c new file +48
-0+static int vmufat_list_blocks (struct inode *in) +{ +struct vmufat_inode *vi =VMUFAT_I (in); +struct super_block *sb = in->i_sb; +long nextblock; +long ino = in->i_ino; +struct memcard *vmudetails; +int error; +struct list_head *iter, *iter2; +struct vmufat_block_list *vbl, *nvbl; +u16 fatdata; + + vmudetails = sb->s_fs_info; + nextblock = ino; +if (nextblock =VMUFAT_ZEROBLOCK ) + nextblock =0 ; + +/* Delete any previous list of blocks */ +list_for_each_safe (iter, iter2, &vi->blocks.b_list) { + vbl = list_entry(iter, struct vmufat_block_list, b_list); +list_del (iter); +kmem_cache_free (vmufat_blist_cachep, vbl); + } + vi->nblcks =0 ; +do { + vbl =kmem_cache_alloc (vmufat_blist_cachep, +GFP_KERNEL ); +if (!vbl) { + error = -ENOMEM ; + goto unwind_out; + } +INIT_LIST_HEAD (&vbl->b_list); + vbl->bno = nextblock; +list_add_tail (&vbl->b_list, &vi->blocks.b_list); + vi->nblcks++; + +/* Find next block in the FAT - if there is one */ + fatdata =vmufat_get_fat (sb, nextblock); +if (fatdata =FAT_UNALLOCATED ) { +printk (KERN_WARNING "VMUFAT: FAT table appears to have" +" been corrupted.\n" ); + error = -EIO ; + goto unwind_out; + } +if (fatdata =FAT_FILE_END ) +break ;/*end of file */ + nextblock = fatdata; + }while (1 );
fs/vmufat/inode.c line 662
Quoted 10 lines
fs/vmufat/inode.c new file +10
-0+ +return 0 ; + +unwind_out: +list_for_each_entry_safe (vbl, nvbl, &vi->blocks.b_list, b_list) { +list_del_init (&vbl->b_list); +kmem_cache_free (vmufat_blist_cachep, vbl); + } +return error; +}
And you call *that* on every block allocation?
Review
Quoted 1 line
(quoted diff) +1
-0+ if (le16_to_cpu(((u16 *) bh->b_data)
__le16 *, please, and the same for other places like that.
fs/vmufat/inode.c line 744
Quoted 11 lines
fs/vmufat/inode.c new file +10
-0+ [(y %DIR_ENT_PER_BLK ) * + DIR_REC_LEN / 2 + 0x01]) = ino) + break; +if ((((u8 *) bh->b_data)[0x01 + z] = +0x00 ) & ~(sb->s_flags &MS_RDONLY )) + inode->i_mode |=S_IWUGO ; +/* Is file executible - ie a game */ +if ((((u8 *) bh->b_data)[z] = +0xcc ) & ~(sb->s_flags &MS_NOEXEC )) + inode->i_mode |=S_IXUGO ;
a) there's such thing as local variables. Use them.
b) when you do that, do remember that names may be longer than one character.
c) linux-kernel is not an IOCCC. This & ~ above is a pure obfuscation.
fs/vmufat/inode.c line 774
Quoted 3 lines
fs/vmufat/inode.c new file +3
-0+static void vmufat_put_super (struct super_block *sb) +{ + sb->s_dev =0 ;
WTF for? Leave handling that to fs/super.c, please.
Quoted 19 lines
fs/vmufat/inode.c new file +18
-0+kfree (sb->s_fs_info); +} +/* Look through the FAT */ + nextblock = vmudetails->fat_bnum + vmudetails->fat_len -1 ; + x = sb->s_blocksize; + bh_fat =vmufat_sb_bread (sb, nextblock); +if (!bh_fat) { + error = -EIO ; + goto out; + } + + do { + fatdata = ((u16 *) bh_fat->b_data)[x]; + if (fatdata = FAT_UNALLOCATED) + free++; + if (--x < 0) { + brelse(bh_fat); + if (--nextblock >= vmudetails->fat_bnum) {
fs/vmufat/inode.c line 813
Quoted 10 lines
fs/vmufat/inode.c new file +10
-0+ x = sb->s_blocksize; + bh_fat =vmufat_sb_bread (sb, nextblock); +if (!bh_fat) { + error = -EIO ; + goto out; + } + }else +break ; + } + }while (1 );
Pardon me, but... what the hell is going on in that code? In particular, is there any reason for not making it a straightforward for() going through blocks and equally straightforward inner for() going through each block? BTW, there seems to be an off-by-factor-of-2 above nicely obfuscated by all that mess. Namely,
x = sb->s_blocksize; ((u16 *) bh_fat->b_data)[x];
will end up accessing data at offset 2 * blocksize, which is twice the size of actual block.
fs/vmufat/inode.c line 978
Quoted 10 lines
fs/vmufat/inode.c new file +10
-0+static int vmufat_unlink (struct inode *dir,struct dentry *dentry) +{ +struct inode *in; + + in = dentry->d_inode; +if (!in) +return -EIO ; +vmufat_delete_inode (in); +return 0 ; +}
And what happens when I open a file, unlink it and try to read?
Overall: code badly needs deobfuscation before anything else can be done with it.
Quoted 57 lines · Adrian McMenamin
I know this still has issues that others have raised but I wanted to post a version before the end of the long weekend...
As before - some documentation about the filesystem:
http://mc.pp.se/dc/vms/flashmem.htmlA shell filesystem (eg for mount over loopback) available here:
http://newgolddream.dyndns.info/pristineA few people commented that this is a bit long for a single file - but it is comparable to other files in the filesystem hierarchy - comments welcome.
The filesystem is hardware independent but is also written on the basis that this is most likely to be used with a Dreamcast VMU - though it may be of more use to emulator writers in the end.
fs/Kconfig | 1 + fs/Makefile | 1 + fs/vmufat/Kconfig | 14 + fs/vmufat/Makefile | 7 + fs/vmufat/inode.c | 1362 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1385 insertions(+), 0 deletions(-)Signed-off-by Adrian McMenamin <[email protected]>---
fs/Kconfig +1
-0@@ -176,6 +176,7 @@ source "fs/romfs/Kconfig" source "fs/sysv/Kconfig" source "fs/ufs/Kconfig" source "fs/exofs/Kconfig" +source "fs/vmufat/Kconfig" config NILFS2_FS tristate "NILFS2 file system support (EXPERIMENTAL)"fs/Makefile +1
-0@@ -124,3 +124,4 @@ obj-$(CONFIG_OCFS2_FS) += ocfs2/ obj-$(CONFIG_BTRFS_FS) += btrfs/ obj-$(CONFIG_GFS2_FS) += gfs2/ obj-$(CONFIG_EXOFS_FS) += exofs/ +obj-$(CONFIG_VMUFAT_FS) += vmufat/fs/vmufat/Kconfig new file +4
-0@@ -0,0 +1,14 @@ +config VMUFAT_FS + tristate "Dreamcast VMU FAT filesystem" + depends on BLOCK + help
fs/vmufat/Kconfig line 14
Quoted 10 lines
fs/vmufat/Kconfig new file +10
-0+ This implements the simple FAT type filesystem found on SEGA + Dreamcast visual memory units. + + Dreamcast users who want to mount their VMUs to view the native + filesystem will say 'Y' here. The filesystem is hardware independent + but is not recommended for any serious use in other circumstances, so + just about everyone else should say 'N'. + + To compile this as a module say 'M' here. The module will be called + vmufat
"vmufat.ko." ?
fs/vmufat/Kconfig
Quoted 4 lines
fs/vmufat/Kconfig new file +4
-0+static unsigned long vmufat_save_bcd(char *bh, int z) +{ + unsigned char day, year, century, nl_day, month; + unsigned char u8year;
u8year? Should this be "u8 u8year"?
Quoted 17 lines
fs/vmufat/Kconfig new file +17
-0+ unsigned long unix_date = CURRENT_TIME.tv_sec; + + day = unix_date / 86400 - 3652; + year = day / 365; + + if ((year + 3) / 4 + 365 * year > day) + year--; + + day -= (year + 3) / 4 + 365 * year; + if (day == 59 && !(year & 3)) { + nl_day = day; + month = 2; + } else { + nl_day = (year & 3) || day <= 59 ? day : day - 1; + for (month = 0; month < 12; month++) + if (day_n[month] > nl_day) + break;
fs/vmufat/Kconfig
Quoted 10 lines
fs/vmufat/Kconfig new file +10
-0+ } + + century = 19; + if (year > 19) + century = 20; + + bh[z + 0x10] = bin2bcd(century); + u8year = year + 80; + if (u8year > 99) + u8year = u8year - 100;
It would be nice to document when this stops working.
Quoted 10 lines
fs/vmufat/Kconfig new file +10
-0+ bh[z + 0x11] = bin2bcd(u8year); + bh[z + 0x12] = bin2bcd(month); + bh[z + 0x13] = + bin2bcd(day - day_n[month - 1] + 1); + bh[z + 0x14] = + bin2bcd((unix_date / 3600) % 24); + bh[z + 0x15] = bin2bcd((unix_date / 60) % 60); + bh[z + 0x16] = bin2bcd(unix_date % 60); + return unix_date; +}
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 12 lines · On Friday 24 April 2009 18:14:55 Pavel Machek wrote:
Quoted 11 lines · Adrian McMenamin
fs/vmufat/Kconfig new file +8
-0@@ -0,0 +1,14 @@ +config VMUFAT_FS + tristate "Dreamcast VMU FAT filesystem" + depends on BLOCK + help + This implements the simple FAT type filesystem found on SEGA + Dreamcast visual memory units. + + Dreamcast users who want to mount their VMUs to view the native
Quoted 8 lines
fs/vmufat/Kconfig line 14
Quoted 6 lines
fs/vmufat/Kconfig new file +6
-0+ filesystem will say 'Y' here. The filesystem is hardware independent + but is not recommended for any serious use in other circumstances, so + just about everyone else should say 'N'. + + To compile this as a module say 'M' here. The module will be called + vmufat"vmufat.ko." ?
no, the standard is to name it without extension. there should be a period there though as it's the end of the sentence ...
-mike
Quoted 22 lines · Mike Frysinger
Quoted 12 lines · On Friday 24 April 2009 18:14:55 Pavel Machek wrote:
Quoted 11 lines · Adrian McMenamin
fs/vmufat/Kconfig new file +8
-0@@ -0,0 +1,14 @@ +config VMUFAT_FS + tristate "Dreamcast VMU FAT filesystem" + depends on BLOCK + help + This implements the simple FAT type filesystem found on SEGA + Dreamcast visual memory units. + + Dreamcast users who want to mount their VMUs to view the nativeQuoted 8 lines
fs/vmufat/Kconfig line 14
Quoted 6 lines
fs/vmufat/Kconfig new file +6
-0+ filesystem will say 'Y' here. The filesystem is hardware independent + but is not recommended for any serious use in other circumstances, so + just about everyone else should say 'N'. + + To compile this as a module say 'M' here. The module will be called + vmufat"vmufat.ko." ?
Quoted 2 lines
no, the standard is to name it without extension. there should be a period there though as it's the end of the sentence ...
Ok, add that period at end of sentence, I stand corrected.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html