Changeset b209135 in mainline


Ignore:
Timestamp:
2018-10-03T12:19:02Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ba36a0
Parents:
2175178
git-author:
Jiri Svoboda <jiri@…> (2018-10-02 22:18:01)
git-committer:
Jiri Svoboda <jiri@…> (2018-10-03 12:19:02)
Message:

Reading volume label from ext4 file system.

Location:
uspace/lib/ext4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/include/ext4/filesystem.h

    r2175178 rb209135  
    4141#include "ext4/types.h"
    4242
    43 extern errno_t ext4_filesystem_probe(service_id_t);
     43extern errno_t ext4_filesystem_probe(service_id_t, ext4_fs_probe_info_t *);
    4444extern errno_t ext4_filesystem_create(ext4_cfg_ver_t, service_id_t);
    4545extern errno_t ext4_filesystem_open(ext4_instance_t *, service_id_t,
  • uspace/lib/ext4/include/ext4/superblock.h

    r2175178 rb209135  
    118118extern void ext4_superblock_get_uuid(ext4_superblock_t *, uuid_t *);
    119119extern void ext4_superblock_set_uuid(ext4_superblock_t *, uuid_t *);
    120 extern const char *ext4_superblock_get_volume_name(ext4_superblock_t *);
     120extern errno_t ext4_superblock_get_volume_name(ext4_superblock_t *, char *,
     121    size_t);
    121122extern void ext4_superblock_set_volume_name(ext4_superblock_t *, const char *);
    122123extern const char *ext4_superblock_get_last_mounted(ext4_superblock_t *);
  • uspace/lib/ext4/include/ext4/types.h

    r2175178 rb209135  
    235235} ext4_filesystem_t;
    236236
     237typedef 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];
     242} ext4_fs_probe_info_t;
     243
    237244#define EXT4_BLOCK_GROUP_INODE_UNINIT   0x0001  /* Inode table/bitmap not in use */
    238245#define EXT4_BLOCK_GROUP_BLOCK_UNINIT   0x0002  /* Block bitmap not in use */
  • uspace/lib/ext4/src/filesystem.c

    r2175178 rb209135  
    374374 *
    375375 * @param service_id Block device to probe
     376 * @param info Place to store probe information
    376377 *
    377378 * @return EOK or an error code.
    378379 *
    379380 */
    380 errno_t ext4_filesystem_probe(service_id_t service_id)
     381errno_t ext4_filesystem_probe(service_id_t service_id,
     382    ext4_fs_probe_info_t *info)
    381383{
    382384        ext4_filesystem_t *fs = NULL;
     
    391393        if (rc != EOK) {
    392394                free(fs);
     395                return rc;
     396        }
     397
     398        rc = ext4_superblock_get_volume_name(fs->superblock, info->vol_name,
     399            sizeof(info->vol_name));
     400        if (rc != EOK) {
     401                ext4_filesystem_fini(fs);
    393402                return rc;
    394403        }
  • uspace/lib/ext4/src/ops.c

    r2175178 rb209135  
    908908static errno_t ext4_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info)
    909909{
    910         return ext4_filesystem_probe(service_id);
     910        ext4_fs_probe_info_t pinfo;
     911        errno_t rc;
     912
     913        rc = ext4_filesystem_probe(service_id, &pinfo);
     914        if (rc != EOK)
     915                return rc;
     916
     917        memcpy(info->label, pinfo.vol_name, sizeof(pinfo.vol_name));
     918        return EOK;
    911919}
    912920
  • uspace/lib/ext4/src/superblock.c

    r2175178 rb209135  
    4444#include <mem.h>
    4545#include <stdlib.h>
     46#include <str.h>
    4647#include <time.h>
    4748#include "ext4/cfg.h"
     
    883884 *
    884885 */
    885 const char *ext4_superblock_get_volume_name(ext4_superblock_t *sb)
    886 {
    887         return sb->volume_name;
     886errno_t ext4_superblock_get_volume_name(ext4_superblock_t *sb, char *buf,
     887    size_t bufsz)
     888{
     889        size_t i;
     890        size_t wi;
     891        wchar_t ch;
     892        errno_t rc;
     893
     894        i = 0;
     895        wi = 0;
     896        while (sb->volume_name[i] != '\0' && i < sizeof(sb->volume_name)) {
     897                /* ISO 8859-1 codes map to identical Unicode code points */
     898                ch = (wchar_t)(uint8_t)sb->volume_name[i];
     899                rc = chr_encode(ch, buf, &wi, bufsz - 1);
     900                if (rc != EOK)
     901                        return rc;
     902
     903                i++;
     904        }
     905
     906        buf[wi] = '\0';
     907        return EOK;
    888908}
    889909
Note: See TracChangeset for help on using the changeset viewer.