Changeset da680b4b in mainline


Ignore:
Timestamp:
2018-07-06T17:18:28Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6419c6e
Parents:
9ba040a
Message:

Don't automatically mount writable filesystems on ATA hard drives. Better be safe than sorry. (But no way to override yet.)

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/str.c

    r9ba040a rda680b4b  
    11341134                        return (char *) (str + last);
    11351135                last = off;
     1136        }
     1137
     1138        return NULL;
     1139}
     1140
     1141/** Find first occurence of substring in string.
     1142 *
     1143 * @param hs  Haystack (string)
     1144 * @param n   Needle (substring to look for)
     1145 *
     1146 * @return Pointer to character in @a hs or @c NULL if not found.
     1147 */
     1148char *str_str(const char *hs, const char *n)
     1149{
     1150        size_t off = 0;
     1151
     1152        if (str_lcmp(hs, n, str_length(n)) == 0)
     1153                return (char *)hs;
     1154
     1155        while (str_decode(hs, &off, STR_NO_LIMIT) != 0) {
     1156                if (str_lcmp(hs + off, n, str_length(n)) == 0)
     1157                        return (char *)(hs + off);
    11361158        }
    11371159
  • uspace/lib/c/include/str.h

    r9ba040a rda680b4b  
    108108extern char *str_chr(const char *str, wchar_t ch);
    109109extern char *str_rchr(const char *str, wchar_t ch);
     110extern char *str_str(const char *hs, const char *n);
    110111
    111112extern void str_rtrim(char *str, wchar_t ch);
  • uspace/lib/c/test/str.c

    r9ba040a rda680b4b  
    8888}
    8989
     90PCUT_TEST(str_str_found)
     91{
     92        const char *hs = "abracadabra";
     93        const char *n = "raca";
     94        char *p;
     95
     96        p = str_str(hs, n);
     97        PCUT_ASSERT_TRUE((const char *)p == hs + 2);
     98}
     99
     100PCUT_TEST(str_str_not_found)
     101{
     102        const char *hs = "abracadabra";
     103        const char *n = "racab";
     104        char *p;
     105
     106        p = str_str(hs, n);
     107        PCUT_ASSERT_TRUE(p == NULL);
     108}
     109
     110PCUT_TEST(str_str_empty_n)
     111{
     112        const char *hs = "abracadabra";
     113        const char *n = "";
     114        char *p;
     115
     116        p = str_str(hs, n);
     117        PCUT_ASSERT_TRUE((const char *)p == hs);
     118}
    90119
    91120PCUT_EXPORT(str);
  • uspace/srv/volsrv/part.c

    r9ba040a rda680b4b  
    256256}
    257257
     258/** Determine if partition is allowed to be mounted by default.
     259 *
     260 * @param part Partition
     261 * @return @c true iff partition is allowed to be mounted by default
     262 */
     263static bool vol_part_allow_mount_by_def(vol_part_t *part)
     264{
     265        /* CDFS is safe to mount (after all, it is read-only) */
     266        if (part->pcnt == vpc_fs && part->fstype == fs_cdfs)
     267                return true;
     268
     269        /* For other file systems disallow mounting from ATA hard drive */
     270        if (str_str(part->svc_name, "\\ata-c") != NULL)
     271                return false;
     272
     273        /* Allow otherwise (e.g. USB mass storage) */
     274        return true;
     275}
     276
    258277static errno_t vol_part_mount(vol_part_t *part)
    259278{
     
    265284                /* Don't mount nameless volumes */
    266285                log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting nameless partition.");
     286                return EOK;
     287        }
     288
     289        if (!vol_part_allow_mount_by_def(part)) {
     290                /* Don't mount partition by default */
     291                log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting per default policy.");
    267292                return EOK;
    268293        }
Note: See TracChangeset for help on using the changeset viewer.