Changeset f4f866c in mainline for uspace/lib/c/generic/sysinfo.c


Ignore:
Timestamp:
2010-04-23T21:42:26Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6c39a907
Parents:
38aaacc2 (diff), 80badbe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r38aaacc2 rf4f866c  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#include <libc.h>
    3636#include <sysinfo.h>
    3737#include <str.h>
     38#include <errno.h>
     39#include <malloc.h>
     40#include <bool.h>
    3841
    39 sysarg_t sysinfo_value(const char *name)
     42/** Get sysinfo item type
     43 *
     44 * @param path Sysinfo path.
     45 *
     46 * @return Sysinfo item type.
     47 *
     48 */
     49sysinfo_item_tag_t sysinfo_get_tag(const char *path)
    4050{
    41         return __SYSCALL2(SYS_SYSINFO_VALUE, (sysarg_t) name,
    42             (sysarg_t) str_size(name));
     51        return (sysinfo_item_tag_t) __SYSCALL2(SYS_SYSINFO_GET_TAG,
     52            (sysarg_t) path, (sysarg_t) str_size(path));
     53}
     54
     55/** Get sysinfo numerical value
     56 *
     57 * @param path  Sysinfo path.
     58 * @param value Pointer to store the numerical value to.
     59 *
     60 * @return EOK if the value was successfully read and
     61 *         is of SYSINFO_VAL_VAL type.
     62 *
     63 */
     64int sysinfo_get_value(const char *path, sysarg_t *value)
     65{
     66        return (int) __SYSCALL3(SYS_SYSINFO_GET_VALUE, (sysarg_t) path,
     67            (sysarg_t) str_size(path), (sysarg_t) value);
     68}
     69
     70/** Get sysinfo binary data size
     71 *
     72 * @param path  Sysinfo path.
     73 * @param value Pointer to store the binary data size.
     74 *
     75 * @return EOK if the value was successfully read and
     76 *         is of SYSINFO_VAL_DATA type.
     77 *
     78 */
     79static int sysinfo_get_data_size(const char *path, size_t *size)
     80{
     81        return (int) __SYSCALL3(SYS_SYSINFO_GET_DATA_SIZE, (sysarg_t) path,
     82            (sysarg_t) str_size(path), (sysarg_t) size);
     83}
     84
     85/** Get sysinfo binary data
     86 *
     87 * @param path  Sysinfo path.
     88 * @param value Pointer to store the binary data size.
     89 *
     90 * @return Binary data read from sysinfo or NULL if the
     91 *         sysinfo item value type is not binary data.
     92 *         The returned non-NULL pointer should be
     93 *         freed by free().
     94 *
     95 */
     96void *sysinfo_get_data(const char *path, size_t *size)
     97{
     98        /* The binary data size might change during time.
     99           Unfortunatelly we cannot allocate the buffer
     100           and transfer the data as a single atomic operation.
     101       
     102           Let's hope that the number of iterations is bounded
     103           in common cases. */
     104       
     105        void *data = NULL;
     106       
     107        while (true) {
     108                /* Get the binary data size */
     109                int ret = sysinfo_get_data_size(path, size);
     110                if ((ret != EOK) || (size == 0)) {
     111                        /* Not a binary data item
     112                           or an empty item */
     113                        break;
     114                }
     115               
     116                data = realloc(data, *size);
     117                if (data == NULL)
     118                        break;
     119               
     120                /* Get the data */
     121                ret = __SYSCALL4(SYS_SYSINFO_GET_DATA, (sysarg_t) path,
     122                    (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size);
     123                if (ret == EOK)
     124                        return data;
     125               
     126                if (ret != ENOMEM) {
     127                        /* The failure to get the data was not caused
     128                           by wrong buffer size */
     129                        break;
     130                }
     131        }
     132       
     133        if (data != NULL)
     134                free(data);
     135       
     136        *size = 0;
     137        return NULL;
    43138}
    44139
Note: See TracChangeset for help on using the changeset viewer.