Changeset 395df52 in mainline


Ignore:
Timestamp:
2017-05-12T19:58:27Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e48947e
Parents:
de5b708
Message:

Probing for ExFAT, Ext4 and CDFS.

Location:
uspace
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/init/init.c

    rde5b708 r395df52  
    316316        }
    317317       
    318         /* Make sure tmpfs is running. */
     318        /* Make sure file systems are running. */
    319319        if (str_cmp(STRING(RDFMT), "tmpfs") != 0)
    320320                srv_start("/srv/tmpfs");
    321        
     321        if (str_cmp(STRING(RDFMT), "exfat") != 0)
     322                srv_start("/srv/exfat");
     323        if (str_cmp(STRING(RDFMT), "fat") != 0)
     324                srv_start("/srv/fat");
     325        srv_start("/srv/cdfs");
    322326        srv_start("/srv/mfs");
    323327       
  • uspace/lib/c/include/types/vol.h

    rde5b708 r395df52  
    5252        fs_fat,
    5353        fs_minix,
    54         fs_ext4
     54        fs_ext4,
     55        fs_cdfs
    5556} vol_fstype_t;
    5657
  • uspace/lib/ext4/include/ext4/filesystem.h

    rde5b708 r395df52  
    3939#include "ext4/types.h"
    4040
     41extern int ext4_filesystem_probe(service_id_t);
    4142extern int ext4_filesystem_open(ext4_instance_t *, service_id_t,
    4243    enum cache_mode, aoff64_t *, ext4_filesystem_t **);
  • uspace/lib/ext4/src/filesystem.c

    rde5b708 r395df52  
    6161 *
    6262 * @param fs         Filesystem instance to be initialized
    63  * @param service_id Identifier if device with the filesystem
     63 * @param service_id Block device to open
    6464 * @param cmode      Cache mode
    6565 *
     
    155155        block_cache_fini(fs->device);
    156156        block_fini(fs->device);
     157}
     158
     159/** Probe filesystem.
     160 *
     161 * @param service_id Block device to probe
     162 *
     163 * @return EOK or negative error code.
     164 *
     165 */
     166int ext4_filesystem_probe(service_id_t service_id)
     167{
     168        ext4_filesystem_t *fs = NULL;
     169        int rc;
     170
     171        fs = calloc(1, sizeof(ext4_filesystem_t));
     172        if (fs == NULL)
     173                return ENOMEM;
     174
     175        /* Initialize the file system for opening */
     176        rc = ext4_filesystem_init(fs, service_id, CACHE_MODE_WT);
     177        if (rc != EOK) {
     178                free(fs);
     179                return rc;
     180        }
     181
     182        ext4_filesystem_fini(fs);
     183        return EOK;
    157184}
    158185
  • uspace/lib/ext4/src/ops.c

    rde5b708 r395df52  
    909909static int ext4_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info)
    910910{
    911         return ENOTSUP;
     911        return ext4_filesystem_probe(service_id);
    912912}
    913913
  • uspace/lib/fdisk/src/fdisk.c

    rde5b708 r395df52  
    824824                sfstype = "Ext4";
    825825                break;
     826        case fs_cdfs:
     827                sfstype = "ISO 9660";
     828                break;
    826829        }
    827830
     
    993996                pcnt = lpc_ext4;
    994997                break;
     998        case fs_cdfs:
     999                return EINVAL; /* You cannot create an ISO partition */
    9951000        }
    9961001
  • uspace/srv/fs/cdfs/cdfs_ops.c

    rde5b708 r395df52  
    906906}
    907907
    908 static bool iso_readfs(cdfs_t *fs, fs_node_t *rfn,
    909     cdfs_lba_t altroot)
     908/** Read the volume descriptors. */
     909static bool iso_read_vol_desc(service_id_t sid, cdfs_lba_t altroot,
     910    uint32_t *rlba, uint32_t *rsize, cdfs_enc_t *enc)
    910911{
    911912        /* First 16 blocks of isofs are empty */
    912913        block_t *block;
    913         int rc = block_get(&block, fs->service_id, altroot + 16, BLOCK_FLAGS_NONE);
     914        int rc = block_get(&block, sid, altroot + 16, BLOCK_FLAGS_NONE);
    914915        if (rc != EOK)
    915916                return false;
     
    956957        // TODO: implement path table support
    957958       
    958         cdfs_node_t *node = CDFS_NODE(rfn);
    959        
    960959        /* Search for Joliet SVD */
    961960       
     
    963962        uint32_t jrsize;
    964963       
    965         rc = cdfs_find_joliet_svd(fs->service_id, altroot, &jrlba, &jrsize);
     964        rc = cdfs_find_joliet_svd(sid, altroot, &jrlba, &jrsize);
    966965        if (rc == EOK) {
    967966                /* Found */
    968                 node->lba = jrlba;
    969                 node->size = jrsize;
    970                 fs->enc = enc_ucs2;
     967                *rlba = jrlba;
     968                *rsize = jrsize;
     969                *enc = enc_ucs2;
    971970        } else {
    972                 node->lba = uint32_lb(vol_desc->data.prisec.root_dir.lba);
    973                 node->size = uint32_lb(vol_desc->data.prisec.root_dir.size);
    974                 fs->enc = enc_ascii;
    975         }
    976        
    977         if (!cdfs_readdir(fs, rfn)) {
    978                 block_put(block);
    979                 return false;
     971                *rlba = uint32_lb(vol_desc->data.prisec.root_dir.lba);
     972                *rsize = uint32_lb(vol_desc->data.prisec.root_dir.size);
     973                *enc = enc_ascii;
    980974        }
    981975       
    982976        block_put(block);
    983977        return true;
     978}
     979
     980static bool iso_readfs(cdfs_t *fs, fs_node_t *rfn,
     981    cdfs_lba_t altroot)
     982{
     983        int rc;
     984       
     985        cdfs_node_t *node = CDFS_NODE(rfn);
     986       
     987        rc = iso_read_vol_desc(fs->service_id, altroot, &node->lba,
     988            &node->size, &fs->enc);
     989        if (rc != EOK)
     990                return false;
     991       
     992        return cdfs_readdir(fs, rfn);
    984993}
    985994
     
    10231032static int cdfs_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info)
    10241033{
    1025         return ENOTSUP;
     1034        /* Initialize the block layer */
     1035        int rc = block_init(service_id, BLOCK_SIZE);
     1036        if (rc != EOK)
     1037                return rc;
     1038       
     1039        cdfs_lba_t altroot = 0;
     1040       
     1041        /*
     1042         * Read TOC multisession information and get the start address
     1043         * of the first track in the last session
     1044         */
     1045        scsi_toc_multisess_data_t toc;
     1046
     1047        rc = block_read_toc(service_id, 1, &toc, sizeof(toc));
     1048        if (rc == EOK && (uint16_t_be2host(toc.toc_len) == 10))
     1049                altroot = uint32_t_be2host(toc.ftrack_lsess.start_addr);
     1050       
     1051        /* Initialize the block cache */
     1052        rc = block_cache_init(service_id, BLOCK_SIZE, 0, CACHE_MODE_WT);
     1053        if (rc != EOK) {
     1054                block_fini(service_id);
     1055                return rc;
     1056        }
     1057       
     1058        /* Check if this device is not already mounted */
     1059        fs_node_t *rootfn;
     1060        rc = cdfs_root_get(&rootfn, service_id);
     1061        if ((rc == EOK) && (rootfn)) {
     1062                cdfs_node_put(rootfn);
     1063                block_cache_fini(service_id);
     1064                block_fini(service_id);
     1065                return EOK;
     1066        }
     1067       
     1068        /* Read volume descriptors */
     1069        uint32_t rlba;
     1070        uint32_t rsize;
     1071        cdfs_enc_t enc;
     1072        if (!iso_read_vol_desc(service_id, altroot, &rlba, &rsize, &enc)) {
     1073                block_cache_fini(service_id);
     1074                block_fini(service_id);
     1075                return EIO;
     1076        }
     1077       
     1078        return EOK;
    10261079}
    10271080
  • uspace/srv/fs/exfat/exfat_fat.c

    rde5b708 r395df52  
    540540 * does not contain a exfat file system.
    541541 */
    542 int exfat_sanity_check(exfat_bs_t *bs, service_id_t service_id)
     542int exfat_sanity_check(exfat_bs_t *bs)
    543543{
    544544        if (str_cmp((char const *)bs->oem_name, "EXFAT   "))
  • uspace/srv/fs/exfat/exfat_fat.h

    rde5b708 r395df52  
    7272extern int exfat_set_cluster(struct exfat_bs *, service_id_t, exfat_cluster_t,
    7373    exfat_cluster_t);
    74 extern int exfat_sanity_check(struct exfat_bs *, service_id_t);
     74extern int exfat_sanity_check(struct exfat_bs *);
    7575
    7676extern int exfat_append_clusters(struct exfat_bs *, struct exfat_node *,
  • uspace/srv/fs/exfat/exfat_ops.c

    rde5b708 r395df52  
    10531053static int exfat_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info)
    10541054{
    1055         return ENOTSUP;
     1055        int rc;
     1056        exfat_bs_t *bs;
     1057
     1058        /* initialize libblock */
     1059        rc = block_init(service_id, BS_SIZE);
     1060        if (rc != EOK)
     1061                return rc;
     1062
     1063        /* prepare the boot block */
     1064        rc = block_bb_read(service_id, BS_BLOCK);
     1065        if (rc != EOK) {
     1066                block_fini(service_id);
     1067                return rc;
     1068        }
     1069
     1070        /* get the buffer with the boot sector */
     1071        bs = block_bb_get(service_id);
     1072
     1073        /* Do some simple sanity checks on the file system. */
     1074        rc = exfat_sanity_check(bs);
     1075
     1076        (void) block_cache_fini(service_id);
     1077        block_fini(service_id);
     1078        return rc;
    10561079}
    10571080
     
    10861109        bs = block_bb_get(service_id);
    10871110
     1111        /* Do some simple sanity checks on the file system. */
     1112        rc = exfat_sanity_check(bs);
     1113        if (rc != EOK) {
     1114                (void) block_cache_fini(service_id);
     1115                block_fini(service_id);
     1116                return rc;
     1117        }
     1118
    10881119        /* Initialize the block cache */
    10891120        rc = block_cache_init(service_id, BPS(bs), 0 /* XXX */, cmode);
    10901121        if (rc != EOK) {
    1091                 block_fini(service_id);
    1092                 return rc;
    1093         }
    1094 
    1095         /* Do some simple sanity checks on the file system. */
    1096         rc = exfat_sanity_check(bs, service_id);
    1097         if (rc != EOK) {
    1098                 (void) block_cache_fini(service_id);
    10991122                block_fini(service_id);
    11001123                return rc;
  • uspace/srv/fs/fat/fat_ops.c

    rde5b708 r395df52  
    915915static int fat_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info)
    916916{
    917         return ENOTSUP;
     917        fat_bs_t *bs;
     918        int rc;
     919
     920        /* initialize libblock */
     921        rc = block_init(service_id, BS_SIZE);
     922        if (rc != EOK)
     923                return rc;
     924
     925        /* prepare the boot block */
     926        rc = block_bb_read(service_id, BS_BLOCK);
     927        if (rc != EOK) {
     928                block_fini(service_id);
     929                return rc;
     930        }
     931
     932        /* get the buffer with the boot sector */
     933        bs = block_bb_get(service_id);
     934
     935        if (BPS(bs) != BS_SIZE) {
     936                block_fini(service_id);
     937                return ENOTSUP;
     938        }
     939
     940        /* Initialize the block cache */
     941        rc = block_cache_init(service_id, BPS(bs), 0 /* XXX */, CACHE_MODE_WB);
     942        if (rc != EOK) {
     943                block_fini(service_id);
     944                return rc;
     945        }
     946
     947        /* Do some simple sanity checks on the file system. */
     948        rc = fat_sanity_check(bs, service_id);
     949
     950        (void) block_cache_fini(service_id);
     951        block_fini(service_id);
     952
     953        return rc;
    918954}
    919955
  • uspace/srv/volsrv/mkfs.c

    rde5b708 r395df52  
    119119                break;
    120120        case fs_ext4:
     121        case fs_cdfs:
    121122                cmd = NULL;
    122123                break;
  • uspace/srv/volsrv/part.c

    rde5b708 r395df52  
    5353static FIBRIL_MUTEX_INITIALIZE(vol_parts_lock);
    5454
     55struct fsname_type {
     56        const char *name;
     57        vol_fstype_t fstype;
     58};
     59
     60static struct fsname_type fstab[] = {
     61        { "ext4fs", fs_ext4 },
     62        { "cdfs", fs_cdfs },
     63        { "exfat", fs_exfat },
     64        { "fat", fs_fat },
     65        { "mfs", fs_minix },
     66        { NULL, 0 }
     67};
     68
    5569/** Check for new partitions */
    5670static int vol_part_check_new(void)
     
    134148        bool empty;
    135149        vfs_fs_probe_info_t info;
     150        struct fsname_type *fst;
    136151        int rc;
    137152
     
    157172
    158173        log_msg(LOG_DEFAULT, LVL_NOTE, "Probe partition %s", part->svc_name);
    159         rc = vfs_fsprobe("mfs", sid, &info);
    160         if (rc == EOK) {
     174
     175        fst = &fstab[0];
     176        while (fst->name != NULL) {
     177                rc = vfs_fsprobe(fst->name, sid, &info);
     178                if (rc == EOK)
     179                        break;
     180                ++fst;
     181        }
     182
     183        if (fst->name != NULL) {
     184                log_msg(LOG_DEFAULT, LVL_NOTE, "Found %s", fst->name);
    161185                part->pcnt = vpc_fs;
    162                 part->fstype = fs_minix;
     186                part->fstype = fst->fstype;
    163187        } else {
    164188                log_msg(LOG_DEFAULT, LVL_NOTE, "Partition does not contain "
Note: See TracChangeset for help on using the changeset viewer.