Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/makefs/ffs/mkfs.c
Show First 20 Lines • Show All 788 Lines • ▼ Show 20 Lines | |||||
* read a block from the file system | * read a block from the file system | ||||
*/ | */ | ||||
void | void | ||||
ffs_rdfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts) | ffs_rdfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts) | ||||
{ | { | ||||
int n; | int n; | ||||
off_t offset; | off_t offset; | ||||
offset = bno * fsopts->sectorsize + fsopts->offset; | offset = (off_t)bno * fsopts->sectorsize + fsopts->offset; | ||||
if (lseek(fsopts->fd, offset, SEEK_SET) < 0) | if (lseek(fsopts->fd, offset, SEEK_SET) < 0) | ||||
err(1, "%s: seek error for sector %lld", __func__, | err(1, "%s: seek error for sector %lld", __func__, | ||||
(long long)bno); | (long long)bno); | ||||
n = read(fsopts->fd, bf, size); | n = read(fsopts->fd, bf, size); | ||||
if (n == -1) { | if (n == -1) { | ||||
abort(); | abort(); | ||||
err(1, "%s: read error bno %lld size %d", __func__, | err(1, "%s: read error bno %lld size %d", __func__, | ||||
(long long)bno, size); | (long long)bno, size); | ||||
} | } | ||||
else if (n != size) | else if (n != size) | ||||
errx(1, "%s: read error for sector %lld", __func__, | errx(1, "%s: read error for sector %lld", __func__, | ||||
(long long)bno); | (long long)bno); | ||||
} | } | ||||
/* | /* | ||||
* write a block to the file system | * write a block to the file system | ||||
*/ | */ | ||||
void | void | ||||
ffs_wtfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts) | ffs_wtfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts) | ||||
{ | { | ||||
int n; | int n; | ||||
off_t offset; | off_t offset; | ||||
offset = bno * fsopts->sectorsize + fsopts->offset; | offset = (off_t)bno * fsopts->sectorsize + fsopts->offset; | ||||
if (lseek(fsopts->fd, offset, SEEK_SET) < 0) | if (lseek(fsopts->fd, offset, SEEK_SET) < 0) | ||||
err(1, "%s: seek error for sector %lld", __func__, | err(1, "%s: seek error for sector %lld", __func__, | ||||
(long long)bno); | (long long)bno); | ||||
n = write(fsopts->fd, bf, size); | n = write(fsopts->fd, bf, size); | ||||
if (n == -1) | if (n == -1) | ||||
err(1, "%s: write error for sector %lld", __func__, | err(1, "%s: write error for sector %lld", __func__, | ||||
(long long)bno); | (long long)bno); | ||||
else if (n != size) | else if (n != size) | ||||
Show All 26 Lines |