Changeset 9e3dc95 in mainline


Ignore:
Timestamp:
2011-03-01T22:10:16Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9a9a58e
Parents:
819450a
Message:

check superblock magic numbers

Location:
uspace/srv/fs/minixfs
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/minixfs/Makefile

    r819450a r9e3dc95  
    3434
    3535SOURCES = \
    36         mfs.c
     36        mfs.c \
     37        mfs_super.c \
     38        mfs_utils.c
    3739
    3840include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/fs/minixfs/mfs_const.h

    r819450a r9e3dc95  
    3838#include <bool.h>
    3939
    40 #define MFS_MAGIC_V1            0x137F
    41 #define MFS_MAGIC_V2            0x2468
    42 #define MFS_MAGIC_V3            0x4D5A
    43 
    4440#define MFS_ROOT_INO            1
    4541#define MFS_SUPER_BLOCK         0
  • uspace/srv/fs/minixfs/mfs_super.c

    r819450a r9e3dc95  
    3131 */
    3232
     33#include <libfs.h>
     34#include <stdlib.h>
     35#include <libblock.h>
     36#include <errno.h>
     37#include <str.h>
    3338#include "mfs_super.h"
     39#include "mfs_utils.h"
     40#include "../../vfs/vfs.h"
     41
     42static bool check_magic_number(int16_t magic, bool *native, mfs_version_t *version);
    3443
    3544void mfs_mounted(ipc_callid_t rid, ipc_call_t *request)
     
    3847        enum cache_mode cmode; 
    3948        struct mfs_superblock *sp;
     49        bool native;
     50        mfs_version_t version;
    4051
    4152        /* Accept the mount options */
     
    7384        /* get the buffer with the superblock */
    7485        sp = block_bb_get(devmap_handle);
     86
     87        if (!check_magic_number(sp->s_magic, &native, &version)) {
     88                /*Magic number is invalid!*/
     89                block_fini(devmap_handle);
     90                async_answer_0(rid, ENOTSUP);
     91                return;
     92        }
     93}
     94
     95static bool check_magic_number(int16_t magic, bool *native, mfs_version_t *version)
     96{
     97        *native = true;
     98
     99repeat_check:
     100
     101        switch (*native ? magic : conv16(false, magic)) {
     102        case MFS_MAGIC_V1:
     103                *version = MFS_VERSION_V1;
     104                return true;
     105        case MFS_MAGIC_V2:
     106                *version = MFS_VERSION_V2;
     107                return true;
     108        case MFS_MAGIC_V3:
     109                *version = MFS_VERSION_V3;
     110                return true;
     111        default:
     112                ;
     113        }
     114
     115        if (*native) {
     116                *native = false;
     117                goto repeat_check;
     118        } else {
     119                return false;
     120        }
     121
     122        /*Should never happens*/
     123        return false;
    75124}
    76125
  • uspace/srv/fs/minixfs/mfs_super.h

    r819450a r9e3dc95  
    3737#include "../../vfs/vfs.h"
    3838
     39#define MFS_MAGIC_V1            0x137F
     40#define MFS_MAGIC_V2            0x2468
     41#define MFS_MAGIC_V3            0x4D5A
     42
    3943struct mfs_superblock {
    4044        /*Total number of inodes on the device*/
     
    6771} __attribute__ ((packed));
    6872
     73typedef enum {
     74        MFS_VERSION_V1 = 1,
     75        MFS_VERSION_V2,
     76        MFS_VERSION_V3
     77} mfs_version_t;
     78
    6979void mfs_mounted(ipc_callid_t rid, ipc_call_t *request);
    7080
  • uspace/srv/fs/minixfs/mfs_utils.c

    r819450a r9e3dc95  
    3838                return n;
    3939
    40         return r = (n << 8) | (n >> 8);
     40        return (n << 8) | (n >> 8);
    4141}
    4242
Note: See TracChangeset for help on using the changeset viewer.