FAT: Add new ioctl VFAT_IOCTL_GET_VOLUME_ID for reading the volume ID.
authorMike Lockwood <lockwood@android.com>
Sat, 15 Mar 2008 17:29:36 +0000 (13:29 -0400)
committerArve Hjønnevåg <arve@android.com>
Mon, 1 Jul 2013 20:40:20 +0000 (13:40 -0700)
Signed-off-by: Brian Swetland <swetland@google.com>
fs/fat/dir.c
fs/fat/fat.h
fs/fat/inode.c
include/uapi/linux/msdos_fs.h

index 7a6f02caf286d4fa20990b259dd5e4773eeff96e..ddfa4529e6ea923870daa7ae457ac0b1a9cf3918 100644 (file)
@@ -776,6 +776,13 @@ static int fat_ioctl_readdir(struct inode *inode, struct file *filp,
        return ret;
 }
 
+static int fat_ioctl_volume_id(struct inode *dir)
+{
+       struct super_block *sb = dir->i_sb;
+       struct msdos_sb_info *sbi = MSDOS_SB(sb);
+       return sbi->vol_id;
+}
+
 static long fat_dir_ioctl(struct file *filp, unsigned int cmd,
                          unsigned long arg)
 {
@@ -792,6 +799,8 @@ static long fat_dir_ioctl(struct file *filp, unsigned int cmd,
                short_only = 0;
                both = 1;
                break;
+       case VFAT_IOCTL_GET_VOLUME_ID:
+               return fat_ioctl_volume_id(inode);
        default:
                return fat_generic_ioctl(filp, cmd, arg);
        }
index 21664fcf361673ec263ce2a23b59c3d7bdabf735..8180ecef59fc9856bfc6f349e9b03a4b286ca2b1 100644 (file)
@@ -86,6 +86,7 @@ struct msdos_sb_info {
        const void *dir_ops;          /* Opaque; default directory operations */
        int dir_per_block;            /* dir entries per block */
        int dir_per_block_bits;       /* log2(dir_per_block) */
+       unsigned long vol_id;         /* volume ID */
 
        int fatent_shift;
        struct fatent_operations *fatent_ops;
index 5d4513cb1b3c03604792f145125b21fb338a3101..a14dd4c0528a90a0f9dce633078ecd160113d59a 100644 (file)
@@ -1252,6 +1252,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
        struct inode *fsinfo_inode = NULL;
        struct buffer_head *bh;
        struct fat_boot_sector *b;
+       struct fat_boot_bsx *bsx;
        struct msdos_sb_info *sbi;
        u16 logical_sector_size;
        u32 total_sectors, total_clusters, fat_clusters, rootdir_sectors;
@@ -1398,6 +1399,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
                        goto out_fail;
                }
 
+               bsx = (struct fat_boot_bsx *)(bh->b_data + FAT32_BSX_OFFSET);
+
                fsinfo = (struct fat_boot_fsinfo *)fsinfo_bh->b_data;
                if (!IS_FSINFO(fsinfo)) {
                        fat_msg(sb, KERN_WARNING, "Invalid FSINFO signature: "
@@ -1413,8 +1416,14 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
                }
 
                brelse(fsinfo_bh);
+       } else {
+               bsx = (struct fat_boot_bsx *)(bh->b_data + FAT16_BSX_OFFSET);
        }
 
+       /* interpret volume ID as a little endian 32 bit integer */
+       sbi->vol_id = (((u32)bsx->vol_id[0]) | ((u32)bsx->vol_id[1] << 8) |
+               ((u32)bsx->vol_id[2] << 16) | ((u32)bsx->vol_id[3] << 24));
+
        sbi->dir_per_block = sb->s_blocksize / sizeof(struct msdos_dir_entry);
        sbi->dir_per_block_bits = ffs(sbi->dir_per_block) - 1;
 
index f055e58b31473f76f946d0b03b0c6f9444e79519..db4ae0cd16c7f2d7ffa9b009be9a1f08a991632c 100644 (file)
@@ -104,6 +104,7 @@ struct __fat_dirent {
 /* <linux/videotext.h> has used 0x72 ('r') in collision, so skip a few */
 #define FAT_IOCTL_GET_ATTRIBUTES       _IOR('r', 0x10, __u32)
 #define FAT_IOCTL_SET_ATTRIBUTES       _IOW('r', 0x11, __u32)
+#define VFAT_IOCTL_GET_VOLUME_ID       _IOR('r', 0x12, __u32)
 
 struct fat_boot_sector {
        __u8    ignored[3];     /* Boot strap short or near jump */
@@ -161,6 +162,17 @@ struct fat_boot_fsinfo {
        __le32   reserved2[4];
 };
 
+struct fat_boot_bsx {
+       __u8     drive;         /* drive number */
+       __u8     reserved1;
+       __u8     signature;     /* extended boot signature */
+       __u8     vol_id[4];     /* volume ID */
+       __u8     vol_label[11]; /* volume label */
+       __u8     type[8];       /* file system type */
+};
+#define FAT16_BSX_OFFSET 36 /* offset of fat_boot_bsx in FAT12 and FAT16 */
+#define FAT32_BSX_OFFSET 64 /* offset of fat_boot_bsx in FAT32 */
+
 struct msdos_dir_entry {
        __u8    name[MSDOS_NAME];/* name and extension */
        __u8    attr;           /* attribute bits */