]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
fat: accessors for msdos_dir_entry 'start' fields
authorSteven J. Magnani <steve@digidescorp.com>
Sat, 21 Jul 2012 00:55:09 +0000 (10:55 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 25 Jul 2012 03:53:27 +0000 (13:53 +1000)
Simplify code by providing accessor functions for the directory entry
start cluster fields.

Signed-off-by: Steven J. Magnani <steve@digidescorp.com>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/fat/fat.h
fs/fat/inode.c
fs/fat/namei_msdos.c
fs/fat/namei_vfat.c

index fc35c5c69136e805b41ffa6102dc1878d68f7a3f..2deeeb86f331c8ad70d56300f1b5d4d5b155fe7b 100644 (file)
@@ -217,6 +217,21 @@ static inline void fat16_towchar(wchar_t *dst, const __u8 *src, size_t len)
 #endif
 }
 
+static inline int fat_get_start(const struct msdos_sb_info *sbi,
+                               const struct msdos_dir_entry *de)
+{
+       int cluster = le16_to_cpu(de->start);
+       if (sbi->fat_bits == 32)
+               cluster |= (le16_to_cpu(de->starthi) << 16);
+       return cluster;
+}
+
+static inline void fat_set_start(struct msdos_dir_entry *de, int cluster)
+{
+       de->start   = cpu_to_le16(cluster);
+       de->starthi = cpu_to_le16(cluster >> 16);
+}
+
 static inline void fatwchar_to16(__u8 *dst, const wchar_t *src, size_t len)
 {
 #ifdef __BIG_ENDIAN
index 09691fd0409073fa4484a075211143031155b14e..fd8e47cd898b294abe0c6c2c7207ba8fa59df61f 100644 (file)
@@ -369,10 +369,7 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
                inode->i_op = sbi->dir_ops;
                inode->i_fop = &fat_dir_operations;
 
-               MSDOS_I(inode)->i_start = le16_to_cpu(de->start);
-               if (sbi->fat_bits == 32)
-                       MSDOS_I(inode)->i_start |= (le16_to_cpu(de->starthi) << 16);
-
+               MSDOS_I(inode)->i_start = fat_get_start(sbi, de);
                MSDOS_I(inode)->i_logstart = MSDOS_I(inode)->i_start;
                error = fat_calc_dir_size(inode);
                if (error < 0)
@@ -385,9 +382,7 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
                inode->i_mode = fat_make_mode(sbi, de->attr,
                        ((sbi->options.showexec && !is_exec(de->name + 8))
                         ? S_IRUGO|S_IWUGO : S_IRWXUGO));
-               MSDOS_I(inode)->i_start = le16_to_cpu(de->start);
-               if (sbi->fat_bits == 32)
-                       MSDOS_I(inode)->i_start |= (le16_to_cpu(de->starthi) << 16);
+               MSDOS_I(inode)->i_start = fat_get_start(sbi, de);
 
                MSDOS_I(inode)->i_logstart = MSDOS_I(inode)->i_start;
                inode->i_size = le32_to_cpu(de->size);
@@ -618,8 +613,7 @@ retry:
        else
                raw_entry->size = cpu_to_le32(inode->i_size);
        raw_entry->attr = fat_make_attrs(inode);
-       raw_entry->start = cpu_to_le16(MSDOS_I(inode)->i_logstart);
-       raw_entry->starthi = cpu_to_le16(MSDOS_I(inode)->i_logstart >> 16);
+       fat_set_start(raw_entry, MSDOS_I(inode)->i_logstart);
        fat_time_unix2fat(sbi, &inode->i_mtime, &raw_entry->time,
                          &raw_entry->date, NULL);
        if (sbi->options.isvfat) {
index 70d993a9380572bac393a45f3dcb9896db404f9e..b0e12bf9f4a1c0fc32dc42facffaf84ff75fe880 100644 (file)
@@ -246,8 +246,7 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name,
        de.ctime_cs = 0;
        de.time = time;
        de.date = date;
-       de.start = cpu_to_le16(cluster);
-       de.starthi = cpu_to_le16(cluster >> 16);
+       fat_set_start(&de, cluster);
        de.size = 0;
 
        err = fat_add_entries(dir, &de, 1, sinfo);
@@ -530,9 +529,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
                mark_inode_dirty(old_inode);
 
        if (update_dotdot) {
-               int start = MSDOS_I(new_dir)->i_logstart;
-               dotdot_de->start = cpu_to_le16(start);
-               dotdot_de->starthi = cpu_to_le16(start >> 16);
+               fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
                mark_buffer_dirty_inode(dotdot_bh, old_inode);
                if (IS_DIRSYNC(new_dir)) {
                        err = sync_dirty_buffer(dotdot_bh);
@@ -572,9 +569,7 @@ error_dotdot:
        corrupt = 1;
 
        if (update_dotdot) {
-               int start = MSDOS_I(old_dir)->i_logstart;
-               dotdot_de->start = cpu_to_le16(start);
-               dotdot_de->starthi = cpu_to_le16(start >> 16);
+               fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
                mark_buffer_dirty_inode(dotdot_bh, old_inode);
                corrupt |= sync_dirty_buffer(dotdot_bh);
        }
index 6cc480652433b66a52c42cbcd3bde3f19e348f30..6a6d8c0715a1c16daf2b1ac53e8d461eb2253810 100644 (file)
@@ -651,8 +651,7 @@ shortname:
        de->time = de->ctime = time;
        de->date = de->cdate = de->adate = date;
        de->ctime_cs = time_cs;
-       de->start = cpu_to_le16(cluster);
-       de->starthi = cpu_to_le16(cluster >> 16);
+       fat_set_start(de, cluster);
        de->size = 0;
 out_free:
        __putname(uname);
@@ -965,9 +964,7 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
                mark_inode_dirty(old_inode);
 
        if (update_dotdot) {
-               int start = MSDOS_I(new_dir)->i_logstart;
-               dotdot_de->start = cpu_to_le16(start);
-               dotdot_de->starthi = cpu_to_le16(start >> 16);
+               fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
                mark_buffer_dirty_inode(dotdot_bh, old_inode);
                if (IS_DIRSYNC(new_dir)) {
                        err = sync_dirty_buffer(dotdot_bh);
@@ -1009,9 +1006,7 @@ error_dotdot:
        corrupt = 1;
 
        if (update_dotdot) {
-               int start = MSDOS_I(old_dir)->i_logstart;
-               dotdot_de->start = cpu_to_le16(start);
-               dotdot_de->starthi = cpu_to_le16(start >> 16);
+               fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
                mark_buffer_dirty_inode(dotdot_bh, old_inode);
                corrupt |= sync_dirty_buffer(dotdot_bh);
        }