1 // SPDX-License-Identifier: GPL-2.0-or-later
6 #define DEVPATHSTR_SIZE 15
8 static const char *const fit0
= "/dev/fit0";
9 static const char *const fitrw
= "/dev/fitrw";
19 char devpathstr
[DEVPATHSTR_SIZE
+1];
20 struct devpath devpath
;
24 static struct driver fit_driver
;
26 static int fit_volume_identify(struct volume
*v
)
28 struct fit_volume
*p
= container_of(v
, struct fit_volume
, v
);
32 f
= fopen(p
->dev
.devpathstr
, "r");
36 ret
= block_file_identify(f
, 0);
43 static int fit_volume_init(struct volume
*v
)
45 struct fit_volume
*p
= container_of(v
, struct fit_volume
, v
);
49 snprintf(voldir
, sizeof(voldir
), "%s/%s", block_dir_name
, p
->dev
.devpath
.device
);
51 if (read_uint_from_file(voldir
, "size", &volsize
))
55 v
->size
= volsize
<< 9; /* size is returned in sectors of 512 bytes */
56 v
->blk
= p
->dev
.devpathstr
;
58 return block_volume_format(v
, 0, p
->dev
.devpathstr
);
61 static struct volume
*fit_volume_find(char *name
)
68 if (!strcmp(name
, "rootfs"))
70 else if (!strcmp(name
, "rootfs_data"))
75 ret
= stat(fname
, &buf
);
79 p
= calloc(1, sizeof(struct fit_volume
));
83 strncpy(p
->dev
.devpathstr
, fname
, DEVPATHSTR_SIZE
);
84 p
->v
.drv
= &fit_driver
;
85 p
->v
.blk
= p
->dev
.devpathstr
;
91 static struct driver fit_driver
= {
94 .find
= fit_volume_find
,
95 .init
= fit_volume_init
,
96 .identify
= fit_volume_identify
,