首页 \ 问答 \ 在Python中查询块设备文件的大小(Query size of block device file in Python)

在Python中查询块设备文件的大小(Query size of block device file in Python)

我有一个Python脚本,用于读取标记不可读扇区的文件(通常来自光学介质),以允许重新尝试在不同的光学读取器上读取所述不可读的扇区。

我发现我的脚本不适用于块设备(例如/ dev / sr0),以便创建包含的ISO9660 / UDF文件系统的副本,因为os.stat().st_size为零。 该算法目前需要预先了解文件大小; 我可以改变这一点,但是(知道块设备大小的)问题依然存在,并且在这里没有回答,所以我打开这个问题。

我知道以下两个相关的SO问题:

因此,我问:在Python中,如何获取块设备文件的文件大小?


I have a Python script that reads a file (typically from optical media) marking the unreadable sectors, to allow a re-attempt to read said unreadable sectors on a different optical reader.

I discovered that my script does not work with block devices (e.g. /dev/sr0), in order to create a copy of the contained ISO9660/UDF filesystem, because os.stat().st_size is zero. The algorithm currently needs to know the filesize in advance; I can change that, but the issue (of knowing the block device size) remains, and it's not answered here, so I open this question.

I am aware of the following two related SO questions:

Therefore, I'm asking: in Python, how can I get the file size of a block device file?


原文:https://stackoverflow.com/questions/2773604
更新时间:2022-02-03 12:02

最满意答案

   public class Users
        {
             public string Email { get; set; }
public string UserName { get; set; }
public string DisplayName { get; set; }
public bool isMapped { get; set; }


        }



 try
{

    string DomainPath = "";
    DirectoryEntry searchRoot = new DirectoryEntry(DomainPath); 
    DirectorySearcher search = new DirectorySearcher(searchRoot);
    search.Filter = "(&(objectClass=user)(objectCategory=person))";
    search.PropertiesToLoad.Add("samaccountname");
    search.PropertiesToLoad.Add("mail");
    search.PropertiesToLoad.Add("usergroup");
    search.PropertiesToLoad.Add("displayname");

    SearchResult result;
    SearchResultCollection resultCol = search.FindAll();
    if (resultCol != null)
    {
        for (int counter = 0; counter < resultCol.Count; counter++)
        {
            string UserNameEmailString = string.Empty;
            result = resultCol[counter];
            if (result.Properties.Contains("samaccountname") && 
                     result.Properties.Contains("mail") && 
                result.Properties.Contains("displayname"))
            {
                Users objSurveyUsers = new Users();
                objSurveyUsers.Email = (String)result.Properties["mail"][0];
                objSurveyUsers.UserName = (String)result.Properties["samaccountname"][0];
                objSurveyUsers.DisplayName = (String)result.Properties["displayname"][0];

                lstADUsers.Add(objSurveyUsers);
            }
        }
    }

}
catch (Exception ex)
{

}

   public class Users
        {
             public string Email { get; set; }
public string UserName { get; set; }
public string DisplayName { get; set; }
public bool isMapped { get; set; }


        }



 try
{

    string DomainPath = "";
    DirectoryEntry searchRoot = new DirectoryEntry(DomainPath); 
    DirectorySearcher search = new DirectorySearcher(searchRoot);
    search.Filter = "(&(objectClass=user)(objectCategory=person))";
    search.PropertiesToLoad.Add("samaccountname");
    search.PropertiesToLoad.Add("mail");
    search.PropertiesToLoad.Add("usergroup");
    search.PropertiesToLoad.Add("displayname");

    SearchResult result;
    SearchResultCollection resultCol = search.FindAll();
    if (resultCol != null)
    {
        for (int counter = 0; counter < resultCol.Count; counter++)
        {
            string UserNameEmailString = string.Empty;
            result = resultCol[counter];
            if (result.Properties.Contains("samaccountname") && 
                     result.Properties.Contains("mail") && 
                result.Properties.Contains("displayname"))
            {
                Users objSurveyUsers = new Users();
                objSurveyUsers.Email = (String)result.Properties["mail"][0];
                objSurveyUsers.UserName = (String)result.Properties["samaccountname"][0];
                objSurveyUsers.DisplayName = (String)result.Properties["displayname"][0];

                lstADUsers.Add(objSurveyUsers);
            }
        }
    }

}
catch (Exception ex)
{

}

相关问答

更多
  • Azure AD角色与应用程序中的角色不同。 你应该看一下这个样本: https : //github.com/Azure-Samples/active-directory-dotnet-webapp-roleclaims 您必须首先在应用清单中定义应用中的角色。 然后将用户分配给他们。 一旦你做了这两件事,就会在你得到的JWT中声称称为“角色”,其中包含用户的角色。 So, after a lot of looking and searching, the way to implement AuthN v ...
  • 您尝试执行的操作不能通过Active Directory完成。 用户可能登录到域,并将其会话锁定或与机器/服务器断开连接,然后回家。 此信息不会传回Active directory因此LastLogon变量将保持不变,直到用户返回并解锁计算机(通过域控制器进行身份验证)。 这就是为什么即使他们已经回家,你也会在晚上看到用户活跃。 您可以判断某个会话当前是否处于活动状态的唯一方法是询问他们所在的计算机并返回会话状态。 但连接到大量的域名机器并不理想。 因此,获取登录用户数据的最佳方法是跟踪域控制器事件日志,并 ...
  • 您正在寻找的是使用活动目录的无缝kerberos SSO身份验证,其中浏览器自动发送您需要验证的一些协商令牌。 通常,这会委托给Web服务器。 有几个Apache插件可以这样做: Windows上的Apache的mod_auth_sspi: http : //mod-auth-sspi.sourceforge.net/ Linux上的Apache的mod_auth_kerb: http : //modauthkerb.sourceforge.net Linux上的Apache的mod_ntlm: http ...
  • 它看起来像你已经请求了user.read作用域。 这将允许您读取当前用户的个人资料( /me ),但不能访问租户( /users )中的其他用户。 您还需要将User.ReadBasic.All请求到您的身份验证请求。 这将允许您阅读租户中任何用户的基本配置文件信息。 It looks like you have requested the user.read scope. This will allow you to read the current user's profile (/me) but no ...
  • 是的,单向信任可能会做。 单向信任基本上意味着“域A信任域B用户是他们所说的他们”。 因此,如果域A信任域B,那么您将能够将域B用户添加到域A组。 相反的情况并非如此,除非你建立双向信任。 Yes, a one-way trust will likely do. A one-way trust essentially means "Domain A trusts that Domain B users are who they say they are". So if Domain A trusts Dom ...
  • public class Users { public string Email { get; set; } public string UserName { get; set; } public string DisplayName { get; set; } public bool isMapped { get; set; } } try { string DomainPath = ""; DirectoryEntr ...
  • 我借用了我的伙伴旧服务器并构建了本地服务器2012并加入了域名。 可能不是每个人的答案。 但为我工作。 (如果我有更多的时间,我希望得到天蓝色的域工作...我确定我正确建立它。只是没有工作。 这是我的答案。 i borrowed my mates old server and built a local server 2012 and joined the domain. probably not everyone's answer. but worked for me. (if i had more ti ...
  • 纯粹的答案是使用带有includeusersecurity选项的stsadm导出操作。 就个人而言,我不是一个stsadm粉丝,并建议您使用SP部署向导工具,并确保选择用户信息更新以导入所有。 这将为他们的个人资料带来安全+用户信息。 Apparently you can't move an active directory with user and their permissions unless the servers you are moving it between are networked. ...
  • 以下是该算法的一般概念: 从SQL Server加载用户数据 将其转换为LDIF (LDAP数据交换格式)文件 使用LDIFDE命令行工具将LDIF文件导入Active Directory Python或任何其他编程语言可以帮助您完成第2步。请注意,转换的详细信息非常特定于数据的表示方式。 您必须仔细地将每个数据库字段映射到LDAP属性,并确定要在LDAP对象中使用的类。 以上会修改现有用户吗? 当然是。 您可以以更新现有数据的方式编写LDIF,或者如果这是一个问题,您可以首先验证Active Direct ...
  • 对不起大家,我明白了。 我忘了为listview添加itemplaceholder: 这是完整的 <%# Eval("UserID") %> ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)