static __inline__ int print_volume_label(Stream_t *Dir, char drive) { Stream_t *Stream = GetFs(Dir); direntry_t entry; DeclareThis(FsPublic_t); char shortname[13]; char longname[VBUFSIZE]; int r; RootDir = OpenRoot(Stream); if(concise) return 0; /* find the volume label */ initializeDirentry(&entry, RootDir); if((r=vfat_lookup(&entry, 0, 0, ACCEPT_LABEL | MATCH_ANY, shortname, longname)) ) { if (r == -2) { /* I/O Error */ return -1; } printf(" Volume in drive %c has no label", drive); } else if (*longname) printf(" Volume in drive %c is %s (abbr=%s)", drive, longname, shortname); else printf(" Volume in drive %c is %s", drive, shortname); if(This->serialized) printf("\n Volume Serial Number is %04lX-%04lX", (This->serial_number >> 16) & 0xffff, This->serial_number & 0xffff); return 0; }
Stream_t *open_root_dir(unsigned char drive, int flags, int *isRop) { Stream_t *Fs; init_streamcache(); drive = toupper(drive); /* open the drive */ if(fss[drive]) Fs = fss[drive]; else { Fs = fs_init(drive, flags, isRop); if (!Fs){ fprintf(stderr, "Cannot initialize '%c:'\n", drive); return NULL; } fss[drive] = Fs; } return OpenRoot(Fs); }
Stream_t *open_root_dir(char *drive, int flags) { Stream_t *Fs; int i, k; init_streamcache(); k = -1; for(i=0; i<256; i++) { if (fss[i] == NULL || strcmp(getDrive(fss[i]), drive) == 0) { k = i; break; } } if(k == -1) { fprintf(stderr, "Cannot initialize '%s:', out of table space\n", drive); return NULL; } /* open the drive */ if(fss[k]) Fs = fss[k]; else { Fs = fs_init(drive, flags); if (!Fs){ fprintf(stderr, "Cannot initialize '%s:'\n", drive); return NULL; } fss[k] = Fs; } return OpenRoot(Fs); }
NS_IMETHODIMP XULContentSinkImpl::HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, PRUint32 aAttsCount, PRInt32 aIndex, PRUint32 aLineNumber) { // XXX Hopefully the parser will flag this before we get here. If // we're in the epilog, there should be no new elements NS_PRECONDITION(mState != eInEpilog, "tag in XUL doc epilog"); NS_PRECONDITION(aIndex >= -1, "Bogus aIndex"); NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount"); // Adjust aAttsCount so it's the actual number of attributes aAttsCount /= 2; if (mState == eInEpilog) return NS_ERROR_UNEXPECTED; if (mState != eInScript) { FlushText(); } PRInt32 nameSpaceID; nsCOMPtr<nsIAtom> prefix, localName; nsContentUtils::SplitExpatName(aName, getter_AddRefs(prefix), getter_AddRefs(localName), &nameSpaceID); nsCOMPtr<nsINodeInfo> nodeInfo; nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID, nsIDOMNode::ELEMENT_NODE); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); nsresult rv = NS_OK; switch (mState) { case eInProlog: // We're the root document element rv = OpenRoot(aAtts, aAttsCount, nodeInfo); break; case eInDocumentElement: rv = OpenTag(aAtts, aAttsCount, aLineNumber, nodeInfo); break; case eInEpilog: case eInScript: PR_LOG(gLog, PR_LOG_WARNING, ("xul: warning: unexpected tags in epilog at line %d", aLineNumber)); rv = NS_ERROR_UNEXPECTED; // XXX break; } // Set the ID attribute atom on the node info object for this node if (aIndex != -1 && NS_SUCCEEDED(rv)) { nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]); if (IDAttr) { nodeInfo->SetIDAttributeAtom(IDAttr); } } return rv; }
/** This function builds the FsOptionMenu list which records all available file system in the system. They include all instances of EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, all instances of EFI_LOAD_FILE_SYSTEM and all type of legacy boot device. @retval EFI_SUCCESS Success find the file system @retval EFI_OUT_OF_RESOURCES Can not create menu entry **/ EFI_STATUS FindFileSystem ( VOID ) { UINTN NoBlkIoHandles; UINTN NoSimpleFsHandles; EFI_HANDLE *BlkIoHandle; EFI_HANDLE *SimpleFsHandle; UINT16 *VolumeLabel; EFI_BLOCK_IO_PROTOCOL *BlkIo; UINTN Index; EFI_STATUS Status; SECUREBOOT_MENU_ENTRY *MenuEntry; SECUREBOOT_FILE_CONTEXT *FileContext; UINT16 *TempStr; UINTN OptionNumber; VOID *Buffer; BOOLEAN RemovableMedia; NoSimpleFsHandles = 0; OptionNumber = 0; InitializeListHead (&FsOptionMenu.Head); // // Locate Handles that support BlockIo protocol // Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &NoBlkIoHandles, &BlkIoHandle ); if (!EFI_ERROR (Status)) { for (Index = 0; Index < NoBlkIoHandles; Index++) { Status = gBS->HandleProtocol ( BlkIoHandle[Index], &gEfiBlockIoProtocolGuid, (VOID **) &BlkIo ); if (EFI_ERROR (Status)) { continue; } // // Issue a dummy read to trigger reinstall of BlockIo protocol for removable media // if (BlkIo->Media->RemovableMedia) { Buffer = AllocateZeroPool (BlkIo->Media->BlockSize); if (NULL == Buffer) { FreePool (BlkIoHandle); return EFI_OUT_OF_RESOURCES; } BlkIo->ReadBlocks ( BlkIo, BlkIo->Media->MediaId, 0, BlkIo->Media->BlockSize, Buffer ); FreePool (Buffer); } } FreePool (BlkIoHandle); } // // Locate Handles that support Simple File System protocol // Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &NoSimpleFsHandles, &SimpleFsHandle ); if (!EFI_ERROR (Status)) { // // Find all the instances of the File System prototocol // for (Index = 0; Index < NoSimpleFsHandles; Index++) { Status = gBS->HandleProtocol ( SimpleFsHandle[Index], &gEfiBlockIoProtocolGuid, (VOID **) &BlkIo ); if (EFI_ERROR (Status)) { // // If no block IO exists assume it's NOT a removable media // RemovableMedia = FALSE; } else { // // If block IO exists check to see if it's remobable media // RemovableMedia = BlkIo->Media->RemovableMedia; } // // Allocate pool for this instance. // MenuEntry = CreateMenuEntry (); if (NULL == MenuEntry) { FreePool (SimpleFsHandle); return EFI_OUT_OF_RESOURCES; } FileContext = (SECUREBOOT_FILE_CONTEXT *) MenuEntry->FileContext; FileContext->Handle = SimpleFsHandle[Index]; MenuEntry->OptionNumber = Index; FileContext->FHandle = OpenRoot (FileContext->Handle); if (FileContext->FHandle == NULL) { DestroyMenuEntry (MenuEntry); continue; } MenuEntry->HelpString = DevicePathToStr (DevicePathFromHandle (FileContext->Handle)); FileContext->Info = FileSystemVolumeLabelInfo (FileContext->FHandle); FileContext->FileName = StrDuplicate (L"\\"); FileContext->DevicePath = FileDevicePath ( FileContext->Handle, FileContext->FileName ); FileContext->IsDir = TRUE; FileContext->IsRoot = TRUE; FileContext->IsRemovableMedia = RemovableMedia; FileContext->IsLoadFile = FALSE; // // Get current file system's Volume Label // if (FileContext->Info == NULL) { VolumeLabel = L"NO FILE SYSTEM INFO"; } else { if (FileContext->Info->VolumeLabel == NULL) { VolumeLabel = L"NULL VOLUME LABEL"; } else { VolumeLabel = FileContext->Info->VolumeLabel; if (*VolumeLabel == 0x0000) { VolumeLabel = L"NO VOLUME LABEL"; } } } TempStr = MenuEntry->HelpString; MenuEntry->DisplayString = AllocateZeroPool (MAX_CHAR); ASSERT (MenuEntry->DisplayString != NULL); UnicodeSPrint ( MenuEntry->DisplayString, MAX_CHAR, L"%s, [%s]", VolumeLabel, TempStr ); OptionNumber++; InsertTailList (&FsOptionMenu.Head, &MenuEntry->Link); } } if (NoSimpleFsHandles != 0) { FreePool (SimpleFsHandle); } // // Remember how many file system options are here // FsOptionMenu.MenuNumber = OptionNumber; return EFI_SUCCESS; }
int fatlabel_set_label(const char* device_name, const char* new_label) { if (strlen(new_label) > VBUFSIZE) return -1; /* * 1. Init clash handling */ struct ClashHandling_t ch; init_clash_handling(&ch); ch.name_converter = label_name; ch.ignore_entry = -2; /* * 2. Open root dir */ struct Stream_t* RootDir = fs_init(device_name, O_RDWR); if (RootDir) RootDir = OpenRoot(RootDir); if (!RootDir) { fprintf(stderr, "Opening root dir failed.\n"); return -2; } /* * 3. Init dir entry */ struct direntry_t entry; initializeDirentry(&entry, RootDir); /* * 4. Lookup vfat */ char longname[VBUFSIZE]; char shortname[45]; if (vfat_lookup(&entry, 0, 0, ACCEPT_LABEL | MATCH_ANY, shortname, longname) == -2) { fprintf(stderr, "Looking up vfat failed.\n"); free_stream(&RootDir); return -3; } /* * 5. Wipe existing entry. */ if (!isNotFound(&entry)) { /* if we have a label, wipe it out before putting new one */ entry.dir.attr = 0; /* for old mlabel */ wipeEntry(&entry); } /* * 6. Write new entry */ ch.ignore_entry = 1; /* don't try to write the label if it's empty */ int result = strlen(new_label) ? mwrite_one(RootDir, new_label, labelit, &ch) : 0; /* * 7. Load FAT boot record */ union bootsector boot; struct Stream_t* Fs = GetFs(RootDir); int have_boot = force_read(Fs, boot.characters, 0, sizeof(boot)) == sizeof(boot); struct label_blk_t* labelBlock = WORD_S(fatlen) ? &boot.boot.ext.old.labelBlock : &boot.boot.ext.fat32.labelBlock; /* * 8. Get "dosconvert" struct */ struct dos_name_t dosname; struct doscp_t* cp = GET_DOSCONVERT(Fs); /* * 9. Convert label */ int mangled = 0; label_name(cp, new_label, &mangled, &dosname); /* * 10. Overwrite FAT boot record */ if (have_boot && boot.boot.descr >= 0xf0 && labelBlock->dos4 == 0x29) { strncpy(labelBlock->label, dosname.base, 11); force_write(Fs, (char *)&boot, 0, sizeof(boot)); } free_stream(&RootDir); fs_close(Fs); return result; }