@samitouri / QOSamiQemu / commits / dbaf84e148

hw/9pfs: change V9fsPath.size to size_t and v9fs_path_sprintf() return type

- Change V9fsPath.size from uint16_t to size_t to support paths larger than 65536 bytes. - Change v9fs_path_sprintf() return type from void to int to allow error reporting. Link: https://lore.kernel.org/qemu-devel/2d2348d94ff43fbe4cc0aea24fb312c5c15ee809.1779126034.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>

Christian Schoenebeck committed May 18, 2026 at 19:35 UTC dbaf84e148b0c8b66dcb47788a6bb13806e401e4
3 files changed +14 -6
fsdev/file-op-9p.h
+1 -1
@@ -112,7 +112,7 @@ struct FsContext {
112 };
113
114 struct V9fsPath {
115 - uint16_t size;
115 + size_t size;
116 char *data;
117 };
118 P9ARRAY_DECLARE_TYPE(V9fsPath);
hw/9pfs/9p.c
+11 -3
@@ -203,16 +203,24 @@ void v9fs_path_free(V9fsPath *path)
203 }
204
205
206 -void v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...)
206 +int v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...)
207 {
208 va_list ap;
209 + int ret;
210
211 v9fs_path_free(path);
212
213 va_start(ap, fmt);
213 - /* Bump the size for including terminating NULL */
214 - path->size = g_vasprintf(&path->data, fmt, ap) + 1;
214 + ret = g_vasprintf(&path->data, fmt, ap);
215 va_end(ap);
216 + if (ret < 0) {
217 + error_report_once("9pfs: unusual path formatting failure; "
218 + "invalidating associated FID");
219 + return -1;
220 + }
221 + /* Bump the size for including terminating NULL */
222 + path->size = ret + 1;
223 + return 0;
224 }
225
226 void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src)
hw/9pfs/9p.h
+2 -2
@@ -456,8 +456,8 @@ static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu)
456 void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu);
457 void v9fs_path_init(V9fsPath *path);
458 void v9fs_path_free(V9fsPath *path);
459 -void G_GNUC_PRINTF(2, 3) v9fs_path_sprintf(V9fsPath *path, const char *fmt,
460 - ...);
459 +int G_GNUC_PRINTF(2, 3) v9fs_path_sprintf(V9fsPath *path, const char *fmt,
460 + ...);
461 void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src);
462 size_t v9fs_readdir_response_size(V9fsString *name);
463 int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,