From 8bec55b976d1ccb47bb6303404854730a88bfef7 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 10 Apr 2018 11:45:22 -0700 Subject: [PATCH] DISK: Properly fail an attempt to access to a non-existent file in raw mode --- sim_disk.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sim_disk.c b/sim_disk.c index 18f8ccfe..972fd7b6 100644 --- a/sim_disk.c +++ b/sim_disk.c @@ -2622,6 +2622,12 @@ if (strchr (openmode, 'r') && (strchr (openmode, '+') || strchr (openmode, 'w')) else if (strchr (openmode, 'r')) mode = O_RDONLY; +if (mode == O_RDONLY) { + struct stat statb; + + if (stat (rawdevicename, &statb)) /* test for existence/access */ + return (FILE *)NULL; + } #ifdef O_LARGEFILE mode |= O_LARGEFILE; #endif