Spinlock save cpu flags

This commit is contained in:
2026-03-12 22:48:34 +01:00
parent 19793e9126
commit 4760818118
50 changed files with 704 additions and 461 deletions

View File

@@ -20,6 +20,8 @@
static int fat1_diskio_read (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* buffer,
uint32_t sector_count) {
uint64_t fd;
struct vfs_volume* volume = ctx->udata;
struct device* back_device = volume->back_device;
@@ -30,11 +32,11 @@ static int fat1_diskio_read (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* bu
size_t phys_sector, phys_sector_count;
int ret;
spin_lock (&back_device->lock);
spin_lock (&back_device->lock, &fd);
ret = device_op (back_device, XDRV_GET_SECTOR_SIZE, ctx->proc, ctx->rctx, &sector_size);
if (ret < 0) {
spin_unlock (&back_device->lock);
spin_unlock (&back_device->lock, fd);
return 0;
}
@@ -44,11 +46,11 @@ static int fat1_diskio_read (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* bu
ret = device_op (back_device, XDRV_READ, ctx->proc, ctx->rctx, &phys_sector, &phys_sector_count,
buffer);
if (ret < 0) {
spin_unlock (&back_device->lock);
spin_unlock (&back_device->lock, fd);
return 0;
}
spin_unlock (&back_device->lock);
spin_unlock (&back_device->lock, fd);
if (ret < 0)
return 0;
@@ -57,6 +59,8 @@ static int fat1_diskio_read (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* bu
static int fat1_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* buffer,
uint32_t sector_count) {
uint64_t fd;
struct vfs_volume* volume = ctx->udata;
struct device* back_device = volume->back_device;
@@ -67,11 +71,11 @@ static int fat1_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* b
size_t phys_sector, phys_sector_count;
int ret;
spin_lock (&back_device->lock);
spin_lock (&back_device->lock, &fd);
ret = device_op (back_device, XDRV_GET_SECTOR_SIZE, ctx->proc, ctx->rctx, &sector_size);
if (ret < 0) {
spin_unlock (&back_device->lock);
spin_unlock (&back_device->lock, fd);
return 0;
}
@@ -81,11 +85,11 @@ static int fat1_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* b
ret = device_op (back_device, XDRV_WRITE, ctx->proc, ctx->rctx, &phys_sector, &phys_sector_count,
buffer);
if (ret < 0) {
spin_unlock (&back_device->lock);
spin_unlock (&back_device->lock, fd);
return 0;
}
spin_unlock (&back_device->lock);
spin_unlock (&back_device->lock, fd);
if (ret < 0)
return 0;
@@ -124,15 +128,17 @@ int fatfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule
}
int fatfs16_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx) {
uint64_t fd;
struct fatfs_ctx* fatfs_ctx = volume->udata;
struct device* back_device = volume->back_device;
size_t total_size;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
spin_lock (&back_device->lock);
spin_lock (&back_device->lock, &fd);
device_op (back_device, XDRV_GET_SIZE, proc, rctx, &total_size);
spin_unlock (&back_device->lock);
spin_unlock (&back_device->lock, fd);
size_t sectors = div_align_up (total_size, FAT_SECTOR_SIZE);
int r = fatfs_format_fat16 (fatfs_ctx, &fatfs_ctx->_fs, sectors, "mop3 fat16");
@@ -140,15 +146,17 @@ int fatfs16_format (struct vfs_volume* volume, struct proc* proc, struct resched
}
int fatfs32_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx) {
uint64_t fd;
struct fatfs_ctx* fatfs_ctx = volume->udata;
struct device* back_device = volume->back_device;
size_t total_size;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
spin_lock (&back_device->lock);
spin_lock (&back_device->lock, &fd);
device_op (back_device, XDRV_GET_SIZE, proc, rctx, &total_size);
spin_unlock (&back_device->lock);
spin_unlock (&back_device->lock, fd);
size_t sectors = div_align_up (total_size, FAT_SECTOR_SIZE);
int r = fatfs_format_fat32 (fatfs_ctx, &fatfs_ctx->_fs, sectors, "mop3 fat32");