Changeset 4c6fd56 in mainline for uspace/srv/bd/file_bd/file_bd.c


Ignore:
Timestamp:
2023-09-16T19:58:18Z (8 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7d7f5e3
Parents:
6a0b2cc
git-author:
Jiri Svoboda <jiri@…> (2023-09-16 19:48:07)
git-committer:
Jiri Svoboda <jiri@…> (2023-09-16 19:58:18)
Message:

loc_server_register() should be callable more than once (API only)

Now loc_server_register() returns a pointer to a loc_srv_t object,
that is then passed to loc_service_register() and
loc_service_add_to_cat().

Added loc_server_unregister() that unregisters the server
and frees the loc_srv_t object.

Updated all callers. The implementation, however, is a stub.
It is not actually possible to call loc_server_register() more
than once, yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/file_bd/file_bd.c

    r6a0b2cc r4c6fd56  
    11/*
    2  * Copyright (c) 2009 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6161static aoff64_t num_blocks;
    6262static FILE *img;
     63static loc_srv_t *srv;
    6364
    6465static service_id_t service_id;
     
    137138                return -1;
    138139
    139         rc = loc_service_register(device_name, &service_id);
     140        rc = loc_service_register(srv, device_name, &service_id);
    140141        if (rc != EOK) {
    141142                printf("%s: Unable to register device '%s': %s.\n",
     
    150151        }
    151152
    152         rc = loc_service_add_to_cat(service_id, disk_cat);
     153        rc = loc_service_add_to_cat(srv, service_id, disk_cat);
    153154        if (rc != EOK) {
    154155                printf("%s: Failed adding %s to category: %s",
     
    176177
    177178        async_set_fallback_port_handler(file_bd_connection, NULL);
    178         errno_t rc = loc_server_register(NAME);
     179        errno_t rc = loc_server_register(NAME, &srv);
    179180        if (rc != EOK) {
    180181                printf("%s: Unable to register driver.\n", NAME);
     
    183184
    184185        img = fopen(fname, "rb+");
    185         if (img == NULL)
    186                 return EINVAL;
     186        if (img == NULL) {
     187                rc = EINVAL;
     188                goto error;
     189        }
    187190
    188191        if (fseek(img, 0, SEEK_END) != 0) {
    189                 fclose(img);
    190                 return EIO;
     192                rc = EIO;
     193                goto error;
    191194        }
    192195
    193196        off64_t img_size = ftell(img);
    194197        if (img_size < 0) {
     198                rc = EIO;
     199                goto error;
     200        }
     201
     202        num_blocks = img_size / block_size;
     203
     204        fibril_mutex_initialize(&dev_lock);
     205
     206        return EOK;
     207error:
     208        if (img != NULL) {
    195209                fclose(img);
    196                 return EIO;
    197         }
    198 
    199         num_blocks = img_size / block_size;
    200 
    201         fibril_mutex_initialize(&dev_lock);
    202 
    203         return EOK;
     210                img = NULL;
     211        }
     212
     213        if (srv != NULL) {
     214                loc_server_unregister(srv);
     215                srv = NULL;
     216        }
     217
     218        return rc;
    204219}
    205220
Note: See TracChangeset for help on using the changeset viewer.