int bd_symlink(const char *pPathExistant, const char *pPathNouveauLien) { int isSuccess = bd_create(pPathNouveauLien); if (isSuccess) { return isSuccess; } // Adds the symbolic link flag int iNode = find_iNode(pPathNouveauLien); add_symlink_flag(iNode); bd_write(pPathNouveauLien, pPathExistant, 0, strlen(pPathExistant)); return 0; }
static int bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize) { struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data); int blks; #ifdef BD_SUPPORT_FRAGS char fragbuf[BIOSDISK_SECSIZE]; size_t fragsize; fragsize = size % BIOSDISK_SECSIZE; #else if (size % BIOSDISK_SECSIZE) panic("bd_strategy: %d bytes I/O not multiple of block size", size); #endif DEBUG("open_disk %p", od); blks = size / BIOSDISK_SECSIZE; if (rsize) *rsize = 0; switch(rw){ case F_READ: DEBUG("read %d from %d to %p", blks, dblk, buf); if (blks && bd_read(od, dblk, blks, buf)) { DEBUG("read error"); return (EIO); } #ifdef BD_SUPPORT_FRAGS DEBUG("bd_strategy: frag read %d from %d+%d to %p", fragsize, dblk, blks, buf + (blks * BIOSDISK_SECSIZE)); if (fragsize && bd_read(od, dblk + blks, 1, fragsize)) { DEBUG("frag read error"); return(EIO); } bcopy(fragbuf, buf + (blks * BIOSDISK_SECSIZE), fragsize); #endif break; case F_WRITE : DEBUG("write %d from %d to %p", blks, dblk, buf); if (blks && bd_write(od, dblk, blks, buf)) { DEBUG("write error"); return (EIO); } #ifdef BD_SUPPORT_FRAGS if(fragsize) { DEBUG("Attempted to write a frag"); return (EIO); } #endif break; default: /* DO NOTHING */ return (EROFS); } if (rsize) *rsize = size; return (0); }
int main(int argc, char **argv) { int index; int RetVal = -99; if ((argc < 2) || (argc > 5)) { printf("On doit fournir entre 2 et 5 arguments a ufs!\n"); return -1; } printf("\n"); // Imprimer la commande a l'ecran for (index=1; index<argc; index++) { printf("%s ",argv[index]); } printf("\n"); // ========== commande truncate() ============= if (strcmp(argv[1],"truncate")==0) { if (argc!=4) { printf("La commande truncate demande 2 arguments!\n"); printf(" ufs truncate nom_fichier taille\n"); return 1; } RetVal = bd_truncate(argv[2], atoi(argv[3])); } // ========== commande blockfree() ============= else if (strcmp(argv[1],"blockfree")==0) { if (argc!=2) { printf("La commande blockfree demande 0 arguments!\n"); printf(" ufs blockfree\n"); return 1; } RetVal = bd_countfreeblocks(argv[2], argv[3]); } // ========== commande read() ============= else if (strcmp(argv[1],"read")==0) { if (argc!=5) { printf("La commande read demande 3 arguments!\n"); printf(" ufs read nom_fichier offset numbytes\n"); return 1; } char Donnees[65536]; RetVal = bd_read(argv[2],Donnees,atoi(argv[3]),atoi(argv[4])); for (index=0; index<RetVal; index++) { printf("%c",Donnees[index]); } printf("\n"); } // ========== commande write() ============= else if (strcmp(argv[1],"write")==0) { if (argc!=5) { printf("La commande write demande 3 arguments!\n"); printf(" ufs write nom_fichier \"Chaine de caractere\" offset\n"); return 1; } RetVal = bd_write(argv[2],argv[3],atoi(argv[4]),strlen(argv[3])); } // ========== commande bd_stat() ============= else if (strcmp(argv[1],"stat")==0) { if (argc!=3) { printf("La commande stat demande 1 arguments!\n"); printf(" ufs stat nom_fichier\n"); return 1; } stat MyStat; RetVal = bd_stat(argv[2], &MyStat); printf("inode:%d size:%d blocks:%d\n",MyStat.st_ino, MyStat.st_size, MyStat.st_blocks); } // ========== commande bd_ls() ============= else if (strcmp(argv[1],"ls")==0) { if (argc!=3) { printf("La commande ls demande 1 arguments!\n"); printf(" ufs ls nom_repertoire\n"); return 1; } RetVal = bd_ls(argv[2]); } else { printf("Impossible de trouver la commande %s\n",argv[1]); return -1; } printf("RetVal:%d\n",RetVal); return 0; }