Re: [RFC][PATCH] filesystem: VMUFAT filesystem
- From: Paul Mundt <lethal@xxxxxxxxxxxx>
- Date: Mon, 16 Feb 2009 12:15:24 +0900
On Sat, Feb 14, 2009 at 09:16:59PM +0000, Adrian McMenamin wrote:
+#include <linux/module.h>Why do you have an mtd include?
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/slab.h>
+#include <linux/blkdev.h>
+#include <linux/buffer_head.h>
+#include <linux/mtd/mtd.h>
+#include "vmufat.h"
+
+struct dentry *vmufat_inode_lookup(struct inode *in, struct dentry *dent,[snip]
+ struct nameidata *nd)
+{
+ sb = in->i_sb;
+ vmudetails = (struct memcard *)sb->s_fs_info;
All of your sb->s_fs_info casts are superfluous. Do not cast void
pointers.
+ if (!ino || IS_ERR(ino)) {In the IS_ERR case, you can use PTR_ERR for setting the error value.
+ error = -EACCES;
+ goto release_bh;
+ }
Throughout most of this code you completely ignore the error value that
is handed down and invent your own instead, making debugging far more
painful than it needs to be.
+ /* do we need to move to the next block in the directory? */
+ if ((fno / 0x10) > (vmudetails->dir_bnum - blck_read)) {
+ brelse(bh);
+ blck_read--;
Was the extra vowel really that much more work to write out?
+ /* BCD timestamp it */This should be abstracted out in to a separate function, and you can get
+ 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->b_data[z + 0x10] = bcd_from_u8(century);
+ u8year = year + 80;
+ if (u8year > 99)
+ u8year = u8year - 100;
+
+ bh->b_data[z + 0x11] = bcd_from_u8(u8year);
+ bh->b_data[z + 0x12] = bcd_from_u8((__u8) month);
+ bh->b_data[z + 0x13] =
+ bcd_from_u8((__u8) day - day_n[month - 1] + 1);
+ bh->b_data[z + 0x14] =
+ bcd_from_u8((__u8) ((unix_date / 3600) % 24));
+ bh->b_data[z + 0x15] = bcd_from_u8((__u8) ((unix_date / 60) % 60));
+ bh->b_data[z + 0x16] = bcd_from_u8((__u8) (unix_date % 60));
+
rid of most of this hand-rolled time mangling by using the rtc lib
routines.
Additionally, all of the bcd conversion code is superfluous, since you
can include linux/bcd.h and use bin2bcd and bcd2bin directly.
+static int vmufat_inode_rename(struct inode *in_source,Just get rid of this if you aren't going to support it.
+ struct dentry *de_source,
+ struct inode *in_target,
+ struct dentry *de_target)
+{
+ return -EPERM;
+}
+
+ saved_file =Error handling?
+ kmalloc(sizeof(struct vmufat_file_info), GFP_KERNEL);
+
+ }
+ /* Now every other block */
+ else {
Please refrain from adopting magical coding styles.
+ }Lots of superfluous whitespace.
+
+ }
+
+
+ }
+
+
+ readbuf = kzalloc(count, GFP_KERNEL);Again, no error handling.
+ /* Traverse through FAT to read the blocks in */
+ x = 0;
+static int vmufat_file_open(struct inode *in, struct file *f)You should be able to kill this off, also.
+{
+ return 0;
+}
+
+__u8 bcd_from_u8(__u8 num)As already mentioned, these are already in linux/bcd.h.
+{
+ __u8 topnib = num / 10;
+ __u8 botnib = num % 10;
+ return topnib << 4 | botnib;
+}
+
+inline int int_from_bcd(__u8 bcd)
+{
+ int topnib = (bcd >> 4) & 0x000f;
+ int botnib = bcd & 0x000f;
+
+ return (topnib * 10) + botnib;
+}
+
+static void vmufat_put_super(struct super_block *sb)
+{
+ struct memcard *vmudetails;
+ sb->s_dev = 0;
+ vmudetails = (struct memcard *) (sb->s_fs_info);
+ kfree(vmudetails);
vmudetails is completely unused here, just kfree sb->s_fs_info.
+ /* BCD timestamp it */
+ 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->b_data[z + 0x10] = bcd_from_u8(century);
+ u8year = year + 80;
+ if (u8year > 99)
+ u8year = u8year - 100;
+ bh->b_data[z + 0x11] = bcd_from_u8(u8year);
+ bh->b_data[z + 0x12] = bcd_from_u8((__u8) month);
+ bh->b_data[z + 0x13] =
+ bcd_from_u8((__u8) day - day_n[month - 1] + 1);
+ bh->b_data[z + 0x14] =
+ bcd_from_u8((__u8) ((unix_date / 3600) % 24));
+ bh->b_data[z + 0x15] = bcd_from_u8((__u8) ((unix_date / 60) % 60));
+ bh->b_data[z + 0x16] = bcd_from_u8((__u8) (unix_date % 60));
+
+ ((__u16 *) bh->b_data)[z / 2 + 0x0C] = cpu_to_le16(in->i_blocks);
+ if (inode_num != 0)
+ ((__u16 *) bh->b_data)[z / 2 + 0x0D] = 0;
+ else /* game */
+ ((__u16 *) bh->b_data)[z / 2 + 0x0D] = cpu_to_le16(1);
+ in->i_mtime.tv_sec = unix_date;
Again, all of this can be simplified using rtc lib and bcd routines.
+static int check_sb_format(struct buffer_head *bh)This magic value is used in lots of places, you should have a define for
+{
+ __u32 s_magic = 0x55555555;
+
it, and add it to linux/magic.h.
+ if (!((((__u32 *) bh->b_data)[0] == s_magic)
+ && (((__u32 *) bh->b_data)[1] == s_magic)
+ && (((__u32 *) bh->b_data)[2] == s_magic)
+ && (s_magic == ((__u32 *) bh->b_data)[3])))
+ return 0;
&&'s at the end of the line. You can also switch the if to a return and
kill off the else.
+ vmudata = kmalloc(sizeof(struct memcard), GFP_KERNEL);No error handling again. You will want to verify all of your kmallocs,
+
+ /* user blocks */
since you seem to have this issue a lot.
+ while ((erasesize /= 2) != 0)
+ log_2++; /* thanks to MR Brown */
+
+ sb->s_blocksize_bits = log_2;
ilog2()?
I've tried to skip over the bits already noted by Evgeniy, but you may
have already fixed up some of the issues noted above anyways.
Also, in the next iteration of this patch, please do not break the Cc
list and send multiple times to different lists, it makes it very
difficult to follow what is going on, especially if the threads of
conversation diverge.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- Re: [RFC][PATCH] filesystem: VMUFAT filesystem
- From: Adrian McMenamin
- Re: [RFC][PATCH] filesystem: VMUFAT filesystem
- References:
- [RFC][PATCH] filesystem: VMUFAT filesystem
- From: Adrian McMenamin
- [RFC][PATCH] filesystem: VMUFAT filesystem
- Prev by Date: Re: [cgroup or VFS ?] WARNING: at fs/namespace.c:636 mntput_no_expire+0xac/0xf2()
- Next by Date: Re: [RFD] Automatic suspend
- Previous by thread: Re: [RFC][PATCH] filesystem: VMUFAT filesystem
- Next by thread: Re: [RFC][PATCH] filesystem: VMUFAT filesystem
- Index(es):