Changeset b7fd2a0 in mainline for uspace/lib/c/generic/vfs/vfs.c


Ignore:
Timestamp:
2018-01-13T03:10:29Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a53ed3a
Parents:
36f0738
Message:

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

File:
1 edited

Legend:

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

    r36f0738 rb7fd2a0  
    8686 * and consume system resources.
    8787 *
    88  * Functions that return int return an error code on error and do not
     88 * Functions that return errno_t return an error code on error and do not
    8989 * set errno. Depending on function, success is signalled by returning either
    9090 * EOK or a non-negative file handle.
     
    9797 *      if (file < 0)
    9898 *              return file;
    99  *      int rc = vfs_open(file, MODE_READ);
     99 *      errno_t rc = vfs_open(file, MODE_READ);
    100100 *      if (rc != EOK) {
    101101 *              (void) vfs_put(file);
     
    128128static int root_fd = -1;
    129129
    130 static int get_parent_and_child(const char *path, int *parent, char **child)
     130static errno_t get_parent_and_child(const char *path, int *parent, char **child)
    131131{
    132132        size_t size;
     
    146146        } else {
    147147                *slash = '\0';
    148                 int rc = vfs_lookup(apath, WALK_DIRECTORY, parent);
     148                errno_t rc = vfs_lookup(apath, WALK_DIRECTORY, parent);
    149149                if (rc != EOK) {
    150150                        free(apath);
     
    238238 * @return              New file handle on success or an error code
    239239 */
    240 int vfs_clone(int file_from, int file_to, bool high, int *handle)
     240errno_t vfs_clone(int file_from, int file_to, bool high, int *handle)
    241241{
    242242        assert(handle != NULL);
     
    244244        async_exch_t *vfs_exch = vfs_exchange_begin();
    245245        sysarg_t ret;
    246         int rc = async_req_3_1(vfs_exch, VFS_IN_CLONE, (sysarg_t) file_from,
     246        errno_t rc = async_req_3_1(vfs_exch, VFS_IN_CLONE, (sysarg_t) file_from,
    247247            (sysarg_t) file_to, (sysarg_t) high, &ret);
    248248        vfs_exchange_end(vfs_exch);
     
    261261 * @return              EOK on success or a non-error code
    262262 */
    263 int vfs_cwd_get(char *buf, size_t size)
     263errno_t vfs_cwd_get(char *buf, size_t size)
    264264{
    265265        fibril_mutex_lock(&cwd_mutex);
     
    282282 * @return      EOK on success or an error code
    283283 */
    284 int vfs_cwd_set(const char *path)
     284errno_t vfs_cwd_set(const char *path)
    285285{
    286286        size_t abs_size;
     
    290290       
    291291        int fd;
    292         int rc = vfs_lookup(abs, WALK_DIRECTORY, &fd);
     292        errno_t rc = vfs_lookup(abs, WALK_DIRECTORY, &fd);
    293293        if (rc != EOK) {
    294294                free(abs);
     
    353353{
    354354        struct stat stat;
    355         int rc = vfs_stat(file, &stat);
     355        errno_t rc = vfs_stat(file, &stat);
    356356        if (rc != 0)
    357357                return NULL;
     
    372372 * @return                      EOK on success or an error code
    373373 */
    374 int vfs_fsprobe(const char *fs_name, service_id_t serv,
     374errno_t vfs_fsprobe(const char *fs_name, service_id_t serv,
    375375    vfs_fs_probe_info_t *info)
    376376{
    377         int rc;
     377        errno_t rc;
    378378       
    379379        ipc_call_t answer;
     
    406406 * @return                      EOK on success or an error code
    407407 */
    408 int vfs_fstypes(vfs_fstypes_t *fstypes)
     408errno_t vfs_fstypes(vfs_fstypes_t *fstypes)
    409409{
    410410        sysarg_t size;
     
    414414
    415415        async_exch_t *exch = vfs_exchange_begin();
    416         int rc = async_req_0_1(exch, VFS_IN_FSTYPES, &size);
     416        errno_t rc = async_req_0_1(exch, VFS_IN_FSTYPES, &size);
    417417
    418418        if (rc != EOK) {
     
    501501 * @return              EOK on success or an error code
    502502 */
    503 int vfs_link(int parent, const char *child, vfs_file_kind_t kind, int *linkedfd)
     503errno_t vfs_link(int parent, const char *child, vfs_file_kind_t kind, int *linkedfd)
    504504{
    505505        int flags = (kind == KIND_DIRECTORY) ? WALK_DIRECTORY : WALK_REGULAR;
    506506        int file = -1;
    507         int rc = vfs_walk(parent, child, WALK_MUST_CREATE | flags, &file);
     507        errno_t rc = vfs_walk(parent, child, WALK_MUST_CREATE | flags, &file);
    508508        if (rc != EOK)
    509509                return rc;
     
    531531 * @return              EOK on success or an error code
    532532 */
    533 int vfs_link_path(const char *path, vfs_file_kind_t kind, int *linkedfd)
     533errno_t vfs_link_path(const char *path, vfs_file_kind_t kind, int *linkedfd)
    534534{
    535535        char *child;
    536536        int parent;
    537         int rc = get_parent_and_child(path, &parent, &child);
     537        errno_t rc = get_parent_and_child(path, &parent, &child);
    538538        if (rc != EOK)
    539539                return rc;
     
    554554 * @return      EOK on success or an error code.
    555555 */
    556 int vfs_lookup(const char *path, int flags, int *handle)
     556errno_t vfs_lookup(const char *path, int flags, int *handle)
    557557{
    558558        size_t size;
     
    570570        *handle = -1;
    571571
    572         int rc = vfs_walk(root, p, flags, handle);
     572        errno_t rc = vfs_walk(root, p, flags, handle);
    573573        vfs_put(root);
    574574        free(p);
     
    587587 * @return      EOK on success or an error code
    588588 */
    589 int vfs_lookup_open(const char *path, int flags, int mode, int *handle)
     589errno_t vfs_lookup_open(const char *path, int flags, int mode, int *handle)
    590590{
    591591        int file;
    592         int rc = vfs_lookup(path, flags, &file);
     592        errno_t rc = vfs_lookup(path, flags, &file);
    593593        if (rc != EOK)
    594594                return rc;
     
    616616 * @return                      EOK on success or an error code
    617617 */
    618 int vfs_mount(int mp, const char *fs_name, service_id_t serv, const char *opts,
     618errno_t vfs_mount(int mp, const char *fs_name, service_id_t serv, const char *opts,
    619619    unsigned int flags, unsigned int instance, int *mountedfd)
    620620{
    621         int rc, rc1;
     621        errno_t rc, rc1;
    622622       
    623623        if (!mountedfd)
     
    660660 * @return                      EOK on success or an error code
    661661 */
    662 int vfs_mount_path(const char *mp, const char *fs_name, const char *fqsn,
     662errno_t vfs_mount_path(const char *mp, const char *fs_name, const char *fqsn,
    663663    const char *opts, unsigned int flags, unsigned int instance)
    664664{
     
    685685       
    686686        service_id_t service_id;
    687         int res = loc_service_get_id(fqsn, &service_id, flags);
     687        errno_t res = loc_service_get_id(fqsn, &service_id, flags);
    688688        if (res != EOK) {
    689689                if (null_id != -1)
     
    704704        fibril_mutex_lock(&root_mutex);
    705705       
    706         int rc;
     706        errno_t rc;
    707707       
    708708        if (str_cmp(mpa, "/") == 0) {
     
    743743                loc_null_destroy(null_id);
    744744       
    745         return (int) rc;
     745        return (errno_t) rc;
    746746}
    747747
     
    754754 * @return      EOK on success or an error code
    755755 */
    756 int vfs_open(int file, int mode)
    757 {
    758         async_exch_t *exch = vfs_exchange_begin();
    759         int rc = async_req_2_0(exch, VFS_IN_OPEN, file, mode);
     756errno_t vfs_open(int file, int mode)
     757{
     758        async_exch_t *exch = vfs_exchange_begin();
     759        errno_t rc = async_req_2_0(exch, VFS_IN_OPEN, file, mode);
    760760        vfs_exchange_end(exch);
    761761       
     
    771771 * @return              EOK on success or an error code
    772772 */
    773 int vfs_pass_handle(async_exch_t *vfs_exch, int file, async_exch_t *exch)
     773errno_t vfs_pass_handle(async_exch_t *vfs_exch, int file, async_exch_t *exch)
    774774{
    775775        return async_state_change_start(exch, VFS_PASS_HANDLE, (sysarg_t) file,
     
    783783 * @return      EOK on success or an error code
    784784 */
    785 int vfs_put(int file)
    786 {
    787         async_exch_t *exch = vfs_exchange_begin();
    788         int rc = async_req_1_0(exch, VFS_IN_PUT, file);
     785errno_t vfs_put(int file)
     786{
     787        async_exch_t *exch = vfs_exchange_begin();
     788        errno_t rc = async_req_1_0(exch, VFS_IN_PUT, file);
    789789        vfs_exchange_end(exch);
    790790       
     
    800800 * @return       EOK on success or an error code
    801801 */
    802 int vfs_receive_handle(bool high, int *handle)
     802errno_t vfs_receive_handle(bool high, int *handle)
    803803{
    804804        ipc_callid_t callid;
     
    813813
    814814        sysarg_t ret;
    815         int rc = async_req_1_1(vfs_exch, VFS_IN_WAIT_HANDLE, high, &ret);
     815        errno_t rc = async_req_1_1(vfs_exch, VFS_IN_WAIT_HANDLE, high, &ret);
    816816
    817817        async_exchange_end(vfs_exch);
     
    839839 * @return              On failure, an error code
    840840 */
    841 int vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte, size_t *nread)
     841errno_t vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte, size_t *nread)
    842842{
    843843        ssize_t cnt = 0;
    844844        size_t nr = 0;
    845845        uint8_t *bp = (uint8_t *) buf;
    846         int rc;
     846        errno_t rc;
    847847       
    848848        do {
     
    879879 * @return              EOK on success or an error code
    880880 */
    881 int vfs_read_short(int file, aoff64_t pos, void *buf, size_t nbyte,
     881errno_t vfs_read_short(int file, aoff64_t pos, void *buf, size_t nbyte,
    882882    ssize_t *nread)
    883883{
    884         int rc;
     884        errno_t rc;
    885885        ipc_call_t answer;
    886886        aid_t req;
     
    921921 * @return      EOK on success or an error code
    922922 */
    923 int vfs_rename_path(const char *old, const char *new)
    924 {
    925         int rc;
    926         int rc_orig;
     923errno_t vfs_rename_path(const char *old, const char *new)
     924{
     925        errno_t rc;
     926        errno_t rc_orig;
    927927        aid_t req;
    928928       
     
    988988 * @return              EOK on success or an error code
    989989 */
    990 int vfs_resize(int file, aoff64_t length)
    991 {
    992         async_exch_t *exch = vfs_exchange_begin();
    993         int rc = async_req_3_0(exch, VFS_IN_RESIZE, file, LOWER32(length),
     990errno_t vfs_resize(int file, aoff64_t length)
     991{
     992        async_exch_t *exch = vfs_exchange_begin();
     993        errno_t rc = async_req_3_0(exch, VFS_IN_RESIZE, file, LOWER32(length),
    994994            UPPER32(length));
    995995        vfs_exchange_end(exch);
     
    10091009                fd = -1;
    10101010        } else {
    1011                 int rc = vfs_clone(root_fd, -1, true, &fd);
     1011                errno_t rc = vfs_clone(root_fd, -1, true, &fd);
    10121012                if (rc != EOK) {
    10131013                        fd = -1;
     
    10281028 * @return  Error code
    10291029 */
    1030 int vfs_root_set(int nroot)
     1030errno_t vfs_root_set(int nroot)
    10311031{
    10321032        int new_root;
    1033         int rc = vfs_clone(nroot, -1, true, &new_root);
     1033        errno_t rc = vfs_clone(nroot, -1, true, &new_root);
    10341034        if (rc != EOK) {
    10351035                return rc;
     
    10521052 * @return              EOK on success or an error code
    10531053 */
    1054 int vfs_stat(int file, struct stat *stat)
    1055 {
    1056         int rc;
     1054errno_t vfs_stat(int file, struct stat *stat)
     1055{
     1056        errno_t rc;
    10571057        aid_t req;
    10581058       
     
    10641064                vfs_exchange_end(exch);
    10651065               
    1066                 int rc_orig;
     1066                errno_t rc_orig;
    10671067                async_wait_for(req, &rc_orig);
    10681068               
     
    10861086 * @return              EOK on success or an error code
    10871087 */
    1088 int vfs_stat_path(const char *path, struct stat *stat)
     1088errno_t vfs_stat_path(const char *path, struct stat *stat)
    10891089{
    10901090        int file;
    1091         int rc = vfs_lookup(path, 0, &file);
     1091        errno_t rc = vfs_lookup(path, 0, &file);
    10921092        if (rc != EOK)
    10931093                return rc;
     
    11071107 * @return              EOK on success or an error code
    11081108 */
    1109 int vfs_statfs(int file, struct statfs *st)
    1110 {
    1111         int rc, ret;
     1109errno_t vfs_statfs(int file, struct statfs *st)
     1110{
     1111        errno_t rc, ret;
    11121112        aid_t req;
    11131113
     
    11321132 * @return              EOK on success or an error code
    11331133 */
    1134 int vfs_statfs_path(const char *path, struct statfs *st)
     1134errno_t vfs_statfs_path(const char *path, struct statfs *st)
    11351135{
    11361136        int file;
    1137         int rc = vfs_lookup(path, 0, &file);
     1137        errno_t rc = vfs_lookup(path, 0, &file);
    11381138        if (rc != EOK)
    11391139                return rc;
     
    11521152 * @return      EOK on success or an error code
    11531153 */
    1154 int vfs_sync(int file)
    1155 {
    1156         async_exch_t *exch = vfs_exchange_begin();
    1157         int rc = async_req_1_0(exch, VFS_IN_SYNC, file);
     1154errno_t vfs_sync(int file)
     1155{
     1156        async_exch_t *exch = vfs_exchange_begin();
     1157        errno_t rc = async_req_1_0(exch, VFS_IN_SYNC, file);
    11581158        vfs_exchange_end(exch);
    11591159       
     
    11741174 * @return              EOK on success or an error code
    11751175 */
    1176 int vfs_unlink(int parent, const char *child, int expect)
    1177 {
    1178         int rc;
     1176errno_t vfs_unlink(int parent, const char *child, int expect)
     1177{
     1178        errno_t rc;
    11791179        aid_t req;
    11801180       
     
    11861186        vfs_exchange_end(exch);
    11871187       
    1188         int rc_orig;
     1188        errno_t rc_orig;
    11891189        async_wait_for(req, &rc_orig);
    11901190       
    11911191        if (rc_orig != EOK)
    1192                 return (int) rc_orig;
     1192                return (errno_t) rc_orig;
    11931193        return rc;
    11941194}
     
    12031203 * @return              EOK on success or an error code
    12041204 */
    1205 int vfs_unlink_path(const char *path)
     1205errno_t vfs_unlink_path(const char *path)
    12061206{
    12071207        int expect;
    1208         int rc = vfs_lookup(path, 0, &expect);
     1208        errno_t rc = vfs_lookup(path, 0, &expect);
    12091209        if (rc != EOK)
    12101210                return rc;
     
    12321232 * @return      EOK on success or an error code
    12331233 */
    1234 int vfs_unmount(int mp)
    1235 {
    1236         async_exch_t *exch = vfs_exchange_begin();
    1237         int rc = async_req_1_0(exch, VFS_IN_UNMOUNT, mp);
     1234errno_t vfs_unmount(int mp)
     1235{
     1236        async_exch_t *exch = vfs_exchange_begin();
     1237        errno_t rc = async_req_1_0(exch, VFS_IN_UNMOUNT, mp);
    12381238        vfs_exchange_end(exch);
    12391239        return rc;
     
    12461246 * @return      EOK on success or an error code
    12471247 */
    1248 int vfs_unmount_path(const char *mpp)
     1248errno_t vfs_unmount_path(const char *mpp)
    12491249{
    12501250        int mp;
    1251         int rc = vfs_lookup(mpp, WALK_MOUNT_POINT | WALK_DIRECTORY, &mp);
     1251        errno_t rc = vfs_lookup(mpp, WALK_MOUNT_POINT | WALK_DIRECTORY, &mp);
    12521252        if (rc != EOK)
    12531253                return rc;
     
    12671267 * @return              Error code.
    12681268 */
    1269 int vfs_walk(int parent, const char *path, int flags, int *handle)
     1269errno_t vfs_walk(int parent, const char *path, int flags, int *handle)
    12701270{
    12711271        async_exch_t *exch = vfs_exchange_begin();
     
    12731273        ipc_call_t answer;
    12741274        aid_t req = async_send_2(exch, VFS_IN_WALK, parent, flags, &answer);
    1275         int rc = async_data_write_start(exch, path, str_size(path));
     1275        errno_t rc = async_data_write_start(exch, path, str_size(path));
    12761276        vfs_exchange_end(exch);
    12771277               
    1278         int rc_orig;
     1278        errno_t rc_orig;
    12791279        async_wait_for(req, &rc_orig);
    12801280
    12811281        if (rc_orig != EOK)
    1282                 return (int) rc_orig;
     1282                return (errno_t) rc_orig;
    12831283               
    12841284        if (rc != EOK)
    1285                 return (int) rc;
     1285                return (errno_t) rc;
    12861286       
    12871287        *handle = (int) IPC_GET_ARG1(answer);
     
    13041304 * @return              On failure, an error code
    13051305 */
    1306 int vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte,
     1306errno_t vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte,
    13071307    size_t *nwritten)
    13081308{
     
    13101310        ssize_t nwr = 0;
    13111311        const uint8_t *bp = (uint8_t *) buf;
    1312         int rc;
     1312        errno_t rc;
    13131313
    13141314        do {
     
    13431343 * @return              EOK on success or an error code
    13441344 */
    1345 int vfs_write_short(int file, aoff64_t pos, const void *buf, size_t nbyte,
     1345errno_t vfs_write_short(int file, aoff64_t pos, const void *buf, size_t nbyte,
    13461346    ssize_t *nwritten)
    13471347{
    1348         int rc;
     1348        errno_t rc;
    13491349        ipc_call_t answer;
    13501350        aid_t req;
Note: See TracChangeset for help on using the changeset viewer.