0

C program that reads a disk image specified as a command line argument and prints the paths for all files and directories in the image.If the entry is a directory, print a forward slash at the end of the path....This is my question in program and i done code as below....

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>

#define K 1024

typedef struct dir {
unsigned int my_node;
unsigned short my_length;
unsigned char my_namelen;
}DIRPATH;



unsigned int getint(int fd, int block, int byte);
unsigned short int getshort(int fd, int block, int byte);


int main (int argc , char *argv[])
{
int i;
int nameleng;
char name[K];
DIRPATH dh;
int argument;
int fd;

argument = (argc > 1) ? atoi(argv[1]) : 0;
fd=open(argv[1],O_RDONLY);
fprintf(stderr,"fd=%d\n",fd);
if(lseek(fd,K,SEEK_SET)<0)
{
fprintf(stderr,"unable to seek");
exit(0);
}
int itab = getint(fd,2,8);
unsigned int first_block = getint(fd,itab,inode_size + 40);
int length=0;
for(i=0;i<6;i++)
{
lseek(fd,first_block * K + length,SEEK_SET);
read(fd,&dh,sizeof(DIRPATH));
length += dh.my_length;
printf("",dh.my_namelen);
read(fd,name,dh.my_namelen);
name[dh.my_namelen] = 0;
printf("%s\n",name);
}
close(fd);
}

unsigned int getint(int fd, int block, int byte)
{
unsigned int x;
int check;
lseek(fd,block * K + byte, SEEK_SET);
check = read(fd, &x, 4);
if(check != 4){
fprintf(stderr,"error to read %d %d \n",block, byte);
exit(0);
}
return(x);
}

unsigned short int getshort(int fd, int block, int byte)
{
unsigned short int x;
int check;
lseek(fd,block * K + byte, SEEK_SET);
check = read(fd, &x, 4);
if(check != 2){
fprintf(stderr,"error to read %d %d \n",block, byte);
exit(0);
}
return(x);
}

I am getting the output but in output it is giving . and ... I have to remove those dots and add / to directories not files.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
  • What do you mean, “can you tell me the errors”? Is your code working or not? If it isn't working, what's wrong? Compilation error? No output? Incorrect output? The program crashes? The program hangs? – Gilles 'SO- stop being evil' Mar 08 '15 at 23:32
  • I am getting the output but in output it is giving . and .. i have to remove those dots and add / to directories not files – Sandy006 Mar 09 '15 at 01:47

0 Answers0