unsigned long discid(cd * this_cd) { unsigned int i=0, t, n = 0, trks=0, l=0; for (i=0; i< this_cd->tracks; i++) if(this_cd->track[T2I(i)].type==AUDIO) { n += cddb_sum((this_cd->track[T2I(i)].start_lba+CD_MSF_OFFSET)/CD_FRAMES); trks++; l=i; } t = (this_cd->track[T2I(l+1)].start_lba- this_cd->track[T2I(0)].start_lba)/CD_FRAMES; return (((n % 0xFF) << 24) | (t << 8) | trks); }
static int cdfs_readdir(struct file *filp, void *dirent, filldir_t filldir) { struct inode *inode = filp->f_dentry->d_inode; int i; cd * this_cd = cdfs_info(inode->i_sb); PRINT("cdfs_readdir ino=%ld f_pos=%u\n", inode->i_ino, (int)filp->f_pos); for(i=filp->f_pos; i<T2I(this_cd->tracks); i++) { if (filldir(dirent, this_cd->track[i].name, strlen(this_cd->track[i].name), 0, i, DT_UNKNOWN) < 0) return 0; filp->f_pos++; } return 1; }
static void cdfs_umount(struct super_block *sb) { int t; cd * this_cd = cdfs_info(sb); PRINT("cdfs_umount\n"); for (t=0; t<=this_cd->tracks; t++) if ((this_cd->track[T2I(t)].type == DATA) && this_cd->track[T2I(t)].iso_info) kfree(this_cd->track[T2I(t)].iso_info); // Free & invalidate cache kfree(this_cd->cache); this_cd->cache_sector = -CACHE_SIZE; // Remove /proc entry cdfs_proc_cd = NULL; kfree(cdfs_info(sb)); #ifdef OLD_KERNEL MOD_DEC_USE_COUNT; #endif }
int cdfs_read_proc(char *buf, char **start, off_t offset, int len, int *eof, void *data ){ int t,i; struct _track_info * track; char proc_info[4096]; char * proc_counter = proc_info; char MSFsize[10]; if (!cdfs_proc_cd) { proc_counter+=sprintf(proc_counter, "[%s\t%s]\n\tNo CD mounted\n", FSNAME, VERSION); } else { proc_counter+=sprintf(proc_counter, "[%s\t%s]\n\nCD (discid=%08X) contains %d track%s:\n\n", FSNAME, VERSION, cdfs_proc_cd->discid, cdfs_proc_cd->tracks, cdfs_proc_cd->tracks-1 ? "s" : ""); /* add stuff here */ for (t=0; t<cdfs_proc_cd->tracks; t++) { i=T2I(t); proc_counter+=sprintf(proc_counter,"\n"); track = &cdfs_proc_cd->track[i]; if (track->type == DATA) { if (track->iso_size) { /* DATA & ISO */ proc_counter+=sprintf(proc_counter,"Track %2d: data track (%s), [%d-%d/%d], length=%d MB\n", t+1, track->name, track->start_lba, track->iso_size/2048, track->stop_lba, track->track_size/1024/1024); proc_counter+=sprintf(proc_counter, "\ttype: %c info: %.5s version: %c\n" "\tdate: %.2s/%.2s/%.4s time: %.2s:%.2s:%.2s\n" "\tsystem: %.32s\n\tvolume: %.32s\n", track->iso_info->type[0]+48, track->iso_info->id, track->iso_info->version[0]+48, track->iso_info->creation_date+6, track->iso_info->creation_date+4, track->iso_info->creation_date, track->iso_info->creation_date+8, track->iso_info->creation_date+10, track->iso_info->creation_date+12, track->iso_info->system_id, track->iso_info->volume_id ); proc_counter+=sprintf(proc_counter, "\tpublisher: %.128s\n", track->iso_info->publisher_id); proc_counter-=2; while (*--proc_counter==' ') ; proc_counter+=2; *proc_counter++='\n'; proc_counter+=sprintf(proc_counter, "\tpreparer: %.128s\n", track->iso_info->preparer_id); proc_counter-=2; while (*--proc_counter==' ') ; proc_counter+=2; *proc_counter++='\n'; proc_counter+=sprintf(proc_counter, "\tapplication: %.128s\n", track->iso_info->application_id); proc_counter-=2; while (*--proc_counter==' ') ; proc_counter+=2; *proc_counter++='\n'; proc_counter+=sprintf(proc_counter, "\tlength: %d MB / %d MB / %d MB / %d MB\n", (track->iso_size-track->start_lba*CD_FRAMESIZE)/1024/1024, track->track_size/1024/1024, track->iso_size/1024/1024, track->size/1024/1024); } else { /* DATA, geen ISO */ proc_counter+=sprintf(proc_counter,"Track %2d: data track (%s), [%d-%d], length=%d kB\n", t+1, track->name, track->start_lba, track->stop_lba, track->track_size/1024); proc_counter+=sprintf(proc_counter, "\ttype: %s\n", cdfs_proc_cd->videocd_type); proc_counter+=sprintf(proc_counter, "\ttitle: %s\n", cdfs_proc_cd->videocd_title); proc_counter+=sprintf(proc_counter, "\tframesize: %d B\n", track->xa_data_size); } } else if (track->type==BOOT) { proc_counter+=sprintf(proc_counter,"Bootimage (%s), [%d-%d], length=%d kB\n\tID string:%s\n", track->name, track->start_lba, track->stop_lba, track->size/1024, track->bootID); } else if (track->type==HFS) { proc_counter+=sprintf(proc_counter,"Apple HFS (%s), [%d-%d], length=%d MB\n\tID string:%s\n", track->name, track->start_lba, track->stop_lba, track->size/1024/1024, track->bootID); } else if (track->type==AUDIO) { cdfs_constructMSFsize(MSFsize, track->size); proc_counter+=sprintf(proc_counter,"Track %2d: audio track (%s), [%8d -%8d], length=%s\n", t+1, track->name, track->start_lba, track->stop_lba, MSFsize); } } } strncpy(buf, proc_info, proc_counter-proc_info); return proc_counter-proc_info; }
static struct dentry * cdfs_lookup(struct inode *dir, struct dentry *dentry){ #else static struct dentry * cdfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd){ #endif struct inode * inode; int i; cd * this_cd = cdfs_info(dir->i_sb); PRINT("cdfs_lookup %s ino=%ld \n", dentry->d_name.name, dir->i_ino); for(i=0; i<T2I(this_cd->tracks); i++) if (!(strcmp(this_cd->track[i].name, dentry->d_name.name))) { goto found; } return ERR_PTR(-ENOENT); /* Use goto and read inode with iget()/cdfs_iget() */ /* Thanks to David Howells for patch and Master class in his mail */ found: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,24) inode = cdfs_iget(dir->i_sb, i); if (IS_ERR(inode)) return ERR_CAST(inode); #else inode = iget(dir->i_sb, i); if (!inode) return ERR_PTR(-ENOMEM); #endif d_add(dentry, inode); return NULL; } /***************************************************************************/ static struct file_operations cdfs_dir_operations = { .read = generic_read_dir, .readdir = cdfs_readdir, }; static struct inode_operations cdfs_inode_operations = { .lookup = cdfs_lookup }; /**************************************************************************/ static void cdfs_read_inode(struct inode *i) { cd * this_cd = cdfs_info(i->i_sb); PRINT("this_cd = 0x%x\n", (unsigned)this_cd); PRINT("read inode %ld\n", i->i_ino); i->i_uid = this_cd->uid; i->i_gid = this_cd->gid; i->i_nlink = 1; i->i_op = &cdfs_inode_operations; i->i_fop = NULL; i->i_data.a_ops = NULL; if (i->i_ino <= 2) { /* . and .. */ i->i_size = 0; /* Uuugh ?? */ i->i_mtime = i->i_atime = i->i_ctime = CURRENT_TIME; i->i_mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; i->i_fop = &cdfs_dir_operations; } else { /* file */ i->i_size = this_cd->track[i->i_ino].size; #ifdef OLD_KERNEL i->i_mtime = i->i_atime = i->i_ctime = this_cd->track[i->i_ino].time; #else i->i_mtime.tv_sec = i->i_atime.tv_sec = i->i_ctime.tv_sec = this_cd->track[i->i_ino].time; i->i_mtime.tv_nsec = i->i_atime.tv_nsec = i->i_ctime.tv_nsec = 0; #endif i->i_mode = this_cd->mode; if ((this_cd->track[i->i_ino].type==DATA) && this_cd->track[i->i_ino].iso_size) { i->i_fop = &cdfs_cddata_file_operations; i->i_data.a_ops = &cdfs_cddata_aops; } else if (this_cd->track[i->i_ino].type==AUDIO) { i->i_fop = &cdfs_cdda_file_operations; if (this_cd->raw_audio) i->i_data.a_ops = &cdfs_cdda_raw_aops; else i->i_data.a_ops = &cdfs_cdda_aops; } else if (this_cd->track[i->i_ino].type==BOOT) { i->i_fop = &cdfs_cddata_file_operations; i->i_data.a_ops = &cdfs_cddata_aops; } else if (this_cd->track[i->i_ino].type==HFS) { if (this_cd->track[i->i_ino].hfs_offset) { i->i_fop = &cdfs_cdhfs_file_operations; /* Bummer, this partition isn't properly aligned... */ i->i_data.a_ops = &cdfs_cdhfs_aops; } else { i->i_fop = &cdfs_cddata_file_operations; i->i_data.a_ops = &cdfs_cddata_aops; } } else { i->i_fop = &cdfs_cdXA_file_operations; i->i_data.a_ops = &cdfs_cdXA_aops; } } }
static struct super_block * cdfs_mount(struct super_block *sb, void *data, int silent){ kdev_t dev = sb->s_dev; int i, j, t; struct cdrom_tochdr hdr; #else static int cdfs_fill_super(struct super_block *sb, void *data, int silent){ int i, t; #endif struct cdrom_tocentry entry; int no_audio=0, no_data=0; cd * this_cd; struct inode *retinode; PRINT("cdfs_mount\n"); #ifdef OLD_KERNEL MOD_INC_USE_COUNT; set_blocksize(dev, CD_FRAMESIZE); // voor bread met ide-cd #else sb_set_blocksize(sb, CD_FRAMESIZE); // voor bread met ide-cd #endif sb->s_blocksize = CD_FRAMESIZE; sb->s_blocksize_bits = 11; if (!(this_cd = cdfs_info(sb) = kmalloc(sizeof(cd), GFP_KERNEL))){ #ifdef OLD_KERNEL MOD_DEC_USE_COUNT; return NULL; #else return -ENOMEM; #endif } this_cd->mode = MODE; this_cd->gid = GID; this_cd->uid = UID; this_cd->single = FALSE; this_cd->raw_audio = 0; this_cd->toc_scsi = FALSE; // Initialize cache for maximum sector size if (!(this_cd->cache = kmalloc(CD_FRAMESIZE_RAWER*CACHE_SIZE, GFP_KERNEL))) { #ifdef OLD_KERNEL MOD_DEC_USE_COUNT; return NULL; #else kfree(cdfs_info(sb)); return -ENOMEM; #endif } // Cache is still invalid this_cd->cache_sector = -CACHE_SIZE; cdfs_parse_options((char *) data, this_cd); /* Populate CD info with '.' and '..' */ strcpy(this_cd->track[1].name, "."); this_cd->track[1].start_lba=0; strcpy(this_cd->track[2].name, ".."); this_cd->track[2].start_lba=0; this_cd->nr_iso_sessions = 0; this_cd->size = 0; if (this_cd->toc_scsi){ if (cdfs_toc_read_full(sb)){ printk("TOC read failed\n"); #ifdef OLD_KERNEL MOD_DEC_USE_COUNT; return NULL; #else goto invalid; #endif } } else { //if (cdfs_ioctl(sb, CDROMREADTOCHDR, (unsigned long)&hdr)){ if (cdfs_toc_read(sb)){ printk("cdfs_toc_read failed\n"); #ifdef OLD_KERNEL MOD_DEC_USE_COUNT; return NULL; #else goto invalid; #endif } } PRINT("CD contains %d tracks\n", this_cd->tracks); /* Collect track info */ entry.cdte_format = CDROM_LBA; for (t=this_cd->tracks; t>=0; t--) { i = T2I(t); // j = this_cd->tracks-i; // entry.cdte_track = (t==this_cd->tracks) ? CDROM_LEADOUT : t+1; // PRINT("Read track %d/%d/%d\n", entry.cdte_track, t, i); // if (cdfs_ioctl(sb, CDROMREADTOCENTRY, (unsigned long)&entry)){ // printk("ioctl(CDROMREADTOCENTRY) failed\n"); // MOD_DEC_USE_COUNT; // return NULL; // } // this_cd->track[i].start_lba = entry.cdte_addr.lba; // this_cd->track[i].stop_lba = this_cd->track[i+1].start_lba - 1; this_cd->track[i].track_size = this_cd->track[i+1].start_lba - this_cd->track[i].start_lba; /* in sectors! */ PRINT("Start[%d]: %d\n", i, this_cd->track[i].start_lba); if (t!=this_cd->tracks) { /* all tracks but the LEADOUT */ if (this_cd->track[i].type==DATA) { //int track=i; no_data++; this_cd->track[i].iso_info = cdfs_get_iso_info(sb, i); if (this_cd->track[i].iso_info) { this_cd->track[i].time = cdfs_constructtime((char*)&(this_cd->track[i].iso_info->creation_date)); this_cd->track[i].iso_size = cdfs_constructsize((char*)&(this_cd->track[i].iso_info->volume_space_size)) * CD_FRAMESIZE; if (!this_cd->single) this_cd->track[i].iso_size += this_cd->track[i].start_lba * CD_FRAMESIZE; this_cd->track[i].track_size *= CD_FRAMESIZE; this_cd->track[i].size = this_cd->track[i+1].start_lba * CD_FRAMESIZE; sprintf(this_cd->track[i].name, this_cd->single ? DATA_NAME_SINGLE : DATA_NAME_ISO, t+1); this_cd->lba_iso_sessions[this_cd->nr_iso_sessions].start = this_cd->track[i].start_lba; this_cd->lba_iso_sessions[this_cd->nr_iso_sessions].stop = this_cd->track[i].iso_size/CD_FRAMESIZE; this_cd->nr_iso_sessions++; cdfs_get_hfs_info(sb, i); // possibly also a HFS } else { // DATA, but no ISO -> either HFS or VideoCD if (cdfs_get_hfs_info(sb, i)==-1){ printk("CHECKING VIDEOCD!!\n"); cdfs_get_XA_info(sb, i); this_cd->track[i].time = 0; this_cd->track[i].iso_size = 0; this_cd->track[i].track_size = (this_cd->track[i].track_size-1) * this_cd->track[i].xa_data_size; this_cd->track[i].size = this_cd->track[i].track_size; sprintf(this_cd->track[i].name, DATA_NAME_VCD, no_data); } else { // HFS, no ISO, no VideoCD -> remove track this_cd->track[i].iso_info = NULL; this_cd->track[i].type = 0; } } } else { no_audio++; this_cd->track[i].iso_info = NULL; this_cd->track[i].type = AUDIO; this_cd->track[i].time = get_seconds(); this_cd->track[i].iso_size = 0; this_cd->track[i].track_size = this_cd->track[i].track_size * CD_FRAMESIZE_RAW + ((this_cd->raw_audio==0)?WAV_HEADER_SIZE:0); this_cd->track[i].size = this_cd->track[i].track_size; this_cd->track[i].avi = 0; sprintf(this_cd->track[i].name, (this_cd->raw_audio)? RAW_AUDIO_NAME:AUDIO_NAME, t+1); if (this_cd->raw_audio) { /* read the first sector. */ struct cdrom_read_audio cdda; int status,k,j,prevk=0; char* buf; buf=kmalloc(CD_FRAMESIZE_RAW*2,GFP_KERNEL); if(buf==NULL) { printk(FSNAME ": kmalloc failed in root.c !\n"); return(-ENOMEM); } for (j=0;j<10;j++) { cdda.addr_format = CDROM_LBA; cdda.nframes = 1; cdda.buf = buf+CD_FRAMESIZE_RAW; cdda.addr.lba = this_cd->track[i].start_lba+j; status = cdfs_ioctl(sb,CDROMREADAUDIO,(unsigned long)&cdda); if (status) { printk("cdfs_ioctl(CDROMREADAUDIO,%d) ioctl failed: %d\n", cdda.addr.lba, status); goto out; } /* search the first non-zero byte */ for (k=0;k<CD_FRAMESIZE_RAW;k++) if (buf[k+CD_FRAMESIZE_RAW]) break; if (k<=CD_FRAMESIZE_RAW-4) break; prevk=k; if (k<CD_FRAMESIZE_RAW) for (k=0;k<CD_FRAMESIZE_RAW;k++) buf[k]=buf[k+CD_FRAMESIZE_RAW]; } if (j==10) goto out; if ((j!=0)&&(prevk!=CD_FRAMESIZE_RAW)) { k=prevk; j--; } else k+=CD_FRAMESIZE_RAW; this_cd->track[i].avi_offset = j*CD_FRAMESIZE_RAW+k-CD_FRAMESIZE_RAW; if ((buf[k]=='R')&&(buf[k+1]=='I')&& (buf[k+2]=='F')&&(buf[k+3]=='F')) { this_cd->track[i].avi = 1; this_cd->track[i].avi_swab = 0; } else if ((buf[k]=='I')&&(buf[k+1]=='R')&& (buf[k+2]=='F')&&(buf[k+3]=='F')) { this_cd->track[i].avi = 1; this_cd->track[i].avi_swab = 1; } if (this_cd->track[i].avi) { if ((this_cd->track[i].avi_offset&1)!=0) { printk("AVI offset is not even, error\n"); this_cd->track[i].avi=0; } else { this_cd->track[i].track_size -= this_cd->track[i].avi_offset; sprintf(this_cd->track[i].name, AVI_AUDIO_NAME, t+1); } } out: kfree(buf); } } // Calculate total CD size this_cd->size += this_cd->track[i].track_size; PRINT("Track %2d: (%dB)\n", t, this_cd->track[i].size); } // else CDROM_LEADOUT } PRINT("CD ends at %d\n", this_cd->track[this_cd->tracks].start_lba); /* take care to get disc id after the toc has been read. JP, 29-12-2001 */ this_cd->discid = discid(this_cd); //////////////////////////////// /* Check if CD is bootable */ if (this_cd->track[T2I(0)].type==DATA) cdfs_check_bootable(sb); /* Check for an HFS partition in the first data track */ /*if (no_data) { i=T2I(0); while (i<T2I(this_cd->tracks)) { if (this_cd->track[i].type==DATA) break; i++; } cdfs_get_hfs_info(sb, i); } */ PRINT("%d audio tracks and %d data tracks => %dbytes\n", no_audio, no_data, this_cd->size); sb->s_magic = CDFS_MAGIC; sb->s_flags |= MS_RDONLY; sb->s_op = &cdfs_ops; /* always get inode status */ #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,24) retinode=cdfs_iget(sb, 0); #else retinode=iget(sb, 0); #endif if ( IS_ERR(retinode) ) return PTR_ERR(retinode); PRINT("retinode = %ld\n", retinode->i_ino); sb->s_root = d_alloc_root(retinode); cdfs_proc_cd = this_cd; #ifdef OLD_KERNEL return sb; #else return 0; invalid: kfree(this_cd->cache); kfree(cdfs_info(sb)); return -EINVAL; #endif }
static int serveCgi(UosFile* sock, char* url, char* buf) { char* ptr; int i; int j; bool first; Sensor* s = sensorData; char addr[30]; if (!strcmp(url, "/front_data.cgi")) { posMutexLock(sensorMutex); ptr = buf; for (i = 0; i < MAX_TEMP; i++) { if (i == 0) { strcpy(ptr, "["); ptr = ptr + 1; } sensorAddressStr(addr, s); nosSPrintf(ptr, "{\"sensor\":\"%s\"", addr); ptr += strlen(ptr); nosSPrintf(ptr, ",\"temp\":%d.%d", T2I(s->temp), T2D(s->temp)); ptr += strlen(ptr); nosSPrintf(ptr, ",\"tempMin\":%d.%d", T2I(s->tempMin), T2D(s->tempMin)); ptr += strlen(ptr); nosSPrintf(ptr, ",\"tempMax\":%d.%d", T2I(s->tempMax), T2D(s->tempMax)); ptr += strlen(ptr); strcpy(ptr, ",\"tempHistory\":["); ptr += strlen(ptr); j = s->tempCount - 5; if (j < 0) j = 0; first = true; for (;j < s->tempCount; j++) { if (!first) { *ptr = ','; ++ptr; } first = false; nosSPrintf(ptr, "%d.%d", T2I(s->temps[j]), T2D(s->temps[j])); ptr += strlen(ptr); } strcpy(ptr, "]}"); ptr += strlen(ptr); if (i == MAX_TEMP - 1 || s[1].serialNum[0] == 0) { strcat(ptr, "]"); ptr += 1; uosFileWrite(sock, buf, ptr - buf); break; } else { strcat(ptr, ","); ptr += 1; if (SOCK_BUF_SIZE - (ptr - buf) < 128) { uosFileWrite(sock, buf, ptr - buf); ptr = buf; } } s++; } posMutexUnlock(sensorMutex); } else if (!strcmp(url, "/temp_trend_data.cgi")) { posMutexLock(sensorMutex); sensorAddressStr(addr, s); ptr = buf; for (i = 0; i < s->tempCount; i++) { if (i == 0) { strcpy(ptr, "["); ptr = ptr + 1; } nosSPrintf(ptr, "{\"sensor\":\"%s\",\"timeStamp\":%d,\"temp\":%d.%d}", addr, i - s->tempCount + 1, T2I(s->temps[i]), T2D(s->temps[i])); ptr += strlen(ptr); if (i == s->tempCount - 1) { strcat(ptr, "]"); ptr += 1; uosFileWrite(sock, buf, ptr - buf); } else { strcat(ptr, ","); ptr += 1; if (SOCK_BUF_SIZE - (ptr - buf) < 128) { uosFileWrite(sock, buf, ptr - buf); ptr = buf; } } } posMutexUnlock(sensorMutex); } else uosFileWrite(sock, "No-No", 5); return 0; }