18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* miscellaneous bits 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved. 58c2ecf20Sopenharmony_ci * Written by David Howells (dhowells@redhat.com) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/kernel.h> 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/errno.h> 118c2ecf20Sopenharmony_ci#include "internal.h" 128c2ecf20Sopenharmony_ci#include "afs_fs.h" 138c2ecf20Sopenharmony_ci#include "protocol_uae.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* 168c2ecf20Sopenharmony_ci * convert an AFS abort code to a Linux error number 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ciint afs_abort_to_error(u32 abort_code) 198c2ecf20Sopenharmony_ci{ 208c2ecf20Sopenharmony_ci switch (abort_code) { 218c2ecf20Sopenharmony_ci /* Low errno codes inserted into abort namespace */ 228c2ecf20Sopenharmony_ci case 13: return -EACCES; 238c2ecf20Sopenharmony_ci case 27: return -EFBIG; 248c2ecf20Sopenharmony_ci case 30: return -EROFS; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci /* VICE "special error" codes; 101 - 111 */ 278c2ecf20Sopenharmony_ci case VSALVAGE: return -EIO; 288c2ecf20Sopenharmony_ci case VNOVNODE: return -ENOENT; 298c2ecf20Sopenharmony_ci case VNOVOL: return -ENOMEDIUM; 308c2ecf20Sopenharmony_ci case VVOLEXISTS: return -EEXIST; 318c2ecf20Sopenharmony_ci case VNOSERVICE: return -EIO; 328c2ecf20Sopenharmony_ci case VOFFLINE: return -ENOENT; 338c2ecf20Sopenharmony_ci case VONLINE: return -EEXIST; 348c2ecf20Sopenharmony_ci case VDISKFULL: return -ENOSPC; 358c2ecf20Sopenharmony_ci case VOVERQUOTA: return -EDQUOT; 368c2ecf20Sopenharmony_ci case VBUSY: return -EBUSY; 378c2ecf20Sopenharmony_ci case VMOVED: return -ENXIO; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci /* Volume Location server errors */ 408c2ecf20Sopenharmony_ci case AFSVL_IDEXIST: return -EEXIST; 418c2ecf20Sopenharmony_ci case AFSVL_IO: return -EREMOTEIO; 428c2ecf20Sopenharmony_ci case AFSVL_NAMEEXIST: return -EEXIST; 438c2ecf20Sopenharmony_ci case AFSVL_CREATEFAIL: return -EREMOTEIO; 448c2ecf20Sopenharmony_ci case AFSVL_NOENT: return -ENOMEDIUM; 458c2ecf20Sopenharmony_ci case AFSVL_EMPTY: return -ENOMEDIUM; 468c2ecf20Sopenharmony_ci case AFSVL_ENTDELETED: return -ENOMEDIUM; 478c2ecf20Sopenharmony_ci case AFSVL_BADNAME: return -EINVAL; 488c2ecf20Sopenharmony_ci case AFSVL_BADINDEX: return -EINVAL; 498c2ecf20Sopenharmony_ci case AFSVL_BADVOLTYPE: return -EINVAL; 508c2ecf20Sopenharmony_ci case AFSVL_BADSERVER: return -EINVAL; 518c2ecf20Sopenharmony_ci case AFSVL_BADPARTITION: return -EINVAL; 528c2ecf20Sopenharmony_ci case AFSVL_REPSFULL: return -EFBIG; 538c2ecf20Sopenharmony_ci case AFSVL_NOREPSERVER: return -ENOENT; 548c2ecf20Sopenharmony_ci case AFSVL_DUPREPSERVER: return -EEXIST; 558c2ecf20Sopenharmony_ci case AFSVL_RWNOTFOUND: return -ENOENT; 568c2ecf20Sopenharmony_ci case AFSVL_BADREFCOUNT: return -EINVAL; 578c2ecf20Sopenharmony_ci case AFSVL_SIZEEXCEEDED: return -EINVAL; 588c2ecf20Sopenharmony_ci case AFSVL_BADENTRY: return -EINVAL; 598c2ecf20Sopenharmony_ci case AFSVL_BADVOLIDBUMP: return -EINVAL; 608c2ecf20Sopenharmony_ci case AFSVL_IDALREADYHASHED: return -EINVAL; 618c2ecf20Sopenharmony_ci case AFSVL_ENTRYLOCKED: return -EBUSY; 628c2ecf20Sopenharmony_ci case AFSVL_BADVOLOPER: return -EBADRQC; 638c2ecf20Sopenharmony_ci case AFSVL_BADRELLOCKTYPE: return -EINVAL; 648c2ecf20Sopenharmony_ci case AFSVL_RERELEASE: return -EREMOTEIO; 658c2ecf20Sopenharmony_ci case AFSVL_BADSERVERFLAG: return -EINVAL; 668c2ecf20Sopenharmony_ci case AFSVL_PERM: return -EACCES; 678c2ecf20Sopenharmony_ci case AFSVL_NOMEM: return -EREMOTEIO; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci /* Unified AFS error table */ 708c2ecf20Sopenharmony_ci case UAEPERM: return -EPERM; 718c2ecf20Sopenharmony_ci case UAENOENT: return -ENOENT; 728c2ecf20Sopenharmony_ci case UAEAGAIN: return -EAGAIN; 738c2ecf20Sopenharmony_ci case UAEACCES: return -EACCES; 748c2ecf20Sopenharmony_ci case UAEBUSY: return -EBUSY; 758c2ecf20Sopenharmony_ci case UAEEXIST: return -EEXIST; 768c2ecf20Sopenharmony_ci case UAENOTDIR: return -ENOTDIR; 778c2ecf20Sopenharmony_ci case UAEISDIR: return -EISDIR; 788c2ecf20Sopenharmony_ci case UAEFBIG: return -EFBIG; 798c2ecf20Sopenharmony_ci case UAENOSPC: return -ENOSPC; 808c2ecf20Sopenharmony_ci case UAEROFS: return -EROFS; 818c2ecf20Sopenharmony_ci case UAEMLINK: return -EMLINK; 828c2ecf20Sopenharmony_ci case UAEDEADLK: return -EDEADLK; 838c2ecf20Sopenharmony_ci case UAENAMETOOLONG: return -ENAMETOOLONG; 848c2ecf20Sopenharmony_ci case UAENOLCK: return -ENOLCK; 858c2ecf20Sopenharmony_ci case UAENOTEMPTY: return -ENOTEMPTY; 868c2ecf20Sopenharmony_ci case UAELOOP: return -ELOOP; 878c2ecf20Sopenharmony_ci case UAEOVERFLOW: return -EOVERFLOW; 888c2ecf20Sopenharmony_ci case UAENOMEDIUM: return -ENOMEDIUM; 898c2ecf20Sopenharmony_ci case UAEDQUOT: return -EDQUOT; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci /* RXKAD abort codes; from include/rxrpc/packet.h. ET "RXK" == 0x1260B00 */ 928c2ecf20Sopenharmony_ci case RXKADINCONSISTENCY: return -EPROTO; 938c2ecf20Sopenharmony_ci case RXKADPACKETSHORT: return -EPROTO; 948c2ecf20Sopenharmony_ci case RXKADLEVELFAIL: return -EKEYREJECTED; 958c2ecf20Sopenharmony_ci case RXKADTICKETLEN: return -EKEYREJECTED; 968c2ecf20Sopenharmony_ci case RXKADOUTOFSEQUENCE: return -EPROTO; 978c2ecf20Sopenharmony_ci case RXKADNOAUTH: return -EKEYREJECTED; 988c2ecf20Sopenharmony_ci case RXKADBADKEY: return -EKEYREJECTED; 998c2ecf20Sopenharmony_ci case RXKADBADTICKET: return -EKEYREJECTED; 1008c2ecf20Sopenharmony_ci case RXKADUNKNOWNKEY: return -EKEYREJECTED; 1018c2ecf20Sopenharmony_ci case RXKADEXPIRED: return -EKEYEXPIRED; 1028c2ecf20Sopenharmony_ci case RXKADSEALEDINCON: return -EKEYREJECTED; 1038c2ecf20Sopenharmony_ci case RXKADDATALEN: return -EKEYREJECTED; 1048c2ecf20Sopenharmony_ci case RXKADILLEGALLEVEL: return -EKEYREJECTED; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci case RXGEN_OPCODE: return -ENOTSUPP; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci default: return -EREMOTEIO; 1098c2ecf20Sopenharmony_ci } 1108c2ecf20Sopenharmony_ci} 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/* 1138c2ecf20Sopenharmony_ci * Select the error to report from a set of errors. 1148c2ecf20Sopenharmony_ci */ 1158c2ecf20Sopenharmony_civoid afs_prioritise_error(struct afs_error *e, int error, u32 abort_code) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci switch (error) { 1188c2ecf20Sopenharmony_ci case 0: 1198c2ecf20Sopenharmony_ci return; 1208c2ecf20Sopenharmony_ci default: 1218c2ecf20Sopenharmony_ci if (e->error == -ETIMEDOUT || 1228c2ecf20Sopenharmony_ci e->error == -ETIME) 1238c2ecf20Sopenharmony_ci return; 1248c2ecf20Sopenharmony_ci fallthrough; 1258c2ecf20Sopenharmony_ci case -ETIMEDOUT: 1268c2ecf20Sopenharmony_ci case -ETIME: 1278c2ecf20Sopenharmony_ci if (e->error == -ENOMEM || 1288c2ecf20Sopenharmony_ci e->error == -ENONET) 1298c2ecf20Sopenharmony_ci return; 1308c2ecf20Sopenharmony_ci fallthrough; 1318c2ecf20Sopenharmony_ci case -ENOMEM: 1328c2ecf20Sopenharmony_ci case -ENONET: 1338c2ecf20Sopenharmony_ci if (e->error == -ERFKILL) 1348c2ecf20Sopenharmony_ci return; 1358c2ecf20Sopenharmony_ci fallthrough; 1368c2ecf20Sopenharmony_ci case -ERFKILL: 1378c2ecf20Sopenharmony_ci if (e->error == -EADDRNOTAVAIL) 1388c2ecf20Sopenharmony_ci return; 1398c2ecf20Sopenharmony_ci fallthrough; 1408c2ecf20Sopenharmony_ci case -EADDRNOTAVAIL: 1418c2ecf20Sopenharmony_ci if (e->error == -ENETUNREACH) 1428c2ecf20Sopenharmony_ci return; 1438c2ecf20Sopenharmony_ci fallthrough; 1448c2ecf20Sopenharmony_ci case -ENETUNREACH: 1458c2ecf20Sopenharmony_ci if (e->error == -EHOSTUNREACH) 1468c2ecf20Sopenharmony_ci return; 1478c2ecf20Sopenharmony_ci fallthrough; 1488c2ecf20Sopenharmony_ci case -EHOSTUNREACH: 1498c2ecf20Sopenharmony_ci if (e->error == -EHOSTDOWN) 1508c2ecf20Sopenharmony_ci return; 1518c2ecf20Sopenharmony_ci fallthrough; 1528c2ecf20Sopenharmony_ci case -EHOSTDOWN: 1538c2ecf20Sopenharmony_ci if (e->error == -ECONNREFUSED) 1548c2ecf20Sopenharmony_ci return; 1558c2ecf20Sopenharmony_ci fallthrough; 1568c2ecf20Sopenharmony_ci case -ECONNREFUSED: 1578c2ecf20Sopenharmony_ci if (e->error == -ECONNRESET) 1588c2ecf20Sopenharmony_ci return; 1598c2ecf20Sopenharmony_ci fallthrough; 1608c2ecf20Sopenharmony_ci case -ECONNRESET: /* Responded, but call expired. */ 1618c2ecf20Sopenharmony_ci if (e->responded) 1628c2ecf20Sopenharmony_ci return; 1638c2ecf20Sopenharmony_ci e->error = error; 1648c2ecf20Sopenharmony_ci return; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci case -ECONNABORTED: 1678c2ecf20Sopenharmony_ci e->responded = true; 1688c2ecf20Sopenharmony_ci e->error = afs_abort_to_error(abort_code); 1698c2ecf20Sopenharmony_ci return; 1708c2ecf20Sopenharmony_ci } 1718c2ecf20Sopenharmony_ci} 172