This commit is contained in:
Pavan Maddamsetti 2020-10-21 03:03:17 -04:00 committed by Frans Kaashoek
parent e07ca66145
commit 840aae871f

View file

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