Changeset 6ba36a0 in mainline


Ignore:
Timestamp:
2018-10-03T15:31:58Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9b0ceb1
Parents:
b209135
Message:

Setting a custom ext4 volume label.

Location:
uspace
Files:
8 edited

Legend:

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

    rb209135 r6ba36a0  
    5252        char *dev_path;
    5353        service_id_t service_id;
    54         ext4_cfg_ver_t ver;
     54        ext4_cfg_t cfg;
    5555        char *endptr;
    5656        aoff64_t nblocks;
    57         char *label;
     57        const char *label = "";
    5858
    59         ver = ext4_def_fs_version;
     59        cfg.version = ext4_def_fs_version;
    6060
    6161        if (argc < 2) {
     
    9898                        }
    9999
    100                         rc = ext4_version_parse(*argv, &ver);
     100                        rc = ext4_version_parse(*argv, &cfg.version);
    101101                        if (rc != EOK) {
    102102                                printf(NAME ": Error, invalid argument.\n");
     
    146146        }
    147147
    148         (void) label;
     148        cfg.volume_name = label;
    149149        (void) nblocks;
    150150
    151         rc = ext4_filesystem_create(ver, service_id);
     151        rc = ext4_filesystem_create(&cfg, service_id);
    152152        if (rc != EOK) {
    153153                printf(NAME ": Error initializing file system.\n");
  • uspace/lib/ext4/include/ext4/cfg.h

    rb209135 r6ba36a0  
    3434#define LIBEXT4_CFG_H_
    3535
     36#include "types.h"
     37
    3638/** Versions available to choose from when creating a new file system. */
    3739typedef enum {
     
    4547#define ext4_def_fs_version extver_ext2
    4648
     49/** Configuration of a new ext4 file system */
     50typedef struct {
     51        /** File system version */
     52        ext4_cfg_ver_t version;
     53        /** Volume name encoded as UTF-8 string */
     54        const char *volume_name;
     55} ext4_cfg_t;
     56
    4757#endif
    4858
  • uspace/lib/ext4/include/ext4/filesystem.h

    rb209135 r6ba36a0  
    4242
    4343extern errno_t ext4_filesystem_probe(service_id_t, ext4_fs_probe_info_t *);
    44 extern errno_t ext4_filesystem_create(ext4_cfg_ver_t, service_id_t);
     44extern errno_t ext4_filesystem_create(ext4_cfg_t *, service_id_t);
    4545extern errno_t ext4_filesystem_open(ext4_instance_t *, service_id_t,
    4646    enum cache_mode, aoff64_t *, ext4_filesystem_t **);
  • uspace/lib/ext4/include/ext4/superblock.h

    rb209135 r6ba36a0  
    120120extern errno_t ext4_superblock_get_volume_name(ext4_superblock_t *, char *,
    121121    size_t);
    122 extern void ext4_superblock_set_volume_name(ext4_superblock_t *, const char *);
     122extern errno_t ext4_superblock_set_volume_name(ext4_superblock_t *, const char *);
    123123extern const char *ext4_superblock_get_last_mounted(ext4_superblock_t *);
    124124extern void ext4_superblock_set_last_mounted(ext4_superblock_t *, const char *);
     
    166166extern uint32_t ext4_superblock_get_inodes_in_group(ext4_superblock_t *,
    167167    uint32_t);
    168 extern errno_t ext4_superblock_create(size_t, uint64_t, ext4_cfg_ver_t,
     168extern errno_t ext4_superblock_create(size_t, uint64_t, ext4_cfg_t *,
    169169    ext4_superblock_t **);
    170170extern uint32_t ext4_superblock_get_group_backup_blocks(ext4_superblock_t *,
  • uspace/lib/ext4/include/ext4/types.h

    rb209135 r6ba36a0  
    235235} ext4_filesystem_t;
    236236
     237/** Size of buffer for volume name. To hold 16 latin-1 chars encoded as UTF-8
     238 * and a null terminator we need 2 * 16 + 1 bytes
     239 */
     240#define EXT4_VOL_NAME_BYTES 33
     241
    237242typedef struct {
    238         /** Volume name, to hold 16 latin-1 chars in UTF-8 and null terminator
    239          * we need 2 * 16 + 1 bytes
    240          */
    241         char vol_name[33];
     243        char vol_name[EXT4_VOL_NAME_BYTES];
    242244} ext4_fs_probe_info_t;
    243245
  • uspace/lib/ext4/src/filesystem.c

    rb209135 r6ba36a0  
    249249/** Create new filesystem.
    250250 *
    251  * @param ver Filesystem version
    252  * @param service_id Block device where to create new filesystem
    253  */
    254 errno_t ext4_filesystem_create(ext4_cfg_ver_t ver, service_id_t service_id)
     251 * @param cfg Configuration of new file system
     252 * @param service_id Block device where to create new file system
     253 */
     254errno_t ext4_filesystem_create(ext4_cfg_t *cfg, service_id_t service_id)
    255255{
    256256        errno_t rc;
     
    282282
    283283        /* Create superblock */
    284         rc = ext4_superblock_create(dev_bsize, dev_nblocks, ver, &superblock);
     284        rc = ext4_superblock_create(dev_bsize, dev_nblocks, cfg, &superblock);
    285285        if (rc != EOK)
    286286                goto err;
  • uspace/lib/ext4/src/superblock.c

    rb209135 r6ba36a0  
    912912 * @param sb   Superblock
    913913 * @param name New name of the volume
    914  */
    915 void ext4_superblock_set_volume_name(ext4_superblock_t *sb, const char *name)
    916 {
    917         memcpy(sb->volume_name, name, sizeof(sb->volume_name));
     914 * @return EOK on success or error code
     915 */
     916errno_t ext4_superblock_set_volume_name(ext4_superblock_t *sb, const char *name)
     917{
     918        size_t off;
     919        wchar_t ch;
     920        size_t wi;
     921
     922        off = 0;
     923        wi = 0;
     924        while (wi < sizeof(sb->volume_name)) {
     925                ch = str_decode(name, &off, STR_NO_LIMIT);
     926                if (ch == 0)
     927                        break;
     928                if (ch > 255)
     929                        return EINVAL;
     930
     931                sb->volume_name[wi++] = ch;
     932        }
     933
     934        while (wi < sizeof(sb->volume_name))
     935                sb->volume_name[wi++] = '\0';
     936
     937        return EOK;
    918938}
    919939
     
    14751495 * @param dev_bsize Device block size
    14761496 * @param dev_bcnt Device number of blocks
    1477  * @param ver Filesystem version
     1497 * @param cfg Configuration of new file system
    14781498 * @param rsb Place to store pointer to newly allocated superblock
    14791499 * @return EOK on success or error code
    14801500 */
    14811501errno_t ext4_superblock_create(size_t dev_bsize, uint64_t dev_bcnt,
    1482     ext4_cfg_ver_t ver, ext4_superblock_t **rsb)
     1502    ext4_cfg_t *cfg, ext4_superblock_t **rsb)
    14831503{
    14841504        ext4_superblock_t *sb;
     
    15791599        ext4_superblock_set_check_interval(sb, 0);
    15801600        ext4_superblock_set_creator_os(sb, EXT4_SUPERBLOCK_OS_LINUX);
    1581         if (ver >= extver_ext2)
     1601        if (cfg->version >= extver_ext2)
    15821602                ext4_superblock_set_rev_level(sb, EXT4_DYNAMIC_REV);
    15831603        else
     
    15861606        ext4_superblock_set_def_resgid(sb, 0);
    15871607
    1588         if (ver >= extver_ext2) {
     1608        if (cfg->version >= extver_ext2) {
    15891609                /* Dynamic rev */
    15901610                ext4_superblock_set_first_inode(sb, EXT4_REV0_FIRST_INO);
     
    15961616
    15971617                ext4_superblock_set_uuid(sb, &uuid);
    1598                 /* 16-byte Latin-1 string padded with null characters */
    1599                 ext4_superblock_set_volume_name(sb, "HelenOS-Ext4\0\0\0\0");
     1618
     1619                rc = ext4_superblock_set_volume_name(sb, cfg->volume_name);
     1620                if (rc != EOK)
     1621                        goto error;
     1622
    16001623                /* 64-byte Latin-1 string padded with null characters */
    16011624                ext4_superblock_set_last_mounted(sb,
  • uspace/srv/volsrv/mkfs.c

    rb209135 r6ba36a0  
    148148        switch (fstype) {
    149149        case fs_exfat:
     150        case fs_ext4:
    150151        case fs_fat:
    151152                vlsupp->supported = true;
    152153                break;
    153154        case fs_minix:
    154         case fs_ext4:
    155155        case fs_cdfs:
    156156                break;
Note: See TracChangeset for help on using the changeset viewer.