@@ -425,6 +425,39 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
425
425
}
426
426
}
427
427
428
+ static int check_hdev_writable (BDRVRawState * s )
429
+ {
430
+ #if defined(BLKROGET )
431
+ /* Linux block devices can be configured "read-only" using blockdev(8).
432
+ * This is independent of device node permissions and therefore open(2)
433
+ * with O_RDWR succeeds. Actual writes fail with EPERM.
434
+ *
435
+ * bdrv_open() is supposed to fail if the disk is read-only. Explicitly
436
+ * check for read-only block devices so that Linux block devices behave
437
+ * properly.
438
+ */
439
+ struct stat st ;
440
+ int readonly = 0 ;
441
+
442
+ if (fstat (s -> fd , & st )) {
443
+ return - errno ;
444
+ }
445
+
446
+ if (!S_ISBLK (st .st_mode )) {
447
+ return 0 ;
448
+ }
449
+
450
+ if (ioctl (s -> fd , BLKROGET , & readonly ) < 0 ) {
451
+ return - errno ;
452
+ }
453
+
454
+ if (readonly ) {
455
+ return - EACCES ;
456
+ }
457
+ #endif /* defined(BLKROGET) */
458
+ return 0 ;
459
+ }
460
+
428
461
static void raw_parse_flags (int bdrv_flags , int * open_flags , bool has_writers )
429
462
{
430
463
bool read_write = false;
@@ -3323,39 +3356,6 @@ static int hdev_probe_device(const char *filename)
3323
3356
return 0 ;
3324
3357
}
3325
3358
3326
- static int check_hdev_writable (BDRVRawState * s )
3327
- {
3328
- #if defined(BLKROGET )
3329
- /* Linux block devices can be configured "read-only" using blockdev(8).
3330
- * This is independent of device node permissions and therefore open(2)
3331
- * with O_RDWR succeeds. Actual writes fail with EPERM.
3332
- *
3333
- * bdrv_open() is supposed to fail if the disk is read-only. Explicitly
3334
- * check for read-only block devices so that Linux block devices behave
3335
- * properly.
3336
- */
3337
- struct stat st ;
3338
- int readonly = 0 ;
3339
-
3340
- if (fstat (s -> fd , & st )) {
3341
- return - errno ;
3342
- }
3343
-
3344
- if (!S_ISBLK (st .st_mode )) {
3345
- return 0 ;
3346
- }
3347
-
3348
- if (ioctl (s -> fd , BLKROGET , & readonly ) < 0 ) {
3349
- return - errno ;
3350
- }
3351
-
3352
- if (readonly ) {
3353
- return - EACCES ;
3354
- }
3355
- #endif /* defined(BLKROGET) */
3356
- return 0 ;
3357
- }
3358
-
3359
3359
static void hdev_parse_filename (const char * filename , QDict * options ,
3360
3360
Error * * errp )
3361
3361
{
0 commit comments