die
This commit is contained in:
parent
e07ca66145
commit
840aae871f
44
mkfs/mkfs.c
44
mkfs/mkfs.c
|
@ -40,6 +40,7 @@ void rinode(uint inum, struct dinode *ip);
|
||||||
void rsect(uint sec, void *buf);
|
void rsect(uint sec, void *buf);
|
||||||
uint ialloc(ushort type);
|
uint ialloc(ushort type);
|
||||||
void iappend(uint inum, void *p, int n);
|
void iappend(uint inum, void *p, int n);
|
||||||
|
void die(const char *);
|
||||||
|
|
||||||
// convert to intel byte order
|
// convert to intel byte order
|
||||||
ushort
|
ushort
|
||||||
|
@ -85,10 +86,8 @@ main(int argc, char *argv[])
|
||||||
assert((BSIZE % sizeof(struct dirent)) == 0);
|
assert((BSIZE % sizeof(struct dirent)) == 0);
|
||||||
|
|
||||||
fsfd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666);
|
fsfd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666);
|
||||||
if(fsfd < 0){
|
if(fsfd < 0)
|
||||||
perror(argv[1]);
|
die(argv[1]);
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1 fs block = 1 disk sector
|
// 1 fs block = 1 disk sector
|
||||||
nmeta = 2 + nlog + ninodeblocks + nbitmap;
|
nmeta = 2 + nlog + ninodeblocks + nbitmap;
|
||||||
|
@ -138,10 +137,8 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
assert(index(shortname, '/') == 0);
|
assert(index(shortname, '/') == 0);
|
||||||
|
|
||||||
if((fd = open(argv[i], 0)) < 0){
|
if((fd = open(argv[i], 0)) < 0)
|
||||||
perror(argv[i]);
|
die(argv[i]);
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip leading _ in name when writing to file system.
|
// Skip leading _ in name when writing to file system.
|
||||||
// The binaries are named _rm, _cat, etc. to keep the
|
// The binaries are named _rm, _cat, etc. to keep the
|
||||||
|
@ -178,14 +175,10 @@ main(int argc, char *argv[])
|
||||||
void
|
void
|
||||||
wsect(uint sec, void *buf)
|
wsect(uint sec, void *buf)
|
||||||
{
|
{
|
||||||
if(lseek(fsfd, sec * BSIZE, 0) != sec * BSIZE){
|
if(lseek(fsfd, sec * BSIZE, 0) != sec * BSIZE)
|
||||||
perror("lseek");
|
die("lseek");
|
||||||
exit(1);
|
if(write(fsfd, buf, BSIZE) != BSIZE)
|
||||||
}
|
die("write");
|
||||||
if(write(fsfd, buf, BSIZE) != BSIZE){
|
|
||||||
perror("write");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -218,14 +211,10 @@ rinode(uint inum, struct dinode *ip)
|
||||||
void
|
void
|
||||||
rsect(uint sec, void *buf)
|
rsect(uint sec, void *buf)
|
||||||
{
|
{
|
||||||
if(lseek(fsfd, sec * BSIZE, 0) != sec * BSIZE){
|
if(lseek(fsfd, sec * BSIZE, 0) != sec * BSIZE)
|
||||||
perror("lseek");
|
die("lseek");
|
||||||
exit(1);
|
if(read(fsfd, buf, BSIZE) != BSIZE)
|
||||||
}
|
die("read");
|
||||||
if(read(fsfd, buf, BSIZE) != BSIZE){
|
|
||||||
perror("read");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint
|
uint
|
||||||
|
@ -303,3 +292,10 @@ iappend(uint inum, void *xp, int n)
|
||||||
din.size = xint(off);
|
din.size = xint(off);
|
||||||
winode(inum, &din);
|
winode(inum, &din);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
die(const char *s)
|
||||||
|
{
|
||||||
|
perror(s);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue