summaryrefslogtreecommitdiff
path: root/lib/ultralib/src/io/pfssetlabel.c
blob: ab6c6eaf11e49e43bf394eaaa27c077a70921373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PRinternal/controller.h"

s32 osPfsSetLabel(OSPfs* pfs, u8* label) {
    int i;
    s32 ret;

#if BUILD_VERSION >= VERSION_J
    if (!(pfs->status & PFS_INITIALIZED)) {
        return PFS_ERR_INVALID;
    }

    ERRCK(__osCheckId(pfs));
#else
    PFS_CHECK_ID();
#endif

    if (label != NULL) {
        for (i = 0; i < ARRLEN(pfs->label); i++) {
            if (*label == 0) {
                break;
            }

            *(pfs->label + i) = *label++;
        }
    }

#if BUILD_VERSION >= VERSION_J
    if (pfs->activebank != 0) {
        ret = SELECT_BANK(pfs, 0);
        if (ret == 0) {
            ret = (__osContRamWrite(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label, FALSE));
        }
    }
    return ret;
#else
    SET_ACTIVEBANK_TO_ZERO();
    ERRCK(__osContRamWrite(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label, FALSE));
    return 0;
#endif
}