int dir_grow(Stream_t *Dir, int size) { Stream_t *Stream = GetFs(Dir); DeclareThis(FsPublic_t); int ret; int buflen; char *buffer; if (!getfreeMinClusters(Dir, 1)) return -1; buflen = This->cluster_size * This->sector_size; if(! (buffer=malloc(buflen)) ){ perror("dir_grow: malloc"); return -1; } memset((char *) buffer, '\0', buflen); ret = force_write(Dir, buffer, (mt_off_t) size * MDIR_SIZE, buflen); free(buffer); if(ret < buflen) return -1; return 0; }
/* * Open the named file for read, create the cluster chain, return the * directory structure or NULL on error. */ int makeit(char *dosname, char *longname, void *arg0, direntry_t *targetEntry) { Stream_t *Target; CreateArg_t *arg = (CreateArg_t *) arg0; int fat; direntry_t subEntry; /* will it fit? At least one cluster must be free */ if (!getfreeMinClusters(targetEntry->Dir, 1)) return -1; mk_entry(dosname, ATTR_DIR, 1, 0, arg->mtime, &targetEntry->dir); Target = OpenFileByDirentry(targetEntry); if(!Target){ fprintf(stderr,"Could not open Target\n"); return -1; } /* this allocates the first cluster for our directory */ initializeDirentry(&subEntry, Target); subEntry.entry = 1; GET_DATA(targetEntry->Dir, 0, 0, 0, &fat); if (fat == fat32RootCluster(targetEntry->Dir)) { fat = 0; } mk_entry(".. ", ATTR_DIR, fat, 0, arg->mtime, &subEntry.dir); dir_write(&subEntry); FLUSH((Stream_t *) Target); subEntry.entry = 0; GET_DATA(Target, 0, 0, 0, &fat); mk_entry(". ", ATTR_DIR, fat, 0, arg->mtime, &subEntry.dir); dir_write(&subEntry); mk_entry(dosname, ATTR_DIR | arg->attr, fat, 0, arg->mtime, &targetEntry->dir); arg->NewDir = Target; return 0; }
Stream_t *createDir(Stream_t *Dir, const char *filename, ClashHandling_t *ch, unsigned char attr, time_t mtime) { CreateArg_t arg; int ret; arg.Dir = Dir; arg.attr = attr; arg.mtime = mtime; if (!getfreeMinClusters(Dir, 1)) return NULL; ret = mwrite_one(Dir, filename,0, makeit, &arg, ch); if(ret < 1) return NULL; else return arg.NewDir; }