本文整理汇总了Golang中github.com/hanwen/go-mtpfs/mtp.Device.GetStorageInfo方法的典型用法代码示例。如果您正苦于以下问题:Golang Device.GetStorageInfo方法的具体用法?Golang Device.GetStorageInfo怎么用?Golang Device.GetStorageInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hanwen/go-mtpfs/mtp.Device
的用法示例。
在下文中一共展示了Device.GetStorageInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SelectStorages
func SelectStorages(dev *mtp.Device, pat string) ([]uint32, error) {
sids := mtp.Uint32Array{}
err := dev.GetStorageIDs(&sids)
if err != nil {
return nil, err
}
re, err := regexp.Compile(pat)
if err != nil {
return nil, err
}
filtered := []uint32{}
for _, id := range sids.Values {
var s mtp.StorageInfo
err := dev.GetStorageInfo(id, &s)
if err != nil {
return nil, err
}
if !s.IsHierarchical() {
log.Printf("skipping non hierarchical storage %q", s.StorageDescription)
continue
}
if re.FindStringIndex(s.StorageDescription) == nil {
log.Printf("filtering out storage %q", s.StorageDescription)
continue
}
filtered = append(filtered, id)
}
return filtered, nil
}
示例2: NewDeviceFs
// DeviceFs is a simple filesystem interface to an MTP device. It
// should be wrapped in a Locking(Raw)FileSystem to make sure it is
// threadsafe. The file system assumes the device does not touch the
// storage. Arguments are the opened mtp device and a directory for the
// backing store.
func NewDeviceFs(d *mtp.Device, storages []uint32, options DeviceFsOptions) (*DeviceFs, error) {
o := options
root := rootNode{}
fs := &DeviceFs{root: &root, dev: d, options: &o}
root.fs = fs
fs.storages = storages
err := d.GetDeviceInfo(&fs.devInfo)
if err != nil {
return fs, nil
}
if !strings.Contains(fs.devInfo.MTPExtension, "android.com") {
return nil, fmt.Errorf("this device has no android.com extensions.")
}
for _, sid := range fs.storages {
var info mtp.StorageInfo
err := d.GetStorageInfo(sid, &info)
if err != nil {
return nil, err
}
fs.storageInfos = append(fs.storageInfos, info)
}
return fs, nil
}